MCPcopy
hub / github.com/tinylib/msgp / ReadMapHeaderBytes

Function ReadMapHeaderBytes

msgp/read_bytes.go:163–201  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

161// - [ErrShortBytes] (too few bytes)
162// - [TypeError] (not a map)
163func 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

Callers 10

mainFunction · 0.92
TestReadMapHeaderBytesFunction · 0.85
FuzzReadBytesFunction · 0.85
rwMapBytesFunction · 0.85
HasKeyFunction · 0.85
locateFunction · 0.85
locateKVFunction · 0.85
ReadMapBytesFunction · 0.85
readMapStrIntfBytesDepthFunction · 0.85

Calls 3

isfixmapFunction · 0.85
rfixmapFunction · 0.85
badPrefixFunction · 0.85

Tested by 3

TestReadMapHeaderBytesFunction · 0.68
FuzzReadBytesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…