blob: 7cdf8f5d719224ba84e8f6b1bf60d5c292b066b3 [file] [log] [blame]
khenaidooffe076b2019-01-15 16:08:08 -05001// +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
8package 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"
29import "fmt"
30
31type 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
52type testMammoth2Binary uint64
53func (x testMammoth2Binary) MarshalBinary() (data []byte, err error) {
54data = make([]byte, 8)
55bigen.PutUint64(data, uint64(x))
56return
57}
58func (x *testMammoth2Binary) UnmarshalBinary(data []byte) (err error) {
59*x = testMammoth2Binary(bigen.Uint64(data))
60return
61}
62
63type testMammoth2Text uint64
64func (x testMammoth2Text) MarshalText() (data []byte, err error) {
65data = []byte(fmt.Sprintf("%b", uint64(x)))
66return
67}
68func (x *testMammoth2Text) UnmarshalText(data []byte) (err error) {
69_, err = fmt.Sscanf(string(data), "%b", (*uint64)(x))
70return
71}
72
73type testMammoth2Json uint64
74func (x testMammoth2Json) MarshalJSON() (data []byte, err error) {
75data = []byte(fmt.Sprintf("%v", uint64(x)))
76return
77}
78func (x *testMammoth2Json) UnmarshalJSON(data []byte) (err error) {
79_, err = fmt.Sscanf(string(data), "%v", (*uint64)(x))
80return
81}
82
83type testMammoth2Basic [4]uint64
84
85type 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}