varintf

package
v0.0.0-...-d06cbcf Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BufLen

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

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

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

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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