AppendArray writes an array to the provided buffer. The writeFn parameter specifies the function to use to write each element of the array. The returned buffer contains the encoded array. The function panics if the array is larger than math.MaxUint32 elements.
(b []byte, a []T, writeFn func(b []byte, v T) []byte)
| 199 | // The returned buffer contains the encoded array. |
| 200 | // The function panics if the array is larger than math.MaxUint32 elements. |
| 201 | func AppendArray[T any](b []byte, a []T, writeFn func(b []byte, v T) []byte) []byte { |
| 202 | if a == nil { |
| 203 | return AppendNil(b) |
| 204 | } |
| 205 | if uint64(len(a)) > math.MaxUint32 { |
| 206 | panic(fmt.Sprintf("array too large to encode: %d elements", len(a))) |
| 207 | } |
| 208 | b = AppendArrayHeader(b, uint32(len(a))) |
| 209 | for _, v := range a { |
| 210 | b = writeFn(b, v) |
| 211 | } |
| 212 | return b |
| 213 | } |
| 214 | |
| 215 | // ReadMapBytes returns an iterator over key/value |
| 216 | // pairs from a MessagePack map encoded in b. |
searching dependent graphs…