From 8c4a2ca83b5d1ab04361a15d9380f13077b4dda4 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 9 Feb 2012 11:26:03 +1100 Subject: encoding/binary: add Size, to replace the functionality of the old TotalSize R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5644063 --- src/pkg/encoding/binary/binary.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/pkg/encoding/binary') 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 -- cgit v1.3-5-g9baa