Documentation ¶
Overview ¶
Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- func IntDataSize(data any) int
- func Read(r io.Reader, order binary.ByteOrder, data any) error
- func Size(v any) int
- func SizeOf(t reflect.Type) int
- func ValueSize(v reflect.Value) int
- func Write(w io.Writer, order binary.ByteOrder, data any) error
- type Coder
- type Decoder
- func (d *Decoder) Bool() bool
- func (d *Decoder) Int16() int16
- func (d *Decoder) Int32() int32
- func (d *Decoder) Int64() int64
- func (d *Decoder) Int8() int8
- func (d *Decoder) Skip(v reflect.Value)
- func (d *Decoder) Uint16() uint16
- func (d *Decoder) Uint32() uint32
- func (d *Decoder) Uint64() uint64
- func (d *Decoder) Uint8() uint8
- func (d *Decoder) Value(v reflect.Value)
- type Encoder
- func (e *Encoder) Bool(x bool)
- func (e *Encoder) Int16(x int16)
- func (e *Encoder) Int32(x int32)
- func (e *Encoder) Int64(x int64)
- func (e *Encoder) Int8(x int8)
- func (e *Encoder) Skip(v reflect.Value)
- func (e *Encoder) Uint16(x uint16)
- func (e *Encoder) Uint32(x uint32)
- func (e *Encoder) Uint64(x uint64)
- func (e *Encoder) Uint8(x uint8)
- func (e *Encoder) Value(v reflect.Value)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntDataSize ¶
IntDataSize returns the size of the data required to represent the data when encoded. It returns zero if the type cannot be implemented by the fast path in Read or Write.
func Read ¶
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. Bytes read from r are decoded using the specified byte order and written to successive fields of the data. When decoding boolean values, a zero byte is decoded as false, and any other non-zero byte is decoded as true. When reading into structs, the field data for fields with blank (_) field names is skipped; i.e., blank field names may be used for padding. When reading into a struct, all non-blank fields must be exported or Read may panic.
The error is EOF only if no bytes were read. If an EOF happens after reading some but not all the bytes, Read returns ErrUnexpectedEOF.
func Size ¶
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. If v is neither of these, Size returns -1.
func SizeOf ¶
SizeOf returns the size >= 0 of variables for the given type or -1 if the type is not acceptable.
func ValueSize ¶
ValueSize 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 occupied by the header. If the type of v is not acceptable, ValueSize returns -1.
func Write ¶
Write writes the binary representation of data into w. Data must be a fixed-size value or a slice of fixed-size values, or a pointer to such data. Boolean values encode as one byte: 1 for true, and 0 for false. Bytes written to w are encoded using the specified byte order and read from successive fields of the data. When writing structs, zero values are written for fields with blank (_) field names.