mirror of
https://github.com/golang/go
synced 2024-11-22 06:04:39 -07:00
encoding/binary: add Size, to replace the functionality of the old TotalSize
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5644063
This commit is contained in:
parent
fedc277013
commit
8c4a2ca83b
@ -931,7 +931,8 @@ No changes will be needed.
|
|||||||
<h3 id="encoding_binary">The encoding/binary package</h3>
|
<h3 id="encoding_binary">The encoding/binary package</h3>
|
||||||
|
|
||||||
<p>
|
<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>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -835,7 +835,10 @@ No changes will be needed.
|
|||||||
<h3 id="encoding_binary">The encoding/binary package</h3>
|
<h3 id="encoding_binary">The encoding/binary package</h3>
|
||||||
|
|
||||||
<p>
|
<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>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -253,6 +253,12 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error {
|
|||||||
return err
|
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.
|
// 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
|
// 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
|
// it returns the length of the slice times the element size and does not count the memory
|
||||||
|
Loading…
Reference in New Issue
Block a user