Documentation
¶
Index ¶
- Constants
- Variables
- type ByteOrder
- type Endianess
- func (b *Endianess) From(src interface{}, dst []byte) (int, error)
- func (b *Endianess) FromF32(src []float32, dst []byte) (n int)
- func (b *Endianess) FromF64(src []float64, dst []byte) (n int)
- func (b *Endianess) FromI8(src []int8, dst []byte) (n int)
- func (b *Endianess) FromI16(src []int16, dst []byte) (n int)
- func (b *Endianess) FromI32(src []int32, dst []byte) (n int)
- func (b *Endianess) FromI64(src []int64, dst []byte) (n int)
- func (b *Endianess) FromU16(src []uint16, dst []byte) (n int)
- func (b *Endianess) FromU32(src []uint32, dst []byte) (n int)
- func (b *Endianess) FromU64(src []uint64, dst []byte) (n int)
- func (b *Endianess) FromValue(src reflect.Value, dst []byte) (int, error)
- func (b *Endianess) IsBigEndian() bool
- func (b *Endianess) To(src []byte, dst interface{}) (int, error)
- func (b *Endianess) ToF32(src []byte, dst []float32) (n int)
- func (b *Endianess) ToF64(src []byte, dst []float64) (n int)
- func (b *Endianess) ToI8(src []byte, dst []int8) (n int)
- func (b *Endianess) ToI16(src []byte, dst []int16) (n int)
- func (b *Endianess) ToI32(src []byte, dst []int32) (n int)
- func (b *Endianess) ToI64(src []byte, dst []int64) (n int)
- func (b *Endianess) ToU16(src []byte, dst []uint16) (n int)
- func (b *Endianess) ToU32(src []byte, dst []uint32) (n int)
- func (b *Endianess) ToU64(src []byte, dst []uint64) (n int)
- func (b *Endianess) ToValue(src []byte, dst reflect.Value) (int, error)
Constants ¶
const ( // ErrUnsupported the given type is not supported. // All signed and unsigned integers except uint and int, and floats are supported // uint and int are unsupported since their size is platform dependent. ErrUnsupported = errors.Const("fastbytes: unsupported target/source type") // ErrUnaddressable the given [reflect.Value] cannot be addressed ErrUnaddressable = errors.Const("fastbytes: un-addressable value") )
const ( // ErrUnadressable typo // // Deprecated: Use [ErrUnaddressable] instead. ErrUnadressable = ErrUnaddressable )
Variables ¶
var ( // BigEndian copies bytes to and from big endian byte slices BigEndian = Endianess{/* contains filtered or unexported fields */} // LittleEndian copies bytes to and from little endian byte slices LittleEndian = Endianess{/* contains filtered or unexported fields */} )
Functions ¶
This section is empty.
Types ¶
type ByteOrder ¶
type ByteOrder interface {
// FromI8 converts and copies bytes from `src` into `dst`.
// The number of bytes copied is min(len(src), len(dst))
FromI8(src []int8, dst []byte) (n int)
// FromI16 converts and copies []int16 from `src` into `dst`.
// The number of bytes copied is min(len(src)*2, len(dst))
FromI16(src []int16, dst []byte) (n int)
// FromU16 converts and copies []uint16 from `src` into `dst`.
// The number of bytes copied is min(len(src)*2, len(dst))
FromU16(src []uint16, dst []byte) (n int)
// FromI32 converts and copies []int32 from `src` into `dst`.
// The number of bytes copied is min(len(src)*4, len(dst))
FromI32(src []int32, dst []byte) (n int)
// FromU32 converts and copies []uint32 from `src` into `dst`.
// The number of bytes copied is min(len(src)*4, len(dst))
FromU32(src []uint32, dst []byte) (n int)
// FromF32 converts and copies []float32 from `src` into `dst`.
// The number of bytes copied is min(len(src)*4, len(dst))
FromF32(src []float32, dst []byte) (n int)
// FromI64 converts and copies []int64 from `src` into `dst`.
// The number of bytes copied is min(len(src)*8, len(dst))
FromI64(src []int64, dst []byte) (n int)
// FromU64 converts and copies []int64 from `src` into `dst`.
// The number of bytes copied is min(len(src)*8, len(dst))
FromU64(src []uint64, dst []byte) (n int)
// FromF64 converts and copies []float64 from `src` into `dst`.
// The number of bytes copied is min(len(src)*8, len(dst))
FromF64(src []float64, dst []byte) (n int)
// ToI8 converts and copies bytes from `src` into `dst`
// The number of bytes copied is min(len(src), len(dst))
ToI8(src []byte, dst []int8) (n int)
// ToI16 converts and copies bytes form `src` into `dst`
// The number of bytes copied is min(len(src), len(dst)*2)
ToI16(src []byte, dst []int16) (n int)
// ToU16 converts and copies bytes from `src` into `dst`
// The number of bytes copied is min(len(src), len(dst)*2)
ToU16(src []byte, dst []uint16) (n int)
// ToI32 converts and copies bytes from `src` into `dst`
// The number of bytes copied is min(len(src), len(dst)*4)
ToI32(src []byte, dst []int32) (n int)
// ToU32 converts and copies bytes from `src` into `dst`
// The number of bytes copied is min(len(src), len(dst)*4)
ToU32(src []byte, dst []uint32) (n int)
// ToF32 converts and copies bytes from `src` into `dst`
// The number of bytes copied is min(len(src), len(dst)*4)
ToF32(src []byte, dst []float32) (n int)
// ToI64 converts and copies bytes from `src` into `dst`
// The number of bytes copied is min(len(src), len(dst)*8)
ToI64(src []byte, dst []int64) (n int)
// ToU64 converts and copies bytes from `src` into `dst`
// The number of bytes copied is min(len(src), len(dst)*8)
ToU64(src []byte, dst []uint64) (n int)
// ToU64 converts and copies bytes from `src` into `dst`
// The number of bytes copied is min(len(src), len(dst)*8)
ToF64(src []byte, dst []float64) (n int)
// To copies bytes from `s` into the given slice.
// The given interface must be a type that can be safely written to.
// The number of bytes copied is min(len(src), len(dst)* element size of dst)
To(src []byte, dst interface{}) (n int, err error)
// From copies bytes from the given interface.
// The provided interface must be a type that can be safely copied.
// The number of bytes copied is min(len(src)* element size of dst, len(dst))
From(src interface{}, dst []byte) (n int, err error)
// ToValue copies bytes from `src` into the given value
// The given interface must be a type that can be safely written to.
// The number of bytes copied is min(len(src), len(dst)* element size of dst)
ToValue(src []byte, dst reflect.Value) (n int, err error)
// FromValue copies bytes from the given value.
// The provided value must be a type that can be safely converted to bytes.
// The number of bytes copied is min(len(src)* element size of dst, len(dst))
FromValue(src reflect.Value, dst []byte) (n int, err error)
// contains filtered or unexported methods
}
ByteOrder a byteorder.
It is recommended to use Endianess instead.
type Endianess ¶ added in v2.2.0
type Endianess struct {
// contains filtered or unexported fields
}
Endianess provides methods to read and write integer/float slices.
func (*Endianess) From ¶ added in v2.2.0
From copies bytes from the given interface. The provided interface must be a type that can be safely copied. The number of bytes copied is min(len(src)* element size of dst, len(dst))
func (*Endianess) FromF32 ¶ added in v2.2.0
FromF32 converts and copies []float32 from `src` into `dst`. The number of bytes copied is min(len(src)*4, len(dst))
func (*Endianess) FromF64 ¶ added in v2.2.0
FromF64 converts and copies []float64 from `src` into `dst`. The number of bytes copied is min(len(src)*8, len(dst))
func (*Endianess) FromI8 ¶ added in v2.2.0
FromI8 converts and copies bytes from `src` into `dst`. The number of bytes copied is min(len(src), len(dst))
func (*Endianess) FromI16 ¶ added in v2.2.0
FromI16 converts and copies []int16 from `src` into `dst`. The number of bytes copied is min(len(src)*2, len(dst))
func (*Endianess) FromI32 ¶ added in v2.2.0
FromI32 converts and copies []int32 from `src` into `dst`. The number of bytes copied is min(len(src)*4, len(dst))
func (*Endianess) FromI64 ¶ added in v2.2.0
FromI64 converts and copies []int64 from `src` into `dst`. The number of bytes copied is min(len(src)*8, len(dst))
func (*Endianess) FromU16 ¶ added in v2.2.0
FromU16 converts and copies []uint16 from `src` into `dst`. The number of bytes copied is min(len(src)*2, len(dst))
func (*Endianess) FromU32 ¶ added in v2.2.0
FromU32 converts and copies []uint32 from `src` into `dst`. The number of bytes copied is min(len(src)*4, len(dst))
func (*Endianess) FromU64 ¶ added in v2.2.0
FromU64 converts and copies []int64 from `src` into `dst`. The number of bytes copied is min(len(src)*8, len(dst))
func (*Endianess) FromValue ¶ added in v2.2.0
FromValue copies bytes from the given value. The provided value must be a type that can be safely converted to bytes. The number of bytes copied is min(len(src)* element size of dst, len(dst))
func (*Endianess) IsBigEndian ¶ added in v2.2.0
IsBigEndian returns if the endianess of this struct is big endian. If this returns false, the endianess is little endian. This returns the endianess this struct read/writes not the system endianess.
func (*Endianess) To ¶ added in v2.2.0
To copies bytes from `s` into the given slice. The given interface must be a type that can be safely written to. The number of bytes copied is min(len(src), len(dst)* element size of dst)
func (*Endianess) ToF32 ¶ added in v2.2.0
ToF32 converts and copies bytes from `src` into `dst` The number of bytes copied is min(len(src), len(dst)*4)
func (*Endianess) ToF64 ¶ added in v2.2.0
ToF64 converts and copies bytes from `src` into `dst` The number of bytes copied is min(len(src), len(dst)*8)
func (*Endianess) ToI8 ¶ added in v2.2.0
ToI8 converts and copies bytes from `src` into `dst` The number of bytes copied is min(len(src), len(dst))
func (*Endianess) ToI16 ¶ added in v2.2.0
ToI16 converts and copies bytes form `src` into `dst` The number of bytes copied is min(len(src), len(dst)*2)
func (*Endianess) ToI32 ¶ added in v2.2.0
ToI32 converts and copies bytes from `src` into `dst` The number of bytes copied is min(len(src), len(dst)*4)
func (*Endianess) ToI64 ¶ added in v2.2.0
ToI64 converts and copies bytes from `src` into `dst` The number of bytes copied is min(len(src), len(dst)*8)
func (*Endianess) ToU16 ¶ added in v2.2.0
ToU16 converts and copies bytes form `src` into `dst` The number of bytes copied is min(len(src), len(dst)*2)
func (*Endianess) ToU32 ¶ added in v2.2.0
ToU32 converts and copies bytes from `src` into `dst` The number of bytes copied is min(len(src), len(dst)*4)
func (*Endianess) ToU64 ¶ added in v2.2.0
ToU64 converts and copies bytes from `src` into `dst` The number of bytes copied is min(len(src), len(dst)*8)