-
Notifications
You must be signed in to change notification settings - Fork 0
/
marshal_body.go
53 lines (39 loc) · 1.33 KB
/
marshal_body.go
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
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Code generated by embed.sh. DO NOT EDIT.
package codec
const marshalBody = `
«/*» Template body for a type that implements encoding.BinaryMarshaler or encoding.TextMarshaler. «*/»
« $typeID := typeID .Type »
« $typeName := print $typeID "_codec" »
« $goName := goName .Type »
var «$typeID»_type = reflect.TypeOf((*«$goName»)(nil)).Elem()
type «$typeName» struct{
codecapi.NonStruct
}
func (c *«$typeName») TypesUsed() []reflect.Type { return nil }
func (c *«$typeName») SetCodecs([]codecapi.TypeCodec) {}
func (c *«$typeName») Encode(e *codecapi.Encoder, x interface{}) { c.encode(e, x.(«$goName»)) }
func (c *«$typeName») encode(e *codecapi.Encoder, m «$goName») {
data, err := m.Marshal«.Kind»()
if err != nil {
codecapi.Fail(err)
}
e.EncodeBytes(data)
}
func (c *«$typeName») Decode(d *codecapi.Decoder) interface{} {
var x «$goName»
c.decode(d, &x)
return x
}
func (c *«$typeName») decode(d *codecapi.Decoder, p *«$goName») {
data := d.DecodeBytes()
if err := p.Unmarshal«.Kind»(data); err != nil {
codecapi.Fail(err)
}
}
func init() {
codecapi.Register(«$typeID»_type, func() codecapi.TypeCodec { return &«$typeName»{} })
}
`