git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/mmdb/node.go (about) 1 package mmdb 2 3 type nodeReader interface { 4 readLeft(uint) uint 5 readRight(uint) uint 6 } 7 8 type nodeReader24 struct { 9 buffer []byte 10 } 11 12 func (n nodeReader24) readLeft(nodeNumber uint) uint { 13 return (uint(n.buffer[nodeNumber]) << 16) | 14 (uint(n.buffer[nodeNumber+1]) << 8) | 15 uint(n.buffer[nodeNumber+2]) 16 } 17 18 func (n nodeReader24) readRight(nodeNumber uint) uint { 19 return (uint(n.buffer[nodeNumber+3]) << 16) | 20 (uint(n.buffer[nodeNumber+4]) << 8) | 21 uint(n.buffer[nodeNumber+5]) 22 } 23 24 type nodeReader28 struct { 25 buffer []byte 26 } 27 28 func (n nodeReader28) readLeft(nodeNumber uint) uint { 29 return ((uint(n.buffer[nodeNumber+3]) & 0xF0) << 20) | 30 (uint(n.buffer[nodeNumber]) << 16) | 31 (uint(n.buffer[nodeNumber+1]) << 8) | 32 uint(n.buffer[nodeNumber+2]) 33 } 34 35 func (n nodeReader28) readRight(nodeNumber uint) uint { 36 return ((uint(n.buffer[nodeNumber+3]) & 0x0F) << 24) | 37 (uint(n.buffer[nodeNumber+4]) << 16) | 38 (uint(n.buffer[nodeNumber+5]) << 8) | 39 uint(n.buffer[nodeNumber+6]) 40 } 41 42 type nodeReader32 struct { 43 buffer []byte 44 } 45 46 func (n nodeReader32) readLeft(nodeNumber uint) uint { 47 return (uint(n.buffer[nodeNumber]) << 24) | 48 (uint(n.buffer[nodeNumber+1]) << 16) | 49 (uint(n.buffer[nodeNumber+2]) << 8) | 50 uint(n.buffer[nodeNumber+3]) 51 } 52 53 func (n nodeReader32) readRight(nodeNumber uint) uint { 54 return (uint(n.buffer[nodeNumber+4]) << 24) | 55 (uint(n.buffer[nodeNumber+5]) << 16) | 56 (uint(n.buffer[nodeNumber+6]) << 8) | 57 uint(n.buffer[nodeNumber+7]) 58 }