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

Function ExampleReadMapBytes

msgp/iter_test.go:144–161  ·  view source on GitHub ↗

Example: reading a map[string]float64 from a byte slice using ReadMapBytes. It prints key=value pairs and then checks the remaining bytes/error from the returned closure.

()

Source from the content-addressed store, hash-verified

142// Example: reading a map[string]float64 from a byte slice using ReadMapBytes.
143// It prints key=value pairs and then checks the remaining bytes/error from the returned closure.
144func ExampleReadMapBytes() {
145 var b []byte
146 // Append {"pi":3.14, "e":2.718} using AppendMap - we use the sorted version for the example
147 b = AppendMapSorted(b, map[string]float64{"pi": 3.14, "e": 2.718}, AppendString, AppendFloat64)
148
149 seq, finish := ReadMapBytes(b, ReadStringBytes, ReadFloat64Bytes)
150 seq(func(k string, v float64) bool {
151 fmt.Printf("%s=%.3f\n", k, v)
152 return true
153 })
154 if _, err := finish(); err != nil {
155 fmt.Println("err:", err)
156 }
157
158 // Output:
159 // e=2.718
160 // pi=3.140
161}
162
163// Example: slice roundtrip with struct elements using WriteArray/ReadArray.
164// Uses testDec as the element type, with EncoderTo/DecoderFrom helpers.

Callers

nothing calls this directly

Calls 2

AppendMapSortedFunction · 0.85
ReadMapBytesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…