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

Function WriteArray

msgp/iter.go:44–65  ·  view source on GitHub ↗

WriteArray writes an array to the provided Writer. The writeFn parameter specifies the function to use to write each element of the array.

(w *Writer, a []T, writeFn func(T) error)

Source from the content-addressed store, hash-verified

42// WriteArray writes an array to the provided Writer.
43// The writeFn parameter specifies the function to use to write each element of the array.
44func WriteArray[T any](w *Writer, a []T, writeFn func(T) error) error {
45 // Check if nil
46 if a == nil {
47 return w.WriteNil()
48 }
49 if uint64(len(a)) > math.MaxUint32 {
50 return fmt.Errorf("array too large to encode: %d elements", len(a))
51 }
52 // Write array header
53 err := w.WriteArrayHeader(uint32(len(a)))
54 if err != nil {
55 return err
56 }
57 // Write elements
58 for _, v := range a {
59 err = writeFn(v)
60 if err != nil {
61 return err
62 }
63 }
64 return nil
65}
66
67// ReadMap returns an iterator that can be used to iterate over the elements
68// of a map in the MessagePack data while being read by the provided Reader.

Callers 3

ExampleReadArrayFunction · 0.85
ExampleWriteArrayFunction · 0.85
ExampleReadArray_structFunction · 0.85

Calls 2

WriteNilMethod · 0.80
WriteArrayHeaderMethod · 0.80

Tested by 3

ExampleReadArrayFunction · 0.68
ExampleWriteArrayFunction · 0.68
ExampleReadArray_structFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…