binary

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GZipCompress

func GZipCompress(data []byte) []byte

func GZipUncompress

func GZipUncompress(src []byte) []byte

func PutBuilder

func PutBuilder(w *Builder)

PutBuilder 将 Builder 放回池中

func ReleaseGzipWriter

func ReleaseGzipWriter(w *GzipWriter)

func UInt32ToIPV4Address

func UInt32ToIPV4Address(i uint32) string

func ZlibCompress

func ZlibCompress(data []byte) []byte

func ZlibUncompress

func ZlibUncompress(src []byte) []byte

Types

type Builder

type Builder struct {
	io.Writer
	io.ReaderFrom
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(key []byte) *Builder

NewBuilder with finalizer of itself.

Be sure to use all data before builder is GCed.

func SelectBuilder

func SelectBuilder(key []byte) *Builder

SelectBuilder 从池中取出一个 Builder

func (*Builder) EncryptAndWrite

func (b *Builder) EncryptAndWrite(key []byte, data []byte) *Builder

func (*Builder) Len

func (b *Builder) Len() int

func (*Builder) Pack

func (b *Builder) Pack(typ uint16) []byte

Pack TLV with tea encryption if key is set

GC 安全, 返回的数据在 Builder 被销毁之后仍能被正确读取, 但是只能调用一次, 调用后 Builder 即失效

func (*Builder) ReadFrom

func (b *Builder) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom for impl. io.ReaderFrom

func (*Builder) ToBytes

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

ToBytes return data with tea encryption if key is set

GC 安全, 返回的数据在 Builder 被销毁之后仍能被正确读取, 但是只能调用一次, 调用后 Builder 即失效

func (*Builder) ToReader

func (b *Builder) ToReader() io.Reader

ToReader GC 不安全, 确保在 Builder 被回收前使用

func (*Builder) Write

func (b *Builder) Write(p []byte) (n int, err error)

Write for impl. io.Writer

func (*Builder) WriteBool

func (b *Builder) WriteBool(v bool) *Builder

func (*Builder) WriteBytes

func (b *Builder) WriteBytes(v []byte) *Builder

func (*Builder) WriteDouble

func (b *Builder) WriteDouble(v float64) *Builder

func (*Builder) WriteFloat

func (b *Builder) WriteFloat(v float32) *Builder

func (*Builder) WriteI16

func (b *Builder) WriteI16(v int16) *Builder

func (*Builder) WriteI32

func (b *Builder) WriteI32(v int32) *Builder

func (*Builder) WriteI64

func (b *Builder) WriteI64(v int64) *Builder

func (*Builder) WriteI8

func (b *Builder) WriteI8(v int8) *Builder

func (*Builder) WriteLenBytes

func (b *Builder) WriteLenBytes(v []byte) *Builder

func (*Builder) WriteLenString

func (b *Builder) WriteLenString(v string) *Builder

func (*Builder) WritePacketBytes

func (b *Builder) WritePacketBytes(v []byte, prefix string, withPrefix bool) *Builder

WritePacketBytes prefix must not be empty

func (*Builder) WritePacketString

func (b *Builder) WritePacketString(s, prefix string, withPrefix bool) *Builder

func (*Builder) WriteStruct

func (b *Builder) WriteStruct(data ...any) *Builder

func (*Builder) WriteTLV

func (b *Builder) WriteTLV(tlvs ...[]byte) *Builder

func (*Builder) WriteU16

func (b *Builder) WriteU16(v uint16) *Builder

func (*Builder) WriteU32

func (b *Builder) WriteU32(v uint32) *Builder

func (*Builder) WriteU64

func (b *Builder) WriteU64(v uint64) *Builder

func (*Builder) WriteU8

func (b *Builder) WriteU8(v uint8) *Builder

type GzipWriter

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

func AcquireGzipWriter

func AcquireGzipWriter() *GzipWriter

func (*GzipWriter) Bytes

func (w *GzipWriter) Bytes() []byte

func (*GzipWriter) Close

func (w *GzipWriter) Close() error

func (*GzipWriter) Write

func (w *GzipWriter) Write(p []byte) (int, error)

type NetworkReader

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

func NewNetworkReader

func NewNetworkReader(conn net.Conn) *NetworkReader

func (*NetworkReader) ReadByte

func (r *NetworkReader) ReadByte() (byte, error)

func (*NetworkReader) ReadBytes

func (r *NetworkReader) ReadBytes(len int) ([]byte, error)

func (*NetworkReader) ReadInt32

func (r *NetworkReader) ReadInt32() (int32, error)

type Reader

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

func NewReader

func NewReader(buffer []byte) *Reader

func ParseReader

func ParseReader(reader io.Reader) *Reader

func (*Reader) Len

func (r *Reader) Len() int

func (*Reader) ReadAll

func (r *Reader) ReadAll() []byte

ReadAll means read all available data and return them

if r.reader got error, it will return nil

func (*Reader) ReadBytes

func (r *Reader) ReadBytes(length int) (v []byte)

func (*Reader) ReadBytesNoCopy

func (r *Reader) ReadBytesNoCopy(length int) (v []byte)

ReadBytesNoCopy 不拷贝读取的数据, 用于读取后立即使用, 慎用

如需使用, 请确保 Reader 未被回收

func (*Reader) ReadBytesWithLength

func (r *Reader) ReadBytesWithLength(prefix string, withPerfix bool) []byte

func (*Reader) ReadI16

func (r *Reader) ReadI16() (v int16)

func (*Reader) ReadI32

func (r *Reader) ReadI32() (v int32)

func (*Reader) ReadI64

func (r *Reader) ReadI64() (v int64)

func (*Reader) ReadI8

func (r *Reader) ReadI8() (v int8)

func (*Reader) ReadString

func (r *Reader) ReadString(length int) string

func (*Reader) ReadStringWithLength

func (r *Reader) ReadStringWithLength(prefix string, withPerfix bool) string

func (*Reader) ReadTlv

func (r *Reader) ReadTlv() (result map[uint16][]byte)

func (*Reader) ReadU16

func (r *Reader) ReadU16() (v uint16)

func (*Reader) ReadU32

func (r *Reader) ReadU32() (v uint32)

func (*Reader) ReadU64

func (r *Reader) ReadU64() (v uint64)

func (*Reader) ReadU8

func (r *Reader) ReadU8() (v uint8)

func (*Reader) SkipBytes

func (r *Reader) SkipBytes(length int)

func (*Reader) SkipBytesWithLength

func (r *Reader) SkipBytesWithLength(prefix string, withPerfix bool)

func (*Reader) String

func (r *Reader) String() string

String means read all available data and return them as a string

if r.reader got error, it will returns as err.Error()

Jump to

Keyboard shortcuts

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