File: main.go

package info (click to toggle)
golang-github-tinylib-msgp 1.2.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 764 kB
  • sloc: makefile: 47
file content (37 lines) | stat: -rw-r--r-- 606 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main

//go:generate msgp

type Example struct {
	I int    `msg:"i"`
	S string `msg:"s"`
	// NOTE: floats omitted intentionally, many MCUs don't have
	// native support for it so the binary size bloats just due to
	// the software float implementation
}

func main() {
	e := Example{
		I: 1,
		S: "2",
	}
	b, err := e.MarshalMsg(nil)
	if err != nil {
		panic(err)
	}

	var e2 Example
	extra, err := e2.UnmarshalMsg(b)
	if err != nil {
		panic(err)
	}
	if len(extra) != 0 {
		panic("unexpected extra")
	}

	if e.I != e2.I || e.S != e2.S {
		panic("not equal")
	}

	println("done, len(b):", len(b))
}