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

Function ReadMapBytes

msgp/iter.go:219–252  ·  view source on GitHub ↗

ReadMapBytes returns an iterator over key/value pairs from a MessagePack map encoded in b. The iterator yields K,V pairs, and this function also returns a closure to get the remaining bytes and any error.

(b []byte,
	readK func([]byte) (K, []byte, error),
	readV func([]byte) (V, []byte, error))

Source from the content-addressed store, hash-verified

217// The iterator yields K,V pairs, and this function also returns
218// a closure to get the remaining bytes and any error.
219func ReadMapBytes[K any, V any](b []byte,
220 readK func([]byte) (K, []byte, error),
221 readV func([]byte) (V, []byte, error)) (iter.Seq2[K, V], func() (remain []byte, err error)) {
222 var err error
223 var sz uint32
224 if IsNil(b) {
225 b, err = ReadNilBytes(b)
226 return func(yield func(K, V) bool) {}, func() ([]byte, error) { return b, err }
227 }
228 sz, b, err = ReadMapHeaderBytes(b)
229 if err != nil || sz == 0 {
230 return func(yield func(K, V) bool) {}, func() ([]byte, error) { return b, err }
231 }
232
233 return func(yield func(K, V) bool) {
234 for range sz {
235 var k K
236 k, b, err = readK(b)
237 if err != nil {
238 err = fmt.Errorf("cannot read map key: %w", err)
239 return
240 }
241 var v V
242 v, b, err = readV(b)
243 if err != nil {
244 err = fmt.Errorf("cannot read map value: %w", err)
245 return
246 }
247 if !yield(k, v) {
248 return
249 }
250 }
251 }, func() ([]byte, error) { return b, err }
252}
253
254// AppendMap writes a map to the provided buffer.
255// The writeK and writeV parameters specify the functions to use to write each key and value of the map.

Calls 3

IsNilFunction · 0.85
ReadNilBytesFunction · 0.85
ReadMapHeaderBytesFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…