File: pointer.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 (198 lines) | stat: -rw-r--r-- 5,140 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package _generated

import (
	"fmt"
	"time"

	"github.com/tinylib/msgp/msgp"
)

//go:generate msgp $GOFILE$

// Generate only pointer receivers:

//msgp:pointer

var mustNoInterf = []interface{}{
	Pointer0{},
	NamedBoolPointer(true),
	NamedIntPointer(0),
	NamedFloat64Pointer(0),
	NamedStringPointer(""),
	NamedMapStructPointer(nil),
	NamedMapStructPointer2(nil),
	NamedMapStringPointer(nil),
	NamedMapStringPointer2(nil),
	EmbeddableStructPointer{},
	EmbeddableStruct2Pointer{},
	PointerHalfFull{},
	PointerNoName{},
}

var mustHaveInterf = []interface{}{
	&Pointer0{},
	mustPtr(NamedBoolPointer(true)),
	mustPtr(NamedIntPointer(0)),
	mustPtr(NamedFloat64Pointer(0)),
	mustPtr(NamedStringPointer("")),
	mustPtr(NamedMapStructPointer(nil)),
	mustPtr(NamedMapStructPointer2(nil)),
	mustPtr(NamedMapStringPointer(nil)),
	mustPtr(NamedMapStringPointer2(nil)),
	&EmbeddableStructPointer{},
	&EmbeddableStruct2Pointer{},
	&PointerHalfFull{},
	&PointerNoName{},
}

func mustPtr[T any](v T) *T {
	return &v
}

func init() {
	for _, v := range mustNoInterf {
		if _, ok := v.(msgp.Marshaler); ok {
			panic(fmt.Sprintf("type %T supports interface", v))
		}
		if _, ok := v.(msgp.Encodable); ok {
			panic(fmt.Sprintf("type %T supports interface", v))
		}
	}
	for _, v := range mustHaveInterf {
		if _, ok := v.(msgp.Marshaler); !ok {
			panic(fmt.Sprintf("type %T does not support interface", v))
		}
		if _, ok := v.(msgp.Encodable); !ok {
			panic(fmt.Sprintf("type %T does not support interface", v))
		}
	}
}

type Pointer0 struct {
	ABool       bool       `msg:"abool"`
	AInt        int        `msg:"aint"`
	AInt8       int8       `msg:"aint8"`
	AInt16      int16      `msg:"aint16"`
	AInt32      int32      `msg:"aint32"`
	AInt64      int64      `msg:"aint64"`
	AUint       uint       `msg:"auint"`
	AUint8      uint8      `msg:"auint8"`
	AUint16     uint16     `msg:"auint16"`
	AUint32     uint32     `msg:"auint32"`
	AUint64     uint64     `msg:"auint64"`
	AFloat32    float32    `msg:"afloat32"`
	AFloat64    float64    `msg:"afloat64"`
	AComplex64  complex64  `msg:"acomplex64"`
	AComplex128 complex128 `msg:"acomplex128"`

	ANamedBool    bool    `msg:"anamedbool"`
	ANamedInt     int     `msg:"anamedint"`
	ANamedFloat64 float64 `msg:"anamedfloat64"`

	AMapStrStr map[string]string `msg:"amapstrstr"`

	APtrNamedStr *NamedString `msg:"aptrnamedstr"`

	AString      string `msg:"astring"`
	ANamedString string `msg:"anamedstring"`
	AByteSlice   []byte `msg:"abyteslice"`

	ASliceString      []string      `msg:"aslicestring"`
	ASliceNamedString []NamedString `msg:"aslicenamedstring"`

	ANamedStruct    NamedStruct  `msg:"anamedstruct"`
	APtrNamedStruct *NamedStruct `msg:"aptrnamedstruct"`

	AUnnamedStruct struct {
		A string `msg:"a"`
	} `msg:"aunnamedstruct"` // omitempty not supported on unnamed struct

	EmbeddableStruct `msg:",flatten"` // embed flat

	EmbeddableStruct2 `msg:"embeddablestruct2"` // embed non-flat

	AArrayInt [5]int `msg:"aarrayint"` // not supported

	ATime time.Time `msg:"atime"`
}

type (
	NamedBoolPointer       bool
	NamedIntPointer        int
	NamedFloat64Pointer    float64
	NamedStringPointer     string
	NamedMapStructPointer  map[string]Pointer0
	NamedMapStructPointer2 map[string]*Pointer0
	NamedMapStringPointer  map[string]NamedStringPointer
	NamedMapStringPointer2 map[string]*NamedStringPointer
)

type EmbeddableStructPointer struct {
	SomeEmbed string `msg:"someembed"`
}

type EmbeddableStruct2Pointer struct {
	SomeEmbed2 string `msg:"someembed2"`
}

type NamedStructPointer struct {
	A string `msg:"a"`
	B string `msg:"b"`
}

type PointerHalfFull struct {
	Field00 string `msg:"field00"`
	Field01 string `msg:"field01"`
	Field02 string `msg:"field02"`
	Field03 string `msg:"field03"`
}

type PointerNoName struct {
	ABool       bool       `msg:""`
	AInt        int        `msg:""`
	AInt8       int8       `msg:""`
	AInt16      int16      `msg:""`
	AInt32      int32      `msg:""`
	AInt64      int64      `msg:""`
	AUint       uint       `msg:""`
	AUint8      uint8      `msg:""`
	AUint16     uint16     `msg:""`
	AUint32     uint32     `msg:""`
	AUint64     uint64     `msg:""`
	AFloat32    float32    `msg:""`
	AFloat64    float64    `msg:""`
	AComplex64  complex64  `msg:""`
	AComplex128 complex128 `msg:""`

	ANamedBool    bool    `msg:""`
	ANamedInt     int     `msg:""`
	ANamedFloat64 float64 `msg:""`

	AMapStrF       map[string]NamedFloat64Pointer `msg:""`
	AMapStrStruct  map[string]PointerHalfFull     `msg:""`
	AMapStrStruct2 map[string]*PointerHalfFull    `msg:""`

	APtrNamedStr *NamedStringPointer `msg:""`

	AString    string `msg:""`
	AByteSlice []byte `msg:""`

	ASliceString      []string             `msg:""`
	ASliceNamedString []NamedStringPointer `msg:""`

	ANamedStruct    NamedStructPointer  `msg:""`
	APtrNamedStruct *NamedStructPointer `msg:""`

	AUnnamedStruct struct {
		A string `msg:""`
	} `msg:""` // omitempty not supported on unnamed struct

	EmbeddableStructPointer `msg:",flatten"` // embed flat

	EmbeddableStruct2Pointer `msg:""` // embed non-flat

	AArrayInt [5]int `msg:""` // not supported

	ATime time.Time     `msg:""`
	ADur  time.Duration `msg:""`
}