vendor/github.com/golang/protobuf/proto/text.go
changeset 251 1c52a0eeb952
parent 242 2a9ec03fe5a1
equal deleted inserted replaced
250:c040f992052f 251:1c52a0eeb952
   454 	}
   454 	}
   455 
   455 
   456 	return nil
   456 	return nil
   457 }
   457 }
   458 
   458 
       
   459 var textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
       
   460 
   459 // writeAny writes an arbitrary field.
   461 // writeAny writes an arbitrary field.
   460 func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
   462 func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
   461 	v = reflect.Indirect(v)
   463 	v = reflect.Indirect(v)
   462 
   464 
   463 	// Floats have special cases.
   465 	// Floats have special cases.
   517 			// If v is not addressable, then we are not worried about a race
   519 			// If v is not addressable, then we are not worried about a race
   518 			// since it implies that the binary Marshaler cannot possibly be
   520 			// since it implies that the binary Marshaler cannot possibly be
   519 			// mutating this value.
   521 			// mutating this value.
   520 			v = v.Addr()
   522 			v = v.Addr()
   521 		}
   523 		}
   522 		if etm, ok := v.Interface().(encoding.TextMarshaler); ok {
   524 		if v.Type().Implements(textMarshalerType) {
   523 			text, err := etm.MarshalText()
   525 			text, err := v.Interface().(encoding.TextMarshaler).MarshalText()
   524 			if err != nil {
   526 			if err != nil {
   525 				return err
   527 				return err
   526 			}
   528 			}
   527 			if _, err = w.Write(text); err != nil {
   529 			if _, err = w.Write(text); err != nil {
   528 				return err
   530 				return err