This library implements Bencodex serialization format which extends Bencoding.
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) errorbencodex.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.Dictionaryfunc (d *Dictionary) Set(key any, value any)func (d *Dictionary) Get(key any) anyfunc (d *Dictionary) Delete(key any)func (d *Dictionary) Contains(key any) boolfunc (d *Dictionary) Keys() []anyfunc (d *Dictionary) Values() []anyfunc (d *Dictionary) Length() intfunc (d *Dictionary) CanConvertToMap() boolfunc (d *Dictionary) ConvertToMap() map[string]anyfunc NewDictionary() *Dictionaryfunc 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
See Examples