本文整理汇总了Golang中encoding.TextMarshaler.MarshalText方法的典型用法代码示例。如果您正苦于以下问题:Golang TextMarshaler.MarshalText方法的具体用法?Golang TextMarshaler.MarshalText怎么用?Golang TextMarshaler.MarshalText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类encoding.TextMarshaler
的用法示例。
在下文中一共展示了TextMarshaler.MarshalText方法的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)
}