本文整理匯總了Golang中encoding.TextMarshaler類的典型用法代碼示例。如果您正苦於以下問題:Golang TextMarshaler類的具體用法?Golang TextMarshaler怎麽用?Golang TextMarshaler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TextMarshaler類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: marshalTextInterface
func (p *Encoder) marshalTextInterface(marshalable encoding.TextMarshaler) *plistValue {
s, err := marshalable.MarshalText()
if err != nil {
panic(err)
}
return &plistValue{String, string(s)}
}
示例2: marshalTextValue
func (e *encodeState) marshalTextValue(ti encoding.TextMarshaler, options tagOptions) {
b, err := ti.MarshalText()
if err != nil {
panic(err)
}
e.marshalStringValue(string(b), options)
}
示例3: marshalTextInterface
// 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: TestEnumIsTextMarshaller
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: safeMarshal
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: EncTextMarshal
// 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)
}