mammoth2-test.go.tmpl 3.0 KB

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