bytes

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EMPTY_BYTES = NewBytes([]byte{})
	MAX_CACHE   = int32(256)
	INT32_BYTES [256]Bytes
	LONG_BYTES  [256]Bytes
)
View Source
var (
	NUMBERMASK_NONE   = NumberMask{}
	NUMBERMASK_TINY   = newNumberMask("TINY", 0)   // TINY编码
	NUMBERMASK_SHORT  = newNumberMask("SHORT", 1)  // SHORT编码
	NUMBERMASK_NORMAL = newNumberMask("NORMAL", 2) // NORMAL编码
	NUMBERMASK_LONG   = newNumberMask("LONG", 3)   // LONG编码
)
View Source
var (
	DEFAULT_CHARSET = "UTF-8"
	MAX_BUFFER_SIZE = 1024 * 1024 * 1024
	BUFFER_SIZE     = 64
	TRUE_BYTE       = byte(0x01)
	FALSE_BYTE      = byte(0x00)
)
View Source
var EMPTY_SLICE = NewSlice([]byte{})

Functions

func BoolToBytes

func BoolToBytes(value bool) byte

func Concat

func Concat(slices ...[]byte) []byte

func Equals

func Equals(bytes1 []byte, bytes2 []byte) bool

*

  • 比较指定的两个字节数组是否一致;
  • 此方法不处理两者其中之一为 nil 的情形

func Int16ToBytes

func Int16ToBytes(value int16) []byte

func Int32ToBytes

func Int32ToBytes(value int32) []byte

*

  • 将 int 值转为4字节的二进制数组; *
  • @param value value
  • @return 转换后的二进制数组,高位在前,低位在后;

func Int64ToBytes

func Int64ToBytes(value int64) []byte

*

  • 将 long 值转为8字节的二进制数组; *
  • @param value value
  • @return 转换后的二进制数组,高位在前,低位在后;

func Int8ToBytes

func Int8ToBytes(value int8) byte

func IntToBytes

func IntToBytes(value int) []byte

func StartsWith

func StartsWith(srcBytes []byte, prefixBytes []byte) bool

func StringToBytes

func StringToBytes(str string) []byte

TODO UTF-8 ?

func ToBoolean

func ToBoolean(b byte) bool

func ToInt

func ToInt(bys []byte) int

func ToInt16

func ToInt16(b []byte) int16

func ToInt32

func ToInt32(b []byte) int32

func ToInt64

func ToInt64(b []byte) int64

func ToInt8

func ToInt8(b byte) int8

func ToString

func ToString(bytes []byte) string

Types

type Bytes

type Bytes struct {
	// contains filtered or unexported fields
}

func FromBase58

func FromBase58(str string) (*Bytes, error)

func FromInt

func FromInt(value int) *Bytes

func FromInt32

func FromInt32(value int32) *Bytes

func FromInt64

func FromInt64(value int64) *Bytes

func FromString

func FromString(str string) *Bytes

func NewBytes

func NewBytes(b []byte) *Bytes

func NewBytesWithPrefix

func NewBytesWithPrefix(prefix *Bytes, b []byte) *Bytes

func (*Bytes) Concat

func (b *Bytes) Concat(key []byte) *Bytes

func (*Bytes) ConcatBytes

func (b *Bytes) ConcatBytes(key Bytes) *Bytes

func (*Bytes) CopyTo

func (b *Bytes) CopyTo(buffer []byte, offset int, size int) int

func (*Bytes) Equals

func (b *Bytes) Equals(obj interface{}) bool

func (*Bytes) GetDirectBytes

func (b *Bytes) GetDirectBytes() []byte

返回当前的字节数组(不包含前缀对象)

func (*Bytes) Size

func (b *Bytes) Size() int

func (*Bytes) ToBase58

func (b *Bytes) ToBase58() string

func (*Bytes) ToBytes

func (b *Bytes) ToBytes() []byte

func (*Bytes) ToString

func (b *Bytes) ToString() string

*

  • 返回 Base58 编码的字符;

func (*Bytes) ToUTF8String

func (b *Bytes) ToUTF8String() string

func (*Bytes) WriteTo

func (b *Bytes) WriteTo(out io.Writer) int

type BytesSerializable

type BytesSerializable interface {

	/**
	 * 以字节数组形式获取字节块的副本;
	 * @return byte[]
	 */
	ToBytes() []byte
}

type NumberMask

type NumberMask struct {
	Name string

	// 掩码位的个数
	BIT_COUNT byte
	// 头部长度的最大值
	MAX_HEADER_LENGTH int32

	// 最大边界值
	MAX_BOUNDARY_SIZE int64
	// 此常量对于 TINY、SHORT、NORMAL 有效
	BOUNDARY_SIZE_0 int64
	BOUNDARY_SIZE_1 int64
	BOUNDARY_SIZE_2 int64
	BOUNDARY_SIZE_3 int64
	BOUNDARY_SIZE_4 int64
	BOUNDARY_SIZE_5 int64
	BOUNDARY_SIZE_6 int64
	BOUNDARY_SIZE_7 int64
	// contains filtered or unexported fields
}

数值掩码;用于以更少的字节空间输出整数的字节数组

func GetNumberMask

func GetNumberMask(name string) NumberMask

func (*NumberMask) Equals

func (mask *NumberMask) Equals(mask2 NumberMask) bool

func (*NumberMask) GenerateMask

func (mask *NumberMask) GenerateMask(number int64) []byte

生成指定数值的掩码 number 要表示的数值;如果值范围超出掩码的有效范围,将引起恐慌

func (*NumberMask) GetBoundarySize

func (mask *NumberMask) GetBoundarySize(headerLength int32) int64

在指定的头部长度下能够表示的数据大小的临界值(不含) headerLength 值范围必须大于 0 ,且小于等于 MAX_HEADER_LENGTH

func (*NumberMask) GetMaskLength

func (mask *NumberMask) GetMaskLength(number int64) int32

获取能够表示指定的数值的掩码长度,即掩码所需的字节数 number 要表示的数值;如果值范围超出掩码的有效范围,将引起恐慌

func (*NumberMask) ResolveMaskLength

func (mask *NumberMask) ResolveMaskLength(headByte byte) (int32, error)

解析掩码的头字节获得该掩码实例的完整长度 headByte 掩码的头字节;即掩码的字节序列的首个字节 返回掩码实例的完整长度 注:在字节流中,对首字节解析获取该值后减 1,可以得到该掩码后续要读取的字节长度

func (*NumberMask) ResolveMaskedNumber

func (mask *NumberMask) ResolveMaskedNumber(markBytes []byte) (int64, error)

从字节中解析掩码表示的数值

func (*NumberMask) WriteMask

func (mask *NumberMask) WriteMask(number int64) []byte

type Slice

type Slice struct {
	Bytes  []byte
	Offset int
	Size   int
}

func NewSlice

func NewSlice(bytes []byte) Slice

func NewSliceWithOffset

func NewSliceWithOffset(bytes []byte, offset int) (*Slice, error)

func NewSliceWithOffsetAndSize

func NewSliceWithOffsetAndSize(bytes []byte, offset, size int) (*Slice, error)

func (Slice) GetByte

func (s Slice) GetByte(offset int) (byte, error)

func (Slice) GetBytesCopy

func (s Slice) GetBytesCopy(offset, size int) ([]byte, error)

func (Slice) GetInt16

func (s Slice) GetInt16(offset int) (int16, error)

func (Slice) GetInt32

func (s Slice) GetInt32(offset int) (int32, error)

func (Slice) GetInt64

func (s Slice) GetInt64(offset int) (int64, error)

func (Slice) GetSlice

func (s Slice) GetSlice(offset, size int) (*Slice, error)

func (Slice) GetString

func (s Slice) GetString() string

func (Slice) IsEmpty

func (s Slice) IsEmpty() bool

func (Slice) ToBytes

func (s Slice) ToBytes() []byte

Jump to

Keyboard shortcuts

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