rlp.cr
a native library implementing rlp
purely for the crystal language. rlp
is ethereum's recursive length prefix used to encode arbitray data structures.
this library allows for rlp-encoding of:
- binary data (assumed encoded)
- boolean values (true, false)
- scalars (positive integers)
- string literals and characters
- arrays containing any of the the above
- nested arrays containing any of the above
installation
add the rlp
library to your shard.yml
dependencies:
rlp:
github: q9f/rlp.cr
version: "~> 0.1"
usage
# import rlp
require "rlp"
this library exposes the following modules (in logical order):
Rlp
: core library exposingencode
anddecode
logicRlp::Util
: a collection of utilities to ease the conversion between data types
this library is work in progress.
basic usage:
rlp = Rlp.encode("A cat with a short string.")
=> Bytes[154, 65, 32, 99, 97, 116, 32, 119, 105, 116, 104, 32, 97, 32, 115, 104, 111, 114, 116, 32, 115, 116, 114, 105, 110, 103, 46]
pp Rlp::Util.bin_to_hex rlp
=> "9a4120636174207769746820612073686f727420737472696e672e"
documentation
generate a local copy with:
crystal docs
testing
the library is entirely specified through tests in ./spec
; run:
crystal spec --verbose
contribute
create a pull request, and make sure tests and linter passes.
this library with built with the help of the blog post by the mana team implementing rlp
in elixir and coinmonks' annotated version of the rlp
specification. ethereum classic's rlp
article allows for some sweet test cases.
license: apache license v2.0
contributors: @q9f