コード例 #1
0
ファイル: marshal.go プロジェクト: GangWang/go-plist
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
ファイル: marshal.go プロジェクト: Celluliodio/flannel
// 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)
}
コード例 #4
0
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
}
コード例 #6
0
// 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)
}