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 ¶
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 ¶
MarshalBencode encodes a bool as a string with 3 characters.
func (*Bool) UnmarshalBencode ¶
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 ¶
MarshalBencode turns the value into a receiver in a byte string with the prefix 0x0603
func (*Bytes) UnmarshalBencode ¶
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 ¶
MarshalBencode turns the value into a receiver in a byte string with the prefix 0x0600
func (*String) UnmarshalBencode ¶
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.