Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 2.18 KB

README.md

File metadata and controls

56 lines (40 loc) · 2.18 KB

Bencodex codec for Go

This library implements Bencodex serialization format which extends Bencoding.

Usage

It currently provides only the most basic encoder and decoder. See also these methods:

  • bencodex.Encode(val any) ([]byte, error)
  • bencodex.EncodeTo(w io.Writer, val any) error
  • bencodex.Decode(b []byte) (any, error)
  • bencodex.DecodeFrom(r io.Reader) (any, error)

If an integer is too large for decoding with int type, it is decoded to math/big.Int type. And math/big.Int is also available for encoding

The result of decoding the encoded dictionary is returned to the internally defined type, *bencodextype.Dictionary.

But you can use the map[string]any type for bencodex.Encode as well as the *bencodextype.Dictionary type.

  • type bencodextype.Dictionary
    • func (d *Dictionary) Set(key any, value any)
    • func (d *Dictionary) Get(key any) any
    • func (d *Dictionary) Delete(key any)
    • func (d *Dictionary) Contains(key any) bool
    • func (d *Dictionary) Keys() []any
    • func (d *Dictionary) Values() []any
    • func (d *Dictionary) Length() int
    • func (d *Dictionary) CanConvertToMap() bool
    • func (d *Dictionary) ConvertToMap() map[string]any
    • func NewDictionary() *Dictionary
    • func NewDictionaryFromMap(m map[string]any) *Dictionary

It provides fundamental marshaling to Json and Yaml data

  • func util.MarshalJsonMap(data any) ([]byte, error)
  • func util.UnmarshalJsonMap(jsonData []byte]) (any, error)
  • func util.MarshalJsonRepr(data any) ([]byte, error)
  • func util.UnmarshalJsonRepr(jsonData []byte]) (any, error)
  • func util.MarshalYaml(data any) ([]byte, error)
  • func util.UnmarshalYaml(yamlData []byte) (any, error)

Json map data format looks like this
Json repr data format looks like this

Example

See Examples