New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/gdm85/go-rencode

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/gdm85/go-rencode

  • v0.1.8
  • Source
  • Go
  • Socket score

Version published
Created
Source

go-rencode

GoDoc

go-rencode is a Go implementation of aresch/rencode.

The rencode logic is similar to bencode. For complex, heterogeneous data structures with many small elements, r-encodings take up significantly less space than b-encodings.

Usage

Example of encoder construction and use:

	b := bytes.Buffer{}
	e := rencode.NewEncoder(&b)
	
	err := e.Encode(100, true, "hello world", rencode.NewList(42, "nesting is awesome"), 3.14, rencode.Dictionary{})

You can use either specific methods to encode one of the supported types, or the interface-generic Encode() method.

Example of decoder construction:

	e := rencode.NewDecoder(&b)

The DecodeNext() method can be used to decode the next value from the rencode stream; however this method returns an interface{} while it is usually the norm that there is an expected type instead; in such cases, it is advised to use the Scan() method instead, which accepts a pointer to any of the supported types.

Example:

	var i int
	var b bool
	var s string
	var l rencode.List
	err := e.Scan(&i, &b, &s, &l)

You can also decode a dictionary directly into a struct:

	var s struct {
		Alpha int
		Beta  string
		Gamma float64 `rencode:"rencode-exclude"`
	}
	var d Dictionary
	d.Add("alpha", int(54123))
	d.Add("beta", "test")

	err := d.ToStruct(&s, "rencode-exclude")

In this example every field/value of the dictionary must be mapped to a struct field, except those tagged as rencode-exclude. This works as well with nested dictionaries mapping to nested structs.

Supported types

Only the following types are supported:

  • rencode.List
  • rencode.Dictionary
  • big.Int (any integer with more than 63 bits of information)
  • bool
  • float32, float64
  • []byte, string (all strings are stored as byte slices anyway)
  • int8, int16, int32, int64, int
  • uint8, uint16, uint32, uint64, uint

Accessory types

The rencode.List and rencode.Dictionary implement Python-alike features and can store values and keys of the simpler types enumerated above.

TODO

  • try using reflect.Value instead of the generated code

Credits

  • This Go version: gdm85
  • Original Python version: Petru Paler, Connelly Barnes et al.
  • Cython version: Andrew Resch

License

go-rencode is licensed under GNU GPL v2, see COPYING for license information.

FAQs

Package last updated on 01 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc