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

Function main

tinygotest/testdata/roundtrip/main.go:154–203  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

152var buf [256]byte
153
154func main() {
155 var e Example
156 e.Setup()
157
158 b, err := e.MarshalMsg(buf[:0])
159 if err != nil {
160 panic(err)
161 }
162 b1 := b
163
164 var e2 Example
165 _, err = e2.UnmarshalMsg(b)
166 if err != nil {
167 panic(err)
168 }
169
170 println("marshal/unmarshal done: ", &e2)
171
172 e.Omitted = ""
173 if !e.Eq(&e2) {
174 panic("comparison after marshal/unmarhsal failed")
175 }
176
177 var wbuf bytes.Buffer
178 mw := msgp.NewWriterSize(&wbuf, 64)
179
180 e.Omitted = "other"
181 err = e.EncodeMsg(mw)
182 if err != nil {
183 panic(err)
184 }
185 mw.Flush()
186
187 e2 = Example{}
188 mr := msgp.NewReaderSize(bytes.NewReader(wbuf.Bytes()), 64)
189 err = e2.DecodeMsg(mr)
190 if err != nil {
191 panic(err)
192 }
193
194 println("writer/reader done: ", &e2)
195 e.Omitted = ""
196 if !e.Eq(&e2) {
197 panic("comparison after writer/reader failed")
198 }
199
200 if bytes.Compare(wbuf.Bytes(), b1) != 0 {
201 panic("writer and marshal produced different results")
202 }
203}

Callers

nothing calls this directly

Calls 9

SetupMethod · 0.95
EqMethod · 0.95
NewWriterSizeFunction · 0.92
NewReaderSizeFunction · 0.92
FlushMethod · 0.80
MarshalMsgMethod · 0.65
UnmarshalMsgMethod · 0.65
EncodeMsgMethod · 0.65
DecodeMsgMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…