Example #1
0
func (p *Encoder) marshalTextInterface(marshalable encoding.TextMarshaler) *plistValue {
	s, err := marshalable.MarshalText()
	if err != nil {
		panic(err)
	}
	return &plistValue{String, string(s)}
}
Example #2
0
func (e *encodeState) marshalTextValue(ti encoding.TextMarshaler, options tagOptions) {
	b, err := ti.MarshalText()
	if err != nil {
		panic(err)
	}
	e.marshalStringValue(string(b), options)
}
Example #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)
	}
}
Example #5
0
File: encode.go Project: 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)
}