示例#1
0
func (p *Encoder) marshalTextInterface(marshalable encoding.TextMarshaler) *plistValue {
	s, err := marshalable.MarshalText()
	if err != nil {
		panic(err)
	}
	return &plistValue{String, string(s)}
}
示例#2
0
文件: encode.go 项目: kezhuw/toml
func (e *encodeState) marshalTextValue(ti encoding.TextMarshaler, options tagOptions) {
	b, err := ti.MarshalText()
	if err != nil {
		panic(err)
	}
	e.marshalStringValue(string(b), options)
}
示例#3
0
// 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)
}
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)
	}
}
示例#5
0
文件: encode.go 项目: qband/down
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
}
// 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)
}