goprotobuf: Repeated extensions.
Also picks up a tweak to the JSON tags of the XXX_ fields.
R=r
CC=golang-dev
http://codereview.appspot.com/6175045
diff --git a/proto/text.go b/proto/text.go
index 9cd7b69..a8c5429 100644
--- a/proto/text.go
+++ b/proto/text.go
@@ -410,15 +410,27 @@
continue
}
- fmt.Fprintf(w, "[%s]:", desc.Name)
- if !w.compact {
- w.WriteByte(' ')
+ // Repeated extensions will appear as a slice.
+ if !desc.repeated() {
+ writeExtension(w, desc.Name, pb)
+ } else {
+ v := reflect.ValueOf(pb)
+ for i := 0; i < v.Len(); i++ {
+ writeExtension(w, desc.Name, v.Index(i).Interface())
+ }
}
- writeAny(w, reflect.ValueOf(pb), nil)
- w.WriteByte('\n')
}
}
+func writeExtension(w *textWriter, name string, pb interface{}) {
+ fmt.Fprintf(w, "[%s]:", name)
+ if !w.compact {
+ w.WriteByte(' ')
+ }
+ writeAny(w, reflect.ValueOf(pb), nil)
+ w.WriteByte('\n')
+}
+
func marshalText(w io.Writer, pb interface{}, compact bool) {
if pb == nil {
w.Write([]byte("<nil>"))