bencodeext

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package bencodeext defines some extenstions for bencode to work better with the existing JavaScript type system. Mainly, it adds a way to encode bools, null/undefined and unicode values without ambiguity.

The concrete encoding table is taken from https://github.com/ssb-ngi-pointer/ssb-binary-field-encodings-spec

Index

Constants

This section is empty.

Variables

View Source
var (
	Null           = []byte{0x06, 0x02}
	NullRawMessage = bencode.RawMessage{'2', ':', 0x06, 0x02}
)

Null (or undefined) is encoded as a 2 byte string (0x0602)

Functions

This section is empty.

Types

type Bool

type Bool bool

Bool is encoded as a 3 byte string. 0x060100 for false and 0x060101 for true.

func (Bool) MarshalBencode

func (b Bool) MarshalBencode() ([]byte, error)

MarshalBencode encodes a bool as a string with 3 characters.

func (*Bool) UnmarshalBencode

func (b *Bool) UnmarshalBencode(input []byte) error

UnmarshalBencode checks for the two variations '3:\x06\x01\x00" for false and '3:\x06\x01\x01" for true.

type Bytes

type Bytes []byte

Bytes is here since _technically_ bencode only supports byte strings and we want to make extra sure that these are arbitrary bytes.

func (Bytes) MarshalBencode

func (b Bytes) MarshalBencode() ([]byte, error)

MarshalBencode turns the value into a receiver in a byte string with the prefix 0x0603

func (*Bytes) UnmarshalBencode

func (s *Bytes) UnmarshalBencode(input []byte) error

UnmarshalBencode decodes the length before the : then checks if the prefix of the string is 0x0600 if so, it updates the receiver with the slice after the prefix marker

type String

type String string

String is here since _technically_ bencode only supports byte strings and we want to make extra sure that these are utf8 strings.

func (String) MarshalBencode

func (s String) MarshalBencode() ([]byte, error)

MarshalBencode turns the value into a receiver in a byte string with the prefix 0x0600

func (*String) UnmarshalBencode

func (s *String) UnmarshalBencode(input []byte) error

UnmarshalBencode decodes the length before the : then checks if the prefix of the string is 0x0600 if so, it updates the receiver with the slice after the prefix marker

type TanglePoint

type TanglePoint refs.TanglePoint

TanglePoint wrapps a normal tanglepoint with bencode marshaling capabilities

func (TanglePoint) MarshalBencode

func (tp TanglePoint) MarshalBencode() ([]byte, error)

MarshalBencode encodes root and previous as Null if it's not set. If they are, it turns them into tfk byte strings.

func (*TanglePoint) UnmarshalBencode

func (tp *TanglePoint) UnmarshalBencode(input []byte) error

UnmarshalBencode checks if either are Null and if not, decodes them from tfk.

type Tangles

type Tangles map[string]TanglePoint

Tangles are a named set of tanglepoints

Jump to

Keyboard shortcuts

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