Commit 8c4a2ca8 authored by Rob Pike's avatar Rob Pike

encoding/binary: add Size, to replace the functionality of the old TotalSize

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5644063
parent fedc2770
......@@ -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>
......
......@@ -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>
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment