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
- func UnixMilli(t time.Time) int64
- func UnixMilliU(t time.Time) uint64
- func UnixTimeMilli(msEpoch int64) time.Time
- type BuildyBytes
- type PassBytes
Constants ¶
This section is empty.
Variables ¶
var ( // IntCoder is the DEX-wide integer byte-encoding order. IntCoder = binary.BigEndian // A byte-slice representation of boolean false. ByteFalse = []byte{0} // A byte-slice representation of boolean true. ByteTrue = []byte{1} )
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.
func UnixMilli ¶
UnixMilli returns the elapsed time in milliseconds since the Unix Epoch for the given time as an int64. The Location does not matter.
func UnixMilliU ¶
UnixMilliU returns the elapsed time in milliseconds since the Unix Epoch for the given time as a uint64. The Location does not matter.
func UnixTimeMilli ¶
UnixTimeMilli returns a Time for an elapsed time in milliseconds since the Unix Epoch. The time will have Location set to UTC.
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 instantated 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 uint16_max = 65535 bytes.
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.