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/encode.go b/proto/encode.go
index 1248e97..d44b907 100644
--- a/proto/encode.go
+++ b/proto/encode.go
@@ -61,9 +61,6 @@
 
 	// ErrNil is the error returned if Marshal is called with nil.
 	ErrNil = errors.New("proto: Marshal called with nil")
-
-	// ErrNotPtr is the error returned if Marshal is called with something other than a pointer to a struct.
-	ErrNotPtr = errors.New("proto: Marshal called with something other than a pointer to a struct")
 )
 
 // The fundamental encoders that put bytes on the wire.
@@ -169,9 +166,9 @@
 	Marshal() ([]byte, error)
 }
 
-// Marshal takes the protocol buffer struct represented by pb
+// Marshal takes the protocol buffer
 // and encodes it into the wire format, returning the data.
-func Marshal(pb interface{}) ([]byte, error) {
+func Marshal(pb Message) ([]byte, error) {
 	// Can the object marshal itself?
 	if m, ok := pb.(Marshaler); ok {
 		return m.Marshal()
@@ -184,10 +181,10 @@
 	return p.buf, err
 }
 
-// Marshal takes the protocol buffer struct represented by pb
+// Marshal takes the protocol buffer
 // and encodes it into the wire format, writing the result to the
 // Buffer.
-func (p *Buffer) Marshal(pb interface{}) error {
+func (p *Buffer) Marshal(pb Message) error {
 	// Can the object marshal itself?
 	if m, ok := pb.(Marshaler); ok {
 		data, err := m.Marshal()
@@ -203,7 +200,9 @@
 		err = p.enc_struct(t.Elem(), b)
 	}
 
-	stats.Encode++
+	if collectStats {
+		stats.Encode++
+	}
 
 	return err
 }