khenaidoo | ffe076b | 2019-01-15 16:08:08 -0500 | [diff] [blame^] | 1 | // +build !notfastpath |
| 2 | |
| 3 | // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. |
| 4 | // Use of this source code is governed by a MIT license found in the LICENSE file. |
| 5 | |
| 6 | // Code generated from mammoth2-test.go.tmpl - DO NOT EDIT. |
| 7 | |
| 8 | package codec |
| 9 | |
| 10 | // Increase codecoverage by covering all the codecgen paths, in fast-path and gen-helper.go.... |
| 11 | // |
| 12 | // Add: |
| 13 | // - test file for creating a mammoth generated file as _mammoth_generated.go |
| 14 | // - generate a second mammoth files in a different file: mammoth2_generated_test.go |
| 15 | // - mammoth-test.go.tmpl will do this |
| 16 | // - run codecgen on it, into mammoth2_codecgen_generated_test.go (no build tags) |
| 17 | // - as part of TestMammoth, run it also |
| 18 | // - this will cover all the codecgen, gen-helper, etc in one full run |
| 19 | // - check in mammoth* files into github also |
| 20 | // - then |
| 21 | // |
| 22 | // Now, add some types: |
| 23 | // - some that implement BinaryMarshal, TextMarshal, JSONMarshal, and one that implements none of it |
| 24 | // - create a wrapper type that includes TestMammoth2, with it in slices, and maps, and the custom types |
| 25 | // - this wrapper object is what we work encode/decode (so that the codecgen methods are called) |
| 26 | |
| 27 | |
| 28 | // import "encoding/binary" |
| 29 | import "fmt" |
| 30 | |
| 31 | type TestMammoth2 struct { |
| 32 | |
| 33 | {{range .Values }}{{if .Primitive }}{{/* |
| 34 | */}}{{ .MethodNamePfx "F" true }} {{ .Primitive }} |
| 35 | {{ .MethodNamePfx "Fptr" true }} *{{ .Primitive }} |
| 36 | {{end}}{{end}} |
| 37 | |
| 38 | {{range .Values }}{{if not .Primitive }}{{if not .MapKey }}{{/* |
| 39 | */}}{{ .MethodNamePfx "F" false }} []{{ .Elem }} |
| 40 | {{ .MethodNamePfx "Fptr" false }} *[]{{ .Elem }} |
| 41 | {{end}}{{end}}{{end}} |
| 42 | |
| 43 | {{range .Values }}{{if not .Primitive }}{{if .MapKey }}{{/* |
| 44 | */}}{{ .MethodNamePfx "F" false }} map[{{ .MapKey }}]{{ .Elem }} |
| 45 | {{ .MethodNamePfx "Fptr" false }} *map[{{ .MapKey }}]{{ .Elem }} |
| 46 | {{end}}{{end}}{{end}} |
| 47 | |
| 48 | } |
| 49 | |
| 50 | // ----------- |
| 51 | |
| 52 | type testMammoth2Binary uint64 |
| 53 | func (x testMammoth2Binary) MarshalBinary() (data []byte, err error) { |
| 54 | data = make([]byte, 8) |
| 55 | bigen.PutUint64(data, uint64(x)) |
| 56 | return |
| 57 | } |
| 58 | func (x *testMammoth2Binary) UnmarshalBinary(data []byte) (err error) { |
| 59 | *x = testMammoth2Binary(bigen.Uint64(data)) |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | type testMammoth2Text uint64 |
| 64 | func (x testMammoth2Text) MarshalText() (data []byte, err error) { |
| 65 | data = []byte(fmt.Sprintf("%b", uint64(x))) |
| 66 | return |
| 67 | } |
| 68 | func (x *testMammoth2Text) UnmarshalText(data []byte) (err error) { |
| 69 | _, err = fmt.Sscanf(string(data), "%b", (*uint64)(x)) |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | type testMammoth2Json uint64 |
| 74 | func (x testMammoth2Json) MarshalJSON() (data []byte, err error) { |
| 75 | data = []byte(fmt.Sprintf("%v", uint64(x))) |
| 76 | return |
| 77 | } |
| 78 | func (x *testMammoth2Json) UnmarshalJSON(data []byte) (err error) { |
| 79 | _, err = fmt.Sscanf(string(data), "%v", (*uint64)(x)) |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | type testMammoth2Basic [4]uint64 |
| 84 | |
| 85 | type TestMammoth2Wrapper struct { |
| 86 | V TestMammoth2 |
| 87 | T testMammoth2Text |
| 88 | B testMammoth2Binary |
| 89 | J testMammoth2Json |
| 90 | C testMammoth2Basic |
| 91 | M map[testMammoth2Basic]TestMammoth2 |
| 92 | L []TestMammoth2 |
| 93 | A [4]int64 |
| 94 | } |