factom: github.com/Factom-Asset-Tokens/factom/varintf Index | Files

package varintf

import "github.com/Factom-Asset-Tokens/factom/varintf"

Package varintf implements Factom's varInt_F specification.

The varInt_F specifications uses the top bit (0x80) in each byte as the continuation bit. If this bit is set, continue to read the next byte. If this bit is not set, then this is the last byte. The remaining 7 bits are the actual data of the number. The bytes are ordered big endian, unlike the varInt used by protobuf or provided by package encoding/binary.

https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#variable-integers-varint_f

Index

Package Files

varintf.go

func BufLen Uses

func BufLen(x uint64) int

BufLen returns the number of bytes required to encode x.

This must be used when passing buffers to Put.

Put(buf[:BufLen(x)], x)

func Decode Uses

func Decode(buf []byte) (uint64, int)

Decode buf into uint64 and return the number of bytes used.

If buf encodes a number larger than 64 bits, 0 and -1 is returned.

func Encode Uses

func Encode(x uint64) []byte

Encode x as into a new []byte with length BufLen(x).

Use Put to control the allocation of the slice.

func Put Uses

func Put(buf []byte, x uint64)

Put the encoding of x into buf, which must be exactly equal to BufLen(x). For example,

Put(buf[:BufLen(x)], x)

If len(buf) is not exactly equal to BufLen(x), garbage data will be written into buf.

Package varintf imports 1 packages (graph) and is imported by 1 packages. Updated 2020-07-02. Refresh now. Tools for package owners.