encode

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: BlueOak-1.0.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func BytesToUint32(i []byte) uint32

BytesToUint32 converts the length-4, big-endian encoded byte slice to a uint32.

func ClearBytes

func ClearBytes(b []byte)

ClearBytes zeroes the byte slice.

func CopySlice

func CopySlice(b []byte) []byte

CopySlice makes a copy of the slice.

func DecodeBlob

func DecodeBlob(b []byte, preAlloc ...int) (byte, [][]byte, error)

DecodeBlob decodes a versioned blob into its version and the pushes extracted from its data. Empty pushes will be nil.

func DecodeUTime

func DecodeUTime(b []byte) time.Time

DecodeUTime interprets bytes as a uint64 millisecond Unix timestamp and creates a time.Time.

func DropMilliseconds

func DropMilliseconds(t time.Time) time.Time

DropMilliseconds returns the time truncated to the previous second.

func ExtractPushes

func ExtractPushes(b []byte, preAlloc ...int) ([][]byte, error)

ExtractPushes parses the linearly-encoded 2D byte slice into a slice of slices. Empty pushes are nil slices.

func FileHash

func FileHash(name string) ([]byte, error)

FileHash generates the SHA256 hash of the specified file.

func RandomBytes

func RandomBytes(len int) []byte

RandomBytes returns a byte slice with the specified length of random bytes.

func Uint16Bytes

func Uint16Bytes(i uint16) []byte

Uint64Bytes converts the uint16 to a length-2, big-endian encoded byte slice.

func Uint32Bytes

func Uint32Bytes(i uint32) []byte

Uint64Bytes converts the uint32 to a length-4, big-endian encoded byte slice.

func Uint64Bytes

func Uint64Bytes(i uint64) []byte

Uint64Bytes converts the uint64 to a length-8, big-endian encoded byte slice.

func UnixMilli

func UnixMilli(t time.Time) int64

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

func UnixMilliU(t time.Time) uint64

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

func UnixTimeMilli(msEpoch int64) time.Time

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) Clear

func (pb PassBytes) Clear()

Clear zeroes the slice.

func (PassBytes) MarshalJSON

func (pb PassBytes) MarshalJSON() ([]byte, error)

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

func (pb *PassBytes) UnmarshalJSON(rawBytes []byte) error

UnmarshalJSON satisfies the json.Unmarshaler interface, parses JSON-encoded data into UTF8-encoded bytes and stores the result in the `PassBytes` pointer.

Jump to

Keyboard shortcuts

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