Sfoglia il codice sorgente

goprotobuf: Add MarshalTextString helper function.

R=r
CC=golang-dev
http://codereview.appspot.com/5823043
David Symonds 14 anni fa
parent
commit
d2bff3cf5f
1 ha cambiato i file con 7 aggiunte e 0 eliminazioni
  1. 7 0
      proto/text.go

+ 7 - 0
proto/text.go

@@ -423,6 +423,13 @@ func marshalText(w io.Writer, pb interface{}, compact bool) {
 // Values that are not protocol buffers can also be written, but their formatting is not guaranteed.
 func MarshalText(w io.Writer, pb interface{}) { marshalText(w, pb, false) }
 
+// MarshalTextString is the same as MarshalText, but returns the string directly.
+func MarshalTextString(pb interface{}) string {
+	var buf bytes.Buffer
+	marshalText(&buf, pb, false)
+	return buf.String()
+}
+
 // CompactText writes a given protocl buffer in compact text format (one line).
 // Values that are not protocol buffers can also be written, but their formatting is not guaranteed.
 func CompactText(w io.Writer, pb interface{}) { marshalText(w, pb, true) }