github.com/chrislusf/greenpack@v3.7.1-0.20170911073826-ad5bd10b7c47+incompatible/_generated/def.go (about) 1 package _generated 2 3 import ( 4 "github.com/glycerine/greenpack/msgp" 5 "os" 6 "time" 7 ) 8 9 //go:generate greenpack -o generated.go 10 11 // All of the struct 12 // definitions in this 13 // file are fed to the code 14 // generator when `make test` is 15 // called, followed by an 16 // invocation of `go test -v` in this 17 // directory. A simple way of testing 18 // a struct definition is 19 // by adding it to this file. 20 21 type Block [32]byte 22 23 // tests edge-cases with 24 // compiling size compilation. 25 type X struct { 26 Values [32]byte // should compile to 32*msgp.ByteSize; encoded as Bin 27 More Block // should be identical to the above 28 Others [][32]int32 // should compile to len(x.Others)*32*msgp.Int32Size 29 Matrix [][]int32 // should not optimize 30 ManyFixed []Fixed 31 } 32 33 // test fixed-size struct 34 // size compilation 35 type Fixed struct { 36 A float64 37 B bool 38 } 39 40 type PreviouslyAnon struct { 41 ValueA string `msg:"value_a"` 42 ValueB []byte `msg:"value_b"` 43 } 44 45 type TestType struct { 46 F *float64 `msg:"float"` 47 Els map[string]string `msg:"elements"` 48 Obj PreviouslyAnon `msg:"object"` 49 Child *TestType `msg:"child"` 50 Time time.Time `msg:"time"` 51 Any interface{} `msg:"any"` 52 Appended msgp.Raw `msg:"appended"` 53 Num msgp.Number `msg:"num"` 54 Slice1 []string 55 Slice2 []string 56 SlicePtr *[]string 57 } 58 59 type SimpleTestType struct { 60 F *float64 `msg:"float"` 61 Els map[string]string `msg:"elements"` 62 Obj *PreviouslyAnon `msg:"object"` 63 } 64 65 //msgp:tuple Object 66 type Object struct { 67 ObjectNo string `msg:"objno"` 68 Slice1 []string `msg:"slice1"` 69 Slice2 []string `msg:"slice2"` 70 MapMap map[string]map[string]string 71 } 72 73 //msgp:tuple TestBench 74 75 type TestBench struct { 76 Name string 77 BirthDay time.Time 78 Phone string 79 Siblings int 80 Spouse bool 81 Money float64 82 } 83 84 //msgp:tuple TestFast 85 86 type TestFast struct { 87 Lat, Long, Alt float64 // test inline decl 88 Data []byte 89 } 90 91 // Test nested aliases 92 type FastAlias TestFast 93 type AliasContainer struct { 94 Fast FastAlias 95 } 96 97 // Test dependency resolution 98 type IntA int 99 type IntB IntA 100 type IntC IntB 101 102 type TestHidden struct { 103 A string 104 B []float64 105 Bad func(string) bool // This results in a warning: field "Bad" unsupported 106 } 107 108 type Embedded struct { 109 *Embedded // test embedded field 110 Children []Embedded 111 PtrChildren []*Embedded 112 Other string 113 } 114 115 const eight = 8 116 117 type Things struct { 118 Cmplx complex64 `msg:"complex"` // test slices 119 Vals []int32 `msg:"values"` 120 //Arr [msgp.ExtensionPrefixSize]float64 `msg:"arr"` // test const array and *ast.SelectorExpr as array size 121 Arr [6]float64 `msg:"arr"` // test const array and *ast.SelectorExpr as array size 122 Arr2 [4]float64 `msg:"arr2"` // test basic lit array 123 Ext *msgp.RawExtension `msg:"ext,extension"` // test extension 124 Oext msgp.RawExtension `msg:"oext,extension"` // test extension reference 125 } 126 127 //msgp:shim SpecialID as:[]byte using:toBytes/fromBytes 128 129 type SpecialID string 130 type TestObj struct{ ID1, ID2 SpecialID } 131 132 func toBytes(id SpecialID) []byte { return []byte(string(id)) } 133 func fromBytes(id []byte) SpecialID { return SpecialID(string(id)) } 134 135 type MyEnum byte 136 137 const ( 138 A MyEnum = iota 139 B 140 C 141 D 142 invalid 143 ) 144 145 // test shim directive (below) 146 147 //msgp:shim MyEnum as:string using:(MyEnum).String/myenumStr 148 149 //msgp:shim *os.File as:string using:filetostr/filefromstr 150 151 func filetostr(f *os.File) string { 152 return f.Name() 153 } 154 155 func filefromstr(s string) *os.File { 156 f, _ := os.Open(s) 157 return f 158 } 159 160 func (m MyEnum) String() string { 161 switch m { 162 case A: 163 return "A" 164 case B: 165 return "B" 166 case C: 167 return "C" 168 case D: 169 return "D" 170 default: 171 return "<invalid>" 172 } 173 } 174 175 func myenumStr(s string) MyEnum { 176 switch s { 177 case "A": 178 return A 179 case "B": 180 return B 181 case "C": 182 return C 183 case "D": 184 return D 185 default: 186 return invalid 187 } 188 } 189 190 // test pass-specific directive 191 // :encode ignore Insane 192 193 // anonymous structs can't be serialized with greenpack, 194 // because the fieldsempty/everything omitempty by default 195 // logic requires named types when we define the helper 196 // method fieldsNotEmpty(). 197 type Insane [3]map[string]InsaneInner 198 type InsaneInner struct{ A, B CustomInt } 199 200 type Custom struct { 201 Bts CustomBytes `msg:"bts"` 202 Mp map[string]*Embedded `msg:"mp"` 203 Enums []MyEnum `msg:"enums"` // test explicit enum shim 204 Some FileHandle `msg:file_handle` 205 } 206 207 type Files []*os.File 208 209 type FileHandle struct { 210 Relevent Files `msg:"files"` 211 Name string `msg:"name"` 212 } 213 214 type CustomInt int 215 type CustomBytes []byte 216 217 // Test omitempty tag 218 type TestOmitEmpty struct { 219 220 // scalars 221 Name string `msg:",omitempty"` 222 BirthDay time.Time `msg:",omitempty"` 223 Phone string `msg:",omitempty"` 224 Siblings int `msg:",omitempty"` 225 Spouse bool `msg:",omitempty"` 226 Money float64 `msg:",omitempty"` 227 228 // slices 229 SliceName []string `msg:",omitempty"` 230 SliceBirthDay []time.Time `msg:",omitempty"` 231 SlicePhone []string `msg:",omitempty"` 232 SliceSiblings []int `msg:",omitempty"` 233 SliceSpouse []bool `msg:",omitempty"` 234 SliceMoney []float64 `msg:",omitempty"` 235 236 // arrays 237 ArrayName [3]string `msg:",omitempty"` 238 ArrayBirthDay [3]time.Time `msg:",omitempty"` 239 ArrayPhone [3]string `msg:",omitempty"` 240 ArraySiblings [3]int `msg:",omitempty"` 241 ArraySpouse [3]bool `msg:",omitempty"` 242 ArrayMoney [3]float64 `msg:",omitempty"` 243 244 // maps 245 MapStringString map[string]string `msg:",omitempty"` 246 MapStringIface map[string]interface{} `msg:",omitempty"` 247 248 // pointers 249 PtrName *string `msg:",omitempty"` 250 PtrBirthDay *time.Time `msg:",omitempty"` 251 PtrPhone *string `msg:",omitempty"` 252 PtrSiblings *int `msg:",omitempty"` 253 PtrSpouse *bool `msg:",omitempty"` 254 PtrMoney *float64 `msg:",omitempty"` 255 256 Inside1 OmitEmptyInside1 `msg:",omitempty"` 257 Greetings string `msg:",omitempty"` 258 Bullwinkle *Rocky `msg:",omitempty"` 259 } 260 261 type TopNester struct { 262 TopId int 263 Greetings string `msg:",omitempty"` 264 Bullwinkle *Rocky `msg:",omitempty"` 265 266 MyIntArray [3]int `msg:",omitempty"` 267 MyByteArray [3]byte `msg:",omitempty"` 268 MyMap map[string]string `msg:",omitempty"` 269 MyArrayMap [3]map[string]string `msg:",omitempty"` 270 271 // the time.Time extension 272 TopTime time.Time `msg:",omitempty"` 273 PtrTime *time.Time `msg:",omitempty"` 274 } 275 276 type Rocky struct { 277 Bugs *Bunny `msg:",omitempty"` 278 Road string `msg:",omitempty"` 279 Moose *Moose `msg:",omitempty"` 280 } 281 282 type Bunny struct { 283 Carrots []int `msg:",omitempty"` 284 Sayings map[string]string `msg:",omitempty"` 285 BunnyId int `msg:",omitempty"` 286 } 287 288 type Moose struct { 289 Trees []int `msg:",omitempty"` 290 Sayings map[string]string `msg:",omitempty"` 291 Id int 292 } 293 294 type OmitEmptyInside1 struct { 295 CountOfMonteCrisco int 296 Name string `msg:"name,omitempty"` 297 Inside2 OmitEmptyInside2 `msg:",omitempty"` 298 } 299 300 type OmitEmptyInside2 struct { 301 NameSuey string `msg:",omitempty"` 302 } 303 304 type OmitSimple struct { 305 CountDrocula int 306 Inside1 OmitEmptyInside1 `msg:",omitempty"` 307 } 308 309 type Wrapper struct { 310 Tree *Tree 311 } 312 313 type Tree struct { 314 Children []Tree 315 Element int 316 Parent *Wrapper 317 }