aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/encoding/binary
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2012-02-09 11:26:03 +1100
committerRob Pike <r@golang.org>2012-02-09 11:26:03 +1100
commit8c4a2ca83b5d1ab04361a15d9380f13077b4dda4 (patch)
tree1c68d8d565f05d4ac8aa5e19910402c3c28bb5cc /src/pkg/encoding/binary
parentfedc277013d7b8d2812c3ccb869e1a8530b5f6f5 (diff)
downloadgo-8c4a2ca83b5d1ab04361a15d9380f13077b4dda4.tar.xz
encoding/binary: add Size, to replace the functionality of the old TotalSize
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5644063
Diffstat (limited to 'src/pkg/encoding/binary')
-rw-r--r--src/pkg/encoding/binary/binary.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/pkg/encoding/binary/binary.go b/src/pkg/encoding/binary/binary.go
index 4be83f53bd..7f10d40a11 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