-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo_marshal.tmpl
20 lines (19 loc) · 943 Bytes
/
go_marshal.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
func Marshal(<<- param .Name >> S, prefix []byte) []byte {
var enc = prefix
<< range .Fields ->>
<< if isMessage . ->>
enc = << goModuleName . >>.Marshal(<< param $.Name ->>.<< goName .Name >>, enc)
<< else if isGoType . "enum" ->>
enc = marshal.WriteInt32(enc, uint32(<< param $.Name >>.<< goName .Name >>))
<< else if isGoType . "string" ->>
<< lower .Name>>Bytes := []byte(<<- param $.Name ->>.<< goName .Name >>)
enc = marshal.WriteInt(enc, uint64(len(<< lower .Name >>Bytes)))
enc = marshal.WriteBytes(enc, << lower .Name >>Bytes)
<< else if (and (isGoType . "byte") (isSliceType .)) ->>
enc = marshal.WriteInt(enc, uint64(len(<< param $.Name >>.<< goName .Name >>)))
enc = marshal.WriteBytes(enc, << param $.Name >>.<< goName .Name >>)
<< else ->>
enc = marshal.Write<<- marshalType . ->>(enc, << param $.Name ->>.<< goName .Name >>)
<< end ->><<- end >>
return enc
}