diff --git a/doc/go1.html b/doc/go1.html index 28f17f1b5d1..8b0b4745e36 100644 --- a/doc/go1.html +++ b/doc/go1.html @@ -931,7 +931,8 @@ No changes will be needed.
-In Go 1, the binary.TotalSize
function is no longer exported.
+In Go 1, the binary.TotalSize
function is renamed
+Size
.
diff --git a/doc/go1.tmpl b/doc/go1.tmpl index 6375ebcc009..d6803ed1893 100644 --- a/doc/go1.tmpl +++ b/doc/go1.tmpl @@ -835,7 +835,10 @@ No changes will be needed.
-In Go 1, the binary.TotalSize
function is no longer exported.
+In Go 1, the binary.TotalSize
function has been replaced by
+Size
,
+which takes an interface{}
argument rather than
+a reflect.Value
.
diff --git a/src/pkg/encoding/binary/binary.go b/src/pkg/encoding/binary/binary.go index 4be83f53bd4..7f10d40a115 100644 --- a/src/pkg/encoding/binary/binary.go +++ b/src/pkg/encoding/binary/binary.go @@ -253,6 +253,12 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error { return err } +// Size returns how many bytes Write would generate to encode the value v, assuming +// the Write would succeed. +func Size(v interface{}) int { + return dataSize(reflect.ValueOf(v)) +} + // dataSize returns the number of bytes the actual data represented by v occupies in memory. // For compound structures, it sums the sizes of the elements. Thus, for instance, for a slice // it returns the length of the slice times the element size and does not count the memory