mirror of
https://github.com/golang/go.git
synced 2024-09-30 14:57:10 +00:00
encoding/binary: another attempt to describe the type of Read and Write's data
R=golang-dev, rsc, gri, r CC=golang-dev https://golang.org/cl/5641062
This commit is contained in:
parent
54f1e1b163
commit
59dc21584a
@ -5,6 +5,9 @@
|
|||||||
// Package binary implements translation between
|
// Package binary implements translation between
|
||||||
// unsigned integer values and byte sequences
|
// unsigned integer values and byte sequences
|
||||||
// and the reading and writing of fixed-size values.
|
// 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
|
package binary
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -117,11 +120,8 @@ func (bigEndian) String() string { return "BigEndian" }
|
|||||||
func (bigEndian) GoString() string { return "binary.BigEndian" }
|
func (bigEndian) GoString() string { return "binary.BigEndian" }
|
||||||
|
|
||||||
// Read reads structured binary data from r into data.
|
// Read reads structured binary data from r into data.
|
||||||
// Data must be a pointer to a decodable value or a slice
|
// Data must be a pointer to a fixed-size value or a slice
|
||||||
// of decodable values.
|
// of fixed-size values.
|
||||||
// A decodable value is either a fixed-size arithmetic
|
|
||||||
// type (int8, uint8, int16, float32, complex64, ...)
|
|
||||||
// or an array, slice or struct containing only decodable values.
|
|
||||||
// Bytes read from r are decoded using the specified byte order
|
// Bytes read from r are decoded using the specified byte order
|
||||||
// and written to successive fields of the data.
|
// and written to successive fields of the data.
|
||||||
func Read(r io.Reader, order ByteOrder, data interface{}) error {
|
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.
|
// Write writes the binary representation of data into w.
|
||||||
// Data must be an encodable value or a pointer to
|
// Data must be a fixed-size value or a slice of fixed-size
|
||||||
// an encodable value.
|
// values, or a pointer to such data.
|
||||||
// An encodable value is either a fixed-size arithmetic
|
|
||||||
// type (int8, uint8, int16, float32, complex64, ...)
|
|
||||||
// or an array, slice or struct containing only encodable values.
|
|
||||||
// Bytes written to w are encoded using the specified byte order
|
// Bytes written to w are encoded using the specified byte order
|
||||||
// and read from successive fields of the data.
|
// and read from successive fields of the data.
|
||||||
func Write(w io.Writer, order ByteOrder, data interface{}) error {
|
func Write(w io.Writer, order ByteOrder, data interface{}) error {
|
||||||
@ -253,10 +250,10 @@ 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
|
// Size returns how many bytes Write would generate to encode the value v, which
|
||||||
// the Write would succeed.
|
// must be a fixed-size value or a slice of fixed-size values, or a pointer to such data.
|
||||||
func Size(v interface{}) int {
|
func Size(v interface{}) int {
|
||||||
return dataSize(reflect.ValueOf(v))
|
return dataSize(reflect.Indirect(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.
|
||||||
|
Loading…
Reference in New Issue
Block a user