MCPcopy Index your code
hub / github.com/tinylib/msgp / ExampleReadArrayBytes_struct

Function ExampleReadArrayBytes_struct

msgp/iter_test.go:225–246  ·  view source on GitHub ↗

Example: slice roundtrip with struct elements in a byte slice using AppendArray/ReadArrayBytes. Uses testDec as the element type, with EncoderToBytes/DecoderFromBytes helpers.

()

Source from the content-addressed store, hash-verified

223// Example: slice roundtrip with struct elements in a byte slice using AppendArray/ReadArrayBytes.
224// Uses testDec as the element type, with EncoderToBytes/DecoderFromBytes helpers.
225func ExampleReadArrayBytes_struct() {
226 in := []testDec{{A: 1, B: "x"}, {A: 2, B: "y"}}
227 var b []byte
228
229 // Append []testDec using EncoderToBytes as the per-element appender.
230 b = AppendArray(b, in, EncoderToBytes(testDec{}))
231
232 // Read back using DecoderFromBytes as the per-element reader.
233 seq, finish := ReadArrayBytes(b, DecoderFromBytes(testDec{}))
234
235 seq(func(v testDec) bool {
236 fmt.Printf("%d %s\n", v.A, v.B)
237 return true
238 })
239 if _, err := finish(); err != nil {
240 fmt.Println("err:", err)
241 }
242
243 // Output:
244 // 1 x
245 // 2 y
246}
247
248// Example: map roundtrip with struct values in a byte slice using AppendMapSorted/ReadMapBytes.
249// Uses testDec as the value type and sorts keys for deterministic output.

Callers

nothing calls this directly

Calls 4

AppendArrayFunction · 0.85
EncoderToBytesFunction · 0.85
ReadArrayBytesFunction · 0.85
DecoderFromBytesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…