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/clone.go b/proto/clone.go
index 05fb388..d5bfbe5 100644
--- a/proto/clone.go
+++ b/proto/clone.go
@@ -41,8 +41,7 @@
)
// Clone returns a deep copy of a protocol buffer.
-// pb must be a pointer to a protocol buffer struct.
-func Clone(pb interface{}) interface{} {
+func Clone(pb Message) Message {
in := reflect.ValueOf(pb)
if in.Kind() != reflect.Ptr || in.Elem().Kind() != reflect.Struct {
return nil
@@ -50,7 +49,7 @@
out := reflect.New(in.Type().Elem())
copyStruct(out.Elem(), in.Elem())
- return out.Interface()
+ return out.Interface().(Message)
}
func copyStruct(out, in reflect.Value) {