]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/binary: add Size, to replace the functionality of the old TotalSize
authorRob Pike <r@golang.org>
Thu, 9 Feb 2012 00:26:03 +0000 (11:26 +1100)
committerRob Pike <r@golang.org>
Thu, 9 Feb 2012 00:26:03 +0000 (11:26 +1100)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5644063

doc/go1.html
doc/go1.tmpl
src/pkg/encoding/binary/binary.go

index 28f17f1b5d12db02119a60cb44da76e9c9829635..8b0b4745e36d6bd1fea44f023de10de86607827a 100644 (file)
@@ -931,7 +931,8 @@ No changes will be needed.
 <h3 id="encoding_binary">The encoding/binary package</h3>
 
 <p>
-In Go 1, the <code>binary.TotalSize</code></a> function is no longer exported.
+In Go 1, the <code>binary.TotalSize</code> function is renamed
+<a href="/pkg/encoding/binary/#Size"><code>Size</code></a>.
 </p>
 
 <p>
index 6375ebcc00947a815739712c139741ebd3215257..d6803ed18939ffecaec385464544794e85188650 100644 (file)
@@ -835,7 +835,10 @@ No changes will be needed.
 <h3 id="encoding_binary">The encoding/binary package</h3>
 
 <p>
-In Go 1, the <code>binary.TotalSize</code></a> function is no longer exported.
+In Go 1, the <code>binary.TotalSize</code> function has been replaced by
+<a href="/pkg/encoding/binary/#Size"><code>Size</code></a>,
+which takes an <code>interface{}</code> argument rather than
+a <code>reflect.Value</code>.
 </p>
 
 <p>
index 4be83f53bd489f51f9b84b7ac3cb3bf835663e1d..7f10d40a11598e8e2cded26f5eef570edaca29c7 100644 (file)
@@ -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