ReadMapHeaderBytes reads a map header size from 'b' and returns the remaining bytes. Possible errors: - [ErrShortBytes] (too few bytes) - [TypeError] (not a map)
(b []byte)
| 161 | // - [ErrShortBytes] (too few bytes) |
| 162 | // - [TypeError] (not a map) |
| 163 | func ReadMapHeaderBytes(b []byte) (sz uint32, o []byte, err error) { |
| 164 | l := len(b) |
| 165 | if l < 1 { |
| 166 | err = ErrShortBytes |
| 167 | return |
| 168 | } |
| 169 | |
| 170 | lead := b[0] |
| 171 | b = b[1:] |
| 172 | if isfixmap(lead) { |
| 173 | sz = uint32(rfixmap(lead)) |
| 174 | o = b |
| 175 | return |
| 176 | } |
| 177 | |
| 178 | switch lead { |
| 179 | case mmap16: |
| 180 | if len(b) < 2 { |
| 181 | err = ErrShortBytes |
| 182 | return |
| 183 | } |
| 184 | sz = uint32(big.Uint16(b)) |
| 185 | o = b[2:] |
| 186 | return |
| 187 | |
| 188 | case mmap32: |
| 189 | if len(b) < 4 { |
| 190 | err = ErrShortBytes |
| 191 | return |
| 192 | } |
| 193 | sz = big.Uint32(b) |
| 194 | o = b[4:] |
| 195 | return |
| 196 | |
| 197 | default: |
| 198 | err = badPrefix(MapType, lead) |
| 199 | return |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // ReadMapKeyZC attempts to read a map key |
| 204 | // from 'b' and returns the key bytes and the remaining bytes |
searching dependent graphs…