util

package
v0.87.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package util contains helpers for encoding/decoding tlvs to maintain parity with other moneysocket implementations

Index

Constants

View Source
const (
	// TLVMinimum is the minimum tlv value
	// types cannot be less than 2^16 according to bolt-1 https://git.io/JLCRq
	TLVMinimum = 65536

	// TLVTypeStart is the starting value is 2^16+443 and
	// will increment by 2 for new types https://git.io/JLCRc
	TLVTypeStart = TLVMinimum + 443

	// BeaconTLVType is the tlv type for a beacon.
	BeaconTLVType tlv.Type = TLVTypeStart

	// SharedSeedTLVType is the tlv type for a shared type.
	SharedSeedTLVType tlv.Type = TLVTypeStart + 2

	// LocationCountTLVType is the tlv type for a location count.
	LocationCountTLVType tlv.Type = TLVTypeStart + 4

	// LocationListTLVType is the tkv type that prefixes a list of tlv locations.
	LocationListTLVType tlv.Type = TLVTypeStart + 6

	// WebsocketLocationTLVType is the tlv type used for websockets.
	WebsocketLocationTLVType tlv.Type = TLVTypeStart + 8

	// WebRTCLocationTLVType is the tlv type of a web rtc location
	// TODO beacons/__init.py https://git.io/JLC0J
	WebRTCLocationTLVType = TLVTypeStart + 10

	// BluetoothLocationTLVType is the bluetooth location tlv type
	// TODO beacons/__init__.py https://git.io/JLC0I
	BluetoothLocationTLVType tlv.Type = TLVTypeStart + 12

	// NFCLocationTLVType is the tlv type of an nfc loation tlv
	// TODO beacons/__init__.py https://git.io/JLC0g
	NFCLocationTLVType tlv.Type = TLVTypeStart + 14
)

Variables

TLVTypes is a list of all custom implemented tlv types in the package.

Functions

func DVarInt

func DVarInt(r io.Reader, val interface{}, _ *[8]byte, l uint64) error

DVarInt is a Decoder for variable byte slices. An error is returned if val is not *[]byte. This is not currently implemented since these kinds of decodings are done manually using the bigsize module.

func EVarInt

func EVarInt(w io.Writer, val interface{}, b *[8]byte) error

EVarInt is an Encoder for variable byte slices. An error is returned if val is not *[]byte.

func NamespaceTLVsAreValid added in v0.40.0

func NamespaceTLVsAreValid(byteString []byte) bool

NamespaceTLVsAreValid will determine if a bytestring contains valid tlvs.

Types

type TLV added in v0.40.0

type TLV struct {
	// contains filtered or unexported fields
}

TLV is used for encoding/decoding values to/from TLV (Type-Length-Value) byte strings as defined in: https://git.io/JmwOl note: I tried to use the golang implementation, but didn't quite get the streaming encodes/decodes to work. this can be fixed in a future version.

func NamespaceIterTLVs added in v0.40.0

func NamespaceIterTLVs(byteString []byte) (tlvs []TLV, err error)

NamespaceIterTLVs will iterate over the namespaces in a byteString returns error if all are not valid.

func NamespacePopTLVs added in v0.40.0

func NamespacePopTLVs(byteString []byte) (t TLV, remainder []byte, err error)

NamespacePopTLVs Represents a specific namespace of TLVs as referred to in BOLT 1 and provides generic pop helpers for the fundamental types defined here: https://git.io/JmwOJ and https://git.io/JmwOk

func TLVPop added in v0.40.0

func TLVPop(byteString []byte) (tlv TLV, remainder []byte, err error)

TLVPop returns the first TLV from a byteString and returns the remainder returns error if this cannot be done.

func (TLV) Length added in v0.40.0

func (tlv TLV) Length() int

Length gets l of tlv.t.

func (TLV) Type added in v0.40.0

func (tlv TLV) Type() tlvHelper.Type

Type get tlv.type.

func (TLV) Value added in v0.40.0

func (tlv TLV) Value() []byte

Value gets value of tlv.

Directories

Path Synopsis
Package bigsize emulates the bigsize module of py-moneysocket to achieve parity on various kinds of tlv encodings
Package bigsize emulates the bigsize module of py-moneysocket to achieve parity on various kinds of tlv encodings

Jump to

Keyboard shortcuts

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