浏览代码

goprotobuf: Add MarshalTextString helper function.

R=r
CC=golang-dev
http://codereview.appspot.com/5823043
David Symonds 14 年之前
父节点
当前提交
d2bff3cf5f
共有 1 个文件被更改,包括 7 次插入0 次删除
  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) }