binary

package
v0.0.0-...-27647ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2023 License: BSD-3-Clause Imports: 6 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntDataSize

func IntDataSize(data any) int

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

func Read(r io.Reader, order binary.ByteOrder, data any) error

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

func Size(v any) int

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

func SizeOf(t reflect.Type) int

SizeOf returns the size >= 0 of variables for the given type or -1 if the type is not acceptable.

func ValueSize

func ValueSize(v reflect.Value) int

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

func Write(w io.Writer, order binary.ByteOrder, data any) error

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.

Types

type Coder

type Coder struct {
	Order  binary.ByteOrder
	Buf    []byte
	Offset int
}

type Decoder

type Decoder Coder

func (*Decoder) Bool

func (d *Decoder) Bool() bool

func (*Decoder) Int16

func (d *Decoder) Int16() int16

func (*Decoder) Int32

func (d *Decoder) Int32() int32

func (*Decoder) Int64

func (d *Decoder) Int64() int64

func (*Decoder) Int8

func (d *Decoder) Int8() int8

func (*Decoder) Skip

func (d *Decoder) Skip(v reflect.Value)

func (*Decoder) Uint16

func (d *Decoder) Uint16() uint16

func (*Decoder) Uint32

func (d *Decoder) Uint32() uint32

func (*Decoder) Uint64

func (d *Decoder) Uint64() uint64

func (*Decoder) Uint8

func (d *Decoder) Uint8() uint8

func (*Decoder) Value

func (d *Decoder) Value(v reflect.Value)

type Encoder

type Encoder Coder

func (*Encoder) Bool

func (e *Encoder) Bool(x bool)

func (*Encoder) Int16

func (e *Encoder) Int16(x int16)

func (*Encoder) Int32

func (e *Encoder) Int32(x int32)

func (*Encoder) Int64

func (e *Encoder) Int64(x int64)

func (*Encoder) Int8

func (e *Encoder) Int8(x int8)

func (*Encoder) Skip

func (e *Encoder) Skip(v reflect.Value)

func (*Encoder) Uint16

func (e *Encoder) Uint16(x uint16)

func (*Encoder) Uint32

func (e *Encoder) Uint32(x uint32)

func (*Encoder) Uint64

func (e *Encoder) Uint64(x uint64)

func (*Encoder) Uint8

func (e *Encoder) Uint8(x uint8)

func (*Encoder) Value

func (e *Encoder) Value(v reflect.Value)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL