File: clearomitted.go

package info (click to toggle)
golang-github-tinylib-msgp 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 836 kB
  • sloc: makefile: 47
file content (97 lines) | stat: -rw-r--r-- 3,076 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package _generated

import (
	"encoding/json"
	"time"
)

//go:generate msgp

//msgp:clearomitted

// check some specific cases for omitzero

type ClearOmitted0 struct {
	AStruct    ClearOmittedA  `msg:"astruct,omitempty"`    // leave this one omitempty
	BStruct    ClearOmittedA  `msg:"bstruct,omitzero"`     // and compare to this
	AStructPtr *ClearOmittedA `msg:"astructptr,omitempty"` // a pointer case omitempty
	BStructPtr *ClearOmittedA `msg:"bstructptr,omitzero"`  // a pointer case omitzero
	AExt       OmitZeroExt    `msg:"aext,omitzero"`        // external type case

	// more
	APtrNamedStr        *NamedStringCO                     `msg:"aptrnamedstr,omitzero"`
	ANamedStruct        NamedStructCO                      `msg:"anamedstruct,omitzero"`
	APtrNamedStruct     *NamedStructCO                     `msg:"aptrnamedstruct,omitzero"`
	EmbeddableStructCO  `msg:",flatten,omitzero"`          // embed flat
	EmbeddableStructCO2 `msg:"embeddablestruct2,omitzero"` // embed non-flat
	ATime               time.Time                          `msg:"atime,omitzero"`
	ASlice              []int                              `msg:"aslice,omitempty"`
	AMap                map[string]int                     `msg:"amap,omitempty"`
	ABin                []byte                             `msg:"abin,omitempty"`
	AInt                int                                `msg:"aint,omitempty"`
	AString             string                             `msg:"atring,omitempty"`
	Adur                time.Duration                      `msg:"adur,omitempty"`
	AJSON               json.Number                        `msg:"ajson,omitempty"`

	ClearOmittedTuple ClearOmittedTuple `msg:"ozt"` // the inside of a tuple should ignore both omitempty and omitzero
}

type ClearOmittedA struct {
	A string        `msg:"a,omitempty"`
	B NamedStringCO `msg:"b,omitzero"`
	C NamedStringCO `msg:"c,omitzero"`
}

func (o *ClearOmittedA) IsZero() bool {
	if o == nil {
		return true
	}
	return *o == (ClearOmittedA{})
}

type NamedStructCO struct {
	A string `msg:"a,omitempty"`
	B string `msg:"b,omitempty"`
}

func (ns *NamedStructCO) IsZero() bool {
	if ns == nil {
		return true
	}
	return *ns == (NamedStructCO{})
}

type NamedStringCO string

func (ns *NamedStringCO) IsZero() bool {
	if ns == nil {
		return true
	}
	return *ns == ""
}

type EmbeddableStructCO struct {
	SomeEmbed string `msg:"someembed2,omitempty"`
}

func (es EmbeddableStructCO) IsZero() bool { return es == (EmbeddableStructCO{}) }

type EmbeddableStructCO2 struct {
	SomeEmbed2 string `msg:"someembed2,omitempty"`
}

func (es EmbeddableStructCO2) IsZero() bool { return es == (EmbeddableStructCO2{}) }

//msgp:tuple ClearOmittedTuple

// ClearOmittedTuple is flagged for tuple output, it should ignore all omitempty and omitzero functionality
// since it's fundamentally incompatible.
type ClearOmittedTuple struct {
	FieldA string        `msg:"fielda,omitempty"`
	FieldB NamedStringCO `msg:"fieldb,omitzero"`
	FieldC NamedStringCO `msg:"fieldc,omitzero"`
}

type ClearOmitted1 struct {
	T1 ClearOmittedTuple `msg:"t1"`
}