From e513cbd562c3114eec1ce5dd3aec3a2e84d90ebc Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Mon, 18 Jul 2016 09:33:09 -0700 Subject: [PATCH] vendor: update 'gogo/protobuf' --- cmd/Godeps/Godeps.json | 6 +-- .../github.com/gogo/protobuf/proto/decode.go | 9 ++-- .../github.com/gogo/protobuf/proto/encode.go | 8 +++- .../gogo/protobuf/proto/extensions_gogo.go | 4 ++ .../github.com/gogo/protobuf/proto/text.go | 46 ++++++++++++------- 5 files changed, 48 insertions(+), 25 deletions(-) diff --git a/cmd/Godeps/Godeps.json b/cmd/Godeps/Godeps.json index c274cccd4..539f7b93f 100644 --- a/cmd/Godeps/Godeps.json +++ b/cmd/Godeps/Godeps.json @@ -1,6 +1,6 @@ { "ImportPath": "github.com/coreos/etcd", - "GoVersion": "go1.6", + "GoVersion": "devel-a6dbfc1", "GodepVersion": "v74", "Packages": [ "./..." @@ -71,8 +71,8 @@ }, { "ImportPath": "github.com/gogo/protobuf/proto", - "Comment": "v0.2-13-gc3995ae", - "Rev": "c3995ae437bb78d1189f4f147dfe5f87ad3596e4" + "Comment": "v0.2-33-ge18d7aa", + "Rev": "e18d7aa8f8c624c915db340349aad4c49b10d173" }, { "ImportPath": "github.com/golang/glog", diff --git a/cmd/vendor/github.com/gogo/protobuf/proto/decode.go b/cmd/vendor/github.com/gogo/protobuf/proto/decode.go index cb5b213f9..7b06266d1 100644 --- a/cmd/vendor/github.com/gogo/protobuf/proto/decode.go +++ b/cmd/vendor/github.com/gogo/protobuf/proto/decode.go @@ -773,10 +773,11 @@ func (o *Buffer) dec_new_map(p *Properties, base structPointer) error { } } keyelem, valelem := keyptr.Elem(), valptr.Elem() - if !keyelem.IsValid() || !valelem.IsValid() { - // We did not decode the key or the value in the map entry. - // Either way, it's an invalid map entry. - return fmt.Errorf("proto: bad map data: missing key/val") + if !keyelem.IsValid() { + keyelem = reflect.Zero(p.mtype.Key()) + } + if !valelem.IsValid() { + valelem = reflect.Zero(p.mtype.Elem()) } v.SetMapIndex(keyelem, valelem) diff --git a/cmd/vendor/github.com/gogo/protobuf/proto/encode.go b/cmd/vendor/github.com/gogo/protobuf/proto/encode.go index 231b07401..eb7e0474e 100644 --- a/cmd/vendor/github.com/gogo/protobuf/proto/encode.go +++ b/cmd/vendor/github.com/gogo/protobuf/proto/encode.go @@ -64,6 +64,10 @@ var ( // a struct with a repeated field containing a nil element. errRepeatedHasNil = errors.New("proto: repeated field has nil element") + // errOneofHasNil is the error returned if Marshal is called with + // a struct with a oneof field containing a nil element. + errOneofHasNil = errors.New("proto: oneof field has nil value") + // ErrNil is the error returned if Marshal is called with nil. ErrNil = errors.New("proto: Marshal called with nil") ) @@ -1222,7 +1226,9 @@ func (o *Buffer) enc_struct(prop *StructProperties, base structPointer) error { // Do oneof fields. if prop.oneofMarshaler != nil { m := structPointer_Interface(base, prop.stype).(Message) - if err := prop.oneofMarshaler(m, o); err != nil { + if err := prop.oneofMarshaler(m, o); err == ErrNil { + return errOneofHasNil + } else if err != nil { return err } } diff --git a/cmd/vendor/github.com/gogo/protobuf/proto/extensions_gogo.go b/cmd/vendor/github.com/gogo/protobuf/proto/extensions_gogo.go index f884acac8..86b1fa234 100644 --- a/cmd/vendor/github.com/gogo/protobuf/proto/extensions_gogo.go +++ b/cmd/vendor/github.com/gogo/protobuf/proto/extensions_gogo.go @@ -56,6 +56,10 @@ func (this *Extension) Equal(that *Extension) bool { return bytes.Equal(this.enc, that.enc) } +func (this *Extension) Compare(that *Extension) int { + return bytes.Compare(this.enc, that.enc) +} + func SizeOfExtensionMap(m map[int32]Extension) (n int) { return sizeExtensionMap(m) } diff --git a/cmd/vendor/github.com/gogo/protobuf/proto/text.go b/cmd/vendor/github.com/gogo/protobuf/proto/text.go index e2b99b122..b60be28ab 100644 --- a/cmd/vendor/github.com/gogo/protobuf/proto/text.go +++ b/cmd/vendor/github.com/gogo/protobuf/proto/text.go @@ -335,7 +335,8 @@ func writeStruct(w *textWriter, sv reflect.Value) error { } inner := fv.Elem().Elem() // interface -> *T -> T tag := inner.Type().Field(0).Tag.Get("protobuf") - props.Parse(tag) // Overwrite the outer props. + props = new(Properties) // Overwrite the outer props var, but not its pointee. + props.Parse(tag) // Write the value in the oneof, not the oneof itself. fv = inner.Field(0) @@ -727,7 +728,14 @@ func (w *textWriter) writeIndent() { w.complete = false } -func marshalText(w io.Writer, pb Message, compact bool) error { +// TextMarshaler is a configurable text format marshaler. +type TextMarshaler struct { + Compact bool // use compact text format (one line). +} + +// Marshal writes a given protocol buffer in text format. +// The only errors returned are from w. +func (m *TextMarshaler) Marshal(w io.Writer, pb Message) error { val := reflect.ValueOf(pb) if pb == nil || val.IsNil() { w.Write([]byte("")) @@ -742,7 +750,7 @@ func marshalText(w io.Writer, pb Message, compact bool) error { aw := &textWriter{ w: ww, complete: true, - compact: compact, + compact: m.Compact, } if tm, ok := pb.(encoding.TextMarshaler); ok { @@ -769,25 +777,29 @@ func marshalText(w io.Writer, pb Message, compact bool) error { return nil } +// Text is the same as Marshal, but returns the string directly. +func (m *TextMarshaler) Text(pb Message) string { + var buf bytes.Buffer + m.Marshal(&buf, pb) + return buf.String() +} + +var ( + defaultTextMarshaler = TextMarshaler{} + compactTextMarshaler = TextMarshaler{Compact: true} +) + +// TODO: consider removing some of the Marshal functions below. + // MarshalText writes a given protocol buffer in text format. // The only errors returned are from w. -func MarshalText(w io.Writer, pb Message) error { - return marshalText(w, pb, false) -} +func MarshalText(w io.Writer, pb Message) error { return defaultTextMarshaler.Marshal(w, pb) } // MarshalTextString is the same as MarshalText, but returns the string directly. -func MarshalTextString(pb Message) string { - var buf bytes.Buffer - marshalText(&buf, pb, false) - return buf.String() -} +func MarshalTextString(pb Message) string { return defaultTextMarshaler.Text(pb) } // CompactText writes a given protocol buffer in compact text format (one line). -func CompactText(w io.Writer, pb Message) error { return marshalText(w, pb, true) } +func CompactText(w io.Writer, pb Message) error { return compactTextMarshaler.Marshal(w, pb) } // CompactTextString is the same as CompactText, but returns the string directly. -func CompactTextString(pb Message) string { - var buf bytes.Buffer - marshalText(&buf, pb, true) - return buf.String() -} +func CompactTextString(pb Message) string { return compactTextMarshaler.Text(pb) }