summaryrefslogtreecommitdiff
path: root/libgo/go/encoding/binary
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-03-02 16:38:43 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-03-02 16:38:43 +0000
commit2d2d80b8bd963f59534897b3d51ef8bd546cb4bc (patch)
treeefa0c55763b34cbc633bc494c2743d1b5d9aaff3 /libgo/go/encoding/binary
parent2ad2700dbf70b2e49575f3f2307839a45cf2f71c (diff)
downloadgcc-2d2d80b8bd963f59534897b3d51ef8bd546cb4bc.tar.gz
libgo: Update to weekly.2012-02-14 release.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184798 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/encoding/binary')
-rw-r--r--libgo/go/encoding/binary/binary.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/libgo/go/encoding/binary/binary.go b/libgo/go/encoding/binary/binary.go
index 4be83f53bd4..b26b1bb2c93 100644
--- a/libgo/go/encoding/binary/binary.go
+++ b/libgo/go/encoding/binary/binary.go
@@ -5,6 +5,9 @@
// Package binary implements translation between
// unsigned integer values and byte sequences
// and the reading and writing of fixed-size values.
+// A fixed-size value is either a fixed-size arithmetic
+// type (int8, uint8, int16, float32, complex64, ...)
+// or an array or struct containing only fixed-size values.
package binary
import (
@@ -119,9 +122,6 @@ func (bigEndian) GoString() string { return "binary.BigEndian" }
// Read reads structured binary data from r into data.
// Data must be a pointer to a fixed-size value or a slice
// of fixed-size values.
-// A fixed-size value is either a fixed-size arithmetic
-// type (int8, uint8, int16, float32, complex64, ...)
-// or an array or struct containing only fixed-size values.
// Bytes read from r are decoded using the specified byte order
// and written to successive fields of the data.
func Read(r io.Reader, order ByteOrder, data interface{}) error {
@@ -176,11 +176,8 @@ func Read(r io.Reader, order ByteOrder, data interface{}) error {
}
// Write writes the binary representation of data into w.
-// Data must be a fixed-size value or a pointer to
-// a fixed-size value.
-// A fixed-size value is either a fixed-size arithmetic
-// type (int8, uint8, int16, float32, complex64, ...)
-// or an array or struct containing only fixed-size values.
+// Data must be a fixed-size value or a slice of fixed-size
+// values, or a pointer to such data.
// Bytes written to w are encoded using the specified byte order
// and read from successive fields of the data.
func Write(w io.Writer, order ByteOrder, data interface{}) error {
@@ -253,6 +250,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, which
+// must be a fixed-size value or a slice of fixed-size values, or a pointer to such data.
+func Size(v interface{}) int {
+ return dataSize(reflect.Indirect(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
@@ -373,6 +376,7 @@ func (d *decoder) value(v reflect.Value) {
for i := 0; i < l; i++ {
d.value(v.Index(i))
}
+
case reflect.Struct:
l := v.NumField()
for i := 0; i < l; i++ {
@@ -428,11 +432,13 @@ func (e *encoder) value(v reflect.Value) {
for i := 0; i < l; i++ {
e.value(v.Index(i))
}
+
case reflect.Struct:
l := v.NumField()
for i := 0; i < l; i++ {
e.value(v.Field(i))
}
+
case reflect.Slice:
l := v.Len()
for i := 0; i < l; i++ {