作者:GangWan
项目:go-plis
func (p *Encoder) marshalTextInterface(marshalable encoding.TextMarshaler) *plistValue {
s, err := marshalable.MarshalText()
if err != nil {
panic(err)
}
return &plistValue{String, string(s)}
}
作者:kezhu
项目:tom
func (e *encodeState) marshalTextValue(ti encoding.TextMarshaler, options tagOptions) {
b, err := ti.MarshalText()
if err != nil {
panic(err)
}
e.marshalStringValue(string(b), options)
}
作者:Celluliodi
项目:flanne
// marshalTextInterface marshals a TextMarshaler interface value.
func (p *printer) marshalTextInterface(val encoding.TextMarshaler, start StartElement) error {
if err := p.writeStart(&start); err != nil {
return err
}
text, err := val.MarshalText()
if err != nil {
return err
}
EscapeText(p, text)
return p.writeEnd(start.Name)
}
作者:ConfusedRealit
项目:pkg_serialization_thrif
func TestEnumIsTextMarshaller(t *testing.T) {
one := thrifttest.Numberz_ONE
var tm encoding.TextMarshaler = one
b, err := tm.MarshalText()
if err != nil {
t.Fatalf("Unexpected error from MarshalText: %s", err)
}
if string(b) != one.String() {
t.Errorf("MarshalText(%s) = %s, expected = %s", one, b, one)
}
}
作者:qban
项目:dow
func safeMarshal(tm encoding.TextMarshaler) (b []byte, err error) {
defer func() {
if panicVal := recover(); panicVal != nil {
if v := reflect.ValueOf(tm); v.Kind() == reflect.Ptr && v.IsNil() {
b, err = nil, nil
} else {
panic(panicVal)
}
}
}()
b, err = tm.MarshalText()
if err != nil {
return nil, &MarshalerError{
Type: reflect.TypeOf(tm),
Err: err,
}
}
return
}
作者:RookieGameDev
项目:survivele
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
bs, fnerr := iv.MarshalText()
f.e.marshal(bs, fnerr, false, c_UTF8)
}