goprotobuf: Equal and String support for RawMessage.
R=r
CC=golang-dev
http://codereview.appspot.com/5889043
diff --git a/proto/text.go b/proto/text.go
index f7279ae..ae0453c 100644
--- a/proto/text.go
+++ b/proto/text.go
@@ -109,6 +109,11 @@
extendableProtoType = reflect.TypeOf((*extendableProto)(nil)).Elem()
)
+// raw is the interface satisfied by RawMessage.
+type raw interface {
+ Bytes() []byte
+}
+
func writeStruct(w *textWriter, sv reflect.Value) {
if sv.Type() == messageSetType {
writeMessageSet(w, sv.Addr().Interface().(*MessageSet))
@@ -159,6 +164,10 @@
if !w.compact {
w.WriteByte(' ')
}
+ if b, ok := fv.Interface().(raw); ok {
+ writeRaw(w, b.Bytes())
+ continue
+ }
if props.Enum != "" && tryWriteEnum(w, props.Enum, fv) {
// Enum written.
} else {
@@ -174,6 +183,18 @@
}
}
+// writeRaw writes an uninterpreted raw message.
+func writeRaw(w *textWriter, b []byte) {
+ w.WriteByte('<')
+ if !w.compact {
+ w.WriteByte('\n')
+ }
+ w.indent()
+ writeUnknownStruct(w, b)
+ w.unindent()
+ w.WriteByte('>')
+}
+
// tryWriteEnum attempts to write an enum value as a symbolic constant.
// If the enum is unregistered, nothing is written and false is returned.
func tryWriteEnum(w *textWriter, enum string, v reflect.Value) bool {