Documentation ¶
Index ¶
- Variables
- func BytesToUint32(i []byte) uint32
- func ClearBytes(b []byte)
- func CopySlice(b []byte) []byte
- func DecodeBlob(b []byte, preAlloc ...int) (byte, [][]byte, error)
- func DecodeUTime(b []byte) time.Time
- func DropMilliseconds(t time.Time) time.Time
- func ExtractPushes(b []byte, preAlloc ...int) ([][]byte, error)
- func FileHash(name string) ([]byte, error)
- func RandomBytes(len int) []byte
- func Uint16Bytes(i uint16) []byte
- func Uint32Bytes(i uint32) []byte
- func Uint64Bytes(i uint64) []byte
- type BuildyBytes
- type PassBytes
Constants ¶
This section is empty.
Variables ¶
var ( // IntCoder is the DEX-wide integer byte-encoding order. IntCoder must be // BigEndian so that variable length data encodings work as intended. IntCoder = binary.BigEndian // ByteFalse is a byte-slice representation of boolean false. ByteFalse = []byte{0} // ByteTrue is a byte-slice representation of boolean true. ByteTrue = []byte{1} // MaxDataLen is the largest byte slice that can be stored when using // (BuildyBytes).AddData. MaxDataLen = 0x00fe_ffff // top two bytes in big endian stop at 254, signalling 32-bit len )
Functions ¶
func BytesToUint32 ¶
BytesToUint32 converts the length-4, big-endian encoded byte slice to a uint32.
func DecodeBlob ¶
DecodeBlob decodes a versioned blob into its version and the pushes extracted from its data. Empty pushes will be nil.
func DecodeUTime ¶
DecodeUTime interprets bytes as a uint64 millisecond Unix timestamp and creates a time.Time.
func DropMilliseconds ¶
DropMilliseconds returns the time truncated to the previous second.
func ExtractPushes ¶
ExtractPushes parses the linearly-encoded 2D byte slice into a slice of slices. Empty pushes are nil slices.
func RandomBytes ¶
RandomBytes returns a byte slice with the specified length of random bytes.
func Uint16Bytes ¶
Uint64Bytes converts the uint16 to a length-2, big-endian encoded byte slice.
func Uint32Bytes ¶
Uint64Bytes converts the uint32 to a length-4, big-endian encoded byte slice.
func Uint64Bytes ¶
Uint64Bytes converts the uint64 to a length-8, big-endian encoded byte slice.
Types ¶
type BuildyBytes ¶
type BuildyBytes []byte
BuildyBytes is a byte-slice with an AddData method for building linearly encoded 2D byte slices. The AddData method supports chaining. The canonical use case is to create "versioned blobs", where the BuildyBytes is instantiated with a single version byte, and then data pushes are added using the AddData method. Example use:
version := 0 b := BuildyBytes{version}.AddData(data1).AddData(data2)
The versioned blob can be decoded with DecodeBlob to separate the version byte and the "payload". BuildyBytes has some similarities to dcrd's txscript.ScriptBuilder, though simpler and less efficient.
func (BuildyBytes) AddData ¶
func (b BuildyBytes) AddData(d []byte) BuildyBytes
AddData adds the data to the BuildyBytes, and returns the new BuildyBytes. The data has hard-coded length limit of MaxDataLen = 16711679 bytes. The caller should ensure the data is not larger since AddData panics if it is.
type PassBytes ¶
type PassBytes []byte
PassBytes represents a UTF8-encoded byte slice.
func (PassBytes) MarshalJSON ¶
MarshalJSON satisfies the json.Unmarshaler interface, returns a quoted copy of this byte slice. Returns an error if this byte slice is not a valid UTF8-encoded byte slice.
func (*PassBytes) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface, parses JSON-encoded data into UTF8-encoded bytes and stores the result in the `PassBytes` pointer.