goprotobuf: Introduce new proto.Message type.
Every generated protocol buffer type now implements the proto.Message interface,
which means we can add some compile-time type safety throughout the API
as well as drop a bunch of error cases.
R=r, rsc
CC=golang-dev
http://codereview.appspot.com/6298073
diff --git a/proto/decode.go b/proto/decode.go
index de885f6..bef8d66 100644
--- a/proto/decode.go
+++ b/proto/decode.go
@@ -293,7 +293,7 @@
// Unmarshal parses the protocol buffer representation in buf and places the
// decoded result in pb. If the struct underlying pb does not match
// the data in buf, the results can be unpredictable.
-func Unmarshal(buf []byte, pb interface{}) error {
+func Unmarshal(buf []byte, pb Message) error {
// If the object can unmarshal itself, let it.
if u, ok := pb.(Unmarshaler); ok {
return u.Unmarshal(buf)
@@ -306,7 +306,7 @@
// Buffer and places the decoded result in pb. If the struct
// underlying pb does not match the data in the buffer, the results can be
// unpredictable.
-func (p *Buffer) Unmarshal(pb interface{}) error {
+func (p *Buffer) Unmarshal(pb Message) error {
// If the object can unmarshal itself, let it.
if u, ok := pb.(Unmarshaler); ok {
err := u.Unmarshal(p.buf[p.index:])
@@ -321,7 +321,9 @@
err = p.unmarshalType(typ, false, base)
- stats.Decode++
+ if collectStats {
+ stats.Decode++
+ }
return err
}