ReadArrayHeaderBytes attempts to read the array header size off of 'b' and return the size and remaining bytes. Possible errors: - [ErrShortBytes] (too few bytes) - [TypeError] (not an array)
(b []byte)
| 227 | // - [ErrShortBytes] (too few bytes) |
| 228 | // - [TypeError] (not an array) |
| 229 | func ReadArrayHeaderBytes(b []byte) (sz uint32, o []byte, err error) { |
| 230 | if len(b) < 1 { |
| 231 | return 0, nil, ErrShortBytes |
| 232 | } |
| 233 | lead := b[0] |
| 234 | b = b[1:] |
| 235 | if isfixarray(lead) { |
| 236 | sz = uint32(rfixarray(lead)) |
| 237 | o = b |
| 238 | return |
| 239 | } |
| 240 | |
| 241 | switch lead { |
| 242 | case marray16: |
| 243 | if len(b) < 2 { |
| 244 | err = ErrShortBytes |
| 245 | return |
| 246 | } |
| 247 | sz = uint32(big.Uint16(b)) |
| 248 | o = b[2:] |
| 249 | return |
| 250 | |
| 251 | case marray32: |
| 252 | if len(b) < 4 { |
| 253 | err = ErrShortBytes |
| 254 | return |
| 255 | } |
| 256 | sz = big.Uint32(b) |
| 257 | o = b[4:] |
| 258 | return |
| 259 | |
| 260 | default: |
| 261 | err = badPrefix(ArrayType, lead) |
| 262 | return |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // ReadBytesHeader reads the 'bin' header size |
| 267 | // off of 'b' and returns the size and remaining bytes. |
searching dependent graphs…