From 4f1e9758d1a6e079d543ef6909e3983f5f76f587 Mon Sep 17 00:00:00 2001 From: Afr Schoe <58883403+q9f@users.noreply.github.com> Date: Wed, 29 Sep 2021 11:54:48 +0200 Subject: [PATCH] docs: regenerate crystal documentation (#15) --- docs/Rlp.html | 93 +++++++-------- docs/Rlp/RecursiveArray.html | 51 ++++---- docs/Rlp/Util.html | 97 +++++++-------- docs/css/style.css | 62 +++++++++- docs/index.html | 61 ++++++---- docs/index.json | 2 +- docs/js/doc.js | 225 +++++++++++++++++++++++------------ docs/search-index.js | 2 +- 8 files changed, 351 insertions(+), 242 deletions(-) diff --git a/docs/Rlp.html b/docs/Rlp.html index 96dd937..94be653 100644 --- a/docs/Rlp.html +++ b/docs/Rlp.html @@ -3,54 +3,65 @@
- + + + + + - - - -"0.1.2"
+ VERSION = "0.1.8"
rlp
(Bytes
): the encoded Rlp
data to decode.Rlp.decode Bytes[195, 193, 192, 192]
+Rlp.decode Bytes[195, 193, 192, 192]
# => [[[]], []]
NOTE The returned data only restores the data structure.
@@ -341,8 +344,6 @@
- [View source]
-
hex
(String
): the encoded Rlp
data to decode.Rlp.decode "c7c0c1c0c3c0c1c0"
+Rlp.decode "c7c0c1c0c3c0c1c0"
# => [[], [[]], [[], [[]]]]
NOTE The returned data only restores the data structure.
@@ -374,8 +375,6 @@
- [View source]
-
b
(Bytes
): the binary Bytes
data to encode.Rlp.encode Bytes[15, 66, 64]
+Rlp.encode Bytes[15, 66, 64]
# => Bytes[131, 15, 66, 64]
l
(Array
): the nested Array
data to encode.Rlp.encode [[""], [""]]
+Rlp.encode [[""], [""]]
# => Bytes[196, 193, 128, 193, 128]
- [View source]
-
@@ -451,15 +446,13 @@
s
(String
): the String
literal to encode.
-Rlp.encode "dog"
+Rlp.encode "dog"
# => Bytes[131, 100, 111, 103]
- [View source]
-
@@ -479,15 +472,13 @@
i
(Int
): the scalar Int
number to encode.
-Rlp.encode 1_000_000
+Rlp.encode 1_000_000
# => Bytes[131, 15, 66, 64]
- [View source]
-
@@ -507,15 +498,13 @@
c
(Char
): the Char
character to encode.
-Rlp.encode 'x'
+Rlp.encode 'x'
# => Bytes[120]
- [View source]
-
@@ -535,15 +524,13 @@
o
(Bool
): the boolean Bool
value to encode.
-Rlp.encode true
+Rlp.encode true
# => Bytes[1]
- [View source]
-
diff --git a/docs/Rlp/RecursiveArray.html b/docs/Rlp/RecursiveArray.html
index b71c731..47fb77b 100644
--- a/docs/Rlp/RecursiveArray.html
+++ b/docs/Rlp/RecursiveArray.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Rlp::RecursiveArray - github.com/q9f/rlp.cr
+
+ Rlp::RecursiveArray - rlp 0.1.7-dev
+
-
-
+
- -
+
-
Rlp
- -
+
-
RecursiveArray
- -
+
-
Util
@@ -94,10 +105,10 @@
a << [] of RecursiveArray
TODO The recursive alias might be deprecated in future,
-ref: crystal-lang/crystal#5155.
+ref: crystal-lang/crystal#5155.
it's worth considering a custom struct holding a @data
property
of type String | Bytes | Array(RecursiveArray)
and forward missing methods,
-ref: crystal-lang/crystal#8719.
+ref: crystal-lang/crystal#8719.
@@ -132,9 +143,7 @@
-
- array.cr
-
+ array.cr
diff --git a/docs/Rlp/Util.html b/docs/Rlp/Util.html
index 298ce0d..57f9b2d 100644
--- a/docs/Rlp/Util.html
+++ b/docs/Rlp/Util.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Rlp::Util - github.com/q9f/rlp.cr
+
+ Rlp::Util - rlp 0.1.7-dev
+
-
-
+
- -
+
-
Rlp
- -
+
-
RecursiveArray
- -
+
-
Util
@@ -89,7 +100,7 @@
Exposes a set of utilities to ease the handling of different data types.
It comes in handy when building protocols further decoding RLP byte-streams.
-
decoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]
+decoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]
pp decoded
# => [Bytes[42], Bytes[101, 116, 104]]
@@ -122,9 +133,7 @@
-
- util.cr
-
+ util.cr
@@ -276,15 +285,13 @@
b
(Bytes
): the binary Bytes
data to convert.
-Rlp::Util.bin_to_hex Bytes[4, 200, 29]
+Rlp::Util.bin_to_hex Bytes[4, 200, 29]
# => "04c81d"
- [View source]
-
@@ -304,15 +311,13 @@
b
(Bytes
): the binary Bytes
data to convert.
-Rlp::Util.bin_to_int Bytes[15, 66, 64]
+Rlp::Util.bin_to_int Bytes[15, 66, 64]
# => 1000000
- [View source]
-
@@ -336,8 +341,6 @@
- [View source]
-
@@ -357,15 +360,13 @@
b
(Bytes
): the binary Bytes
data to convert.
-Rlp::Util.bin_to_str Bytes[97, 98, 99]
+Rlp::Util.bin_to_str Bytes[97, 98, 99]
# => "abc"
- [View source]
-
@@ -389,8 +390,6 @@
- [View source]
-
@@ -406,7 +405,7 @@
Concatenates two Bytes
slices of UInt8
.
-a = Bytes[131]
+a = Bytes[131]
b = Bytes[97, 98, 99]
Rlp::Util.binary_add a, b
# => Bytes[131, 97, 98, 99]
@@ -415,8 +414,6 @@
- [View source]
-
@@ -436,15 +433,13 @@
h
(String
): the hex-encoded String
to convert.
-Rlp::Util.hex_to_bin "04c81d"
+Rlp::Util.hex_to_bin "04c81d"
# => Bytes[4, 200, 29]
- [View source]
-
@@ -464,15 +459,13 @@
h
(String
): the hex-encoded String
to convert.
-Rlp::Util.hex_to_int "04c81d"
+Rlp::Util.hex_to_int "04c81d"
# => 313373
- [View source]
-
@@ -492,15 +485,13 @@
h
(String
): the hex-encoded String
to convert.
-Rlp::Util.hex_to_str "646f67"
+Rlp::Util.hex_to_str "646f67"
# => "dog"
- [View source]
-
@@ -520,15 +511,13 @@
i
(Int
): the integer to convert.
-Rlp::Util.int_to_bin 1_000_000
+Rlp::Util.int_to_bin 1_000_000
# => Bytes[15, 66, 64]
- [View source]
-
@@ -548,15 +537,13 @@
i
(Int
): the integer to convert.
-Rlp::Util.int_to_hex 313_373
+Rlp::Util.int_to_hex 313_373
# => "04c81d"
- [View source]
-
@@ -576,15 +563,13 @@
s
(String
): the String
literal to convert.
-Rlp::Util.str_to_bin "abc"
+Rlp::Util.str_to_bin "abc"
# => Bytes[97, 98, 99]
- [View source]
-
@@ -604,15 +589,13 @@
s
(String
): the String
literal to convert.
-Rlp::Util.str_to_hex "dog"
+Rlp::Util.str_to_hex "dog"
# => "646f67"
- [View source]
-
diff --git a/docs/css/style.css b/docs/css/style.css
index a63baf5..20bb084 100644
--- a/docs/css/style.css
+++ b/docs/css/style.css
@@ -56,10 +56,11 @@ body {
padding: 0 0 30px;
box-shadow: inset -3px 0 4px rgba(0,0,0,.35);
line-height: 1.2;
+ z-index: 0;
}
.sidebar .search-box {
- padding: 8px 9px;
+ padding: 13px 9px;
}
.sidebar input {
@@ -106,6 +107,55 @@ body {
text-indent: 2px;
}
+.project-summary {
+ padding: 9px 15px 30px 30px;
+}
+
+.project-name {
+ font-size: 1.4rem;
+ margin: 0;
+ color: #f4f4f4;
+ font-weight: 600;
+}
+
+.project-version {
+ margin-top: 5px;
+ display: inline-block;
+ position: relative;
+}
+
+.project-version > form::after {
+ position: absolute;
+ right: 0;
+ top: 0;
+ content: "\25BC";
+ font-size: .6em;
+ line-height: 1.2rem;
+ z-index: -1;
+}
+
+.project-versions-nav {
+ cursor: pointer;
+ margin: 0;
+ padding: 0 .9em 0 0;
+ border: none;
+ -moz-appearance: none;
+ -webkit-appearance: none;
+ appearance: none;
+ background-color: transparent;
+ color: inherit;
+ font-family: inherit;
+ font-size: inherit;
+ line-height: inherit;
+}
+.project-versions-nav:focus {
+ outline: none;
+}
+
+.project-versions-nav > option {
+ color: initial;
+}
+
.sidebar ul {
margin: 0;
padding: 0;
@@ -148,10 +198,6 @@ body {
color: #866BA6;
}
-.repository-links {
- padding: 5px 15px 5px 30px;
-}
-
.types-list li ul {
overflow: hidden;
height: 0;
@@ -414,6 +460,12 @@ span.flag.purple {
border-color: #1F0B37;
}
+span.flag.lime {
+ background-color: #a3ff00;
+ color: #222222;
+ border-color: #00ff1e;
+}
+
.tooltip>span {
position: absolute;
opacity: 0;
diff --git a/docs/index.html b/docs/index.html
index 944e3a9..97095a7 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- README - github.com/q9f/rlp.cr
+
+ rlp 0.1.7-dev
+
-
-
+
- -
+
-
Rlp
- -
+
-
RecursiveArray
- -
+
-
Util
@@ -73,11 +84,11 @@
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.
@@ -143,11 +154,11 @@
documentation
-the full library documentation can be found here: q9f.github.io/rlp.cr
+the full library documentation can be found here: q9f.github.io/rlp.cr
generate a local copy with:
-
crystal docs
+crystal docs
diff --git a/docs/index.json b/docs/index.json
index 65f6f80..ea3c12d 100644
--- a/docs/index.json
+++ b/docs/index.json
@@ -1 +1 @@
-{"repository_name":"github.com/q9f/rlp.cr","body":"# rlp.cr\n\n[![Build Status](https://img.shields.io/github/workflow/status/q9f/rlp.cr/Nightly)](https://github.com/q9f/rlp.cr/actions)\n[![Documentation](https://img.shields.io/badge/docs-html-black)](https://q9f.github.io/rlp.cr/)\n[![Release](https://img.shields.io/github/v/release/q9f/rlp.cr?include_prereleases&color=black)](https://github.com/q9f/rlp.cr/releases/latest)\n[![Language](https://img.shields.io/github/languages/top/q9f/rlp.cr?color=black)](https://github.com/q9f/rlp.cr/search?l=crystal)\n[![License](https://img.shields.io/github/license/q9f/rlp.cr.svg?color=black)](LICENSE)\n\na native library implementing `rlp` purely for the crystal language. `rlp` is ethereum's recursive length prefix used to encode arbitray data structures.\n\nthis library allows for rlp-encoding of:\n* binary data (assumed encoded)\n* boolean values (true, false)\n* scalars (positive integers)\n* string literals and characters\n* arrays containing any of the above\n* nested arrays containing any of the above\n\nthis library allows for decoding of:\n* rlp-encoded data in binary format\n* rlp-encoded data in hexadecimal string format\n\nnote, that decoded data is always binary as per ethereum's design rationale:\n\n> _\"RLP does not attempt to define any specific data types such as booleans, floats, doubles or even integers; instead, it simply exists to store structure, in the form of nested arrays, and leaves it up to the protocol to determine the meaning of the arrays\"_\n\n# installation\n\nadd the `rlp` library to your `shard.yml`\n\n```yaml\ndependencies:\n rlp:\n github: q9f/rlp.cr\n version: \"~> 0.1\"\n```\n\n# usage\n\n```crystal\n# import rlp\nrequire \"rlp\"\n```\n\nthis library exposes the following modules (in logical order):\n\n* `Rlp`: core library exposing `encode` and `decode` logic\n* `Rlp::Util`: a collection of utilities to ease the conversion between data types\n* `Rlp::RecursiveArray`: is a data type alias allowing for arrays of unknown nesting depth\n\nbasic usage:\n\n```crystal\n# rlp-encode a string\nrlp = Rlp.encode \"A cat with a short string.\"\n# => 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]\n\n# (optionally) get a hex representation of the rlp-encoded data\nhex = Rlp::Util.bin_to_hex rlp\n# => \"9a4120636174207769746820612073686f727420737472696e672e\"\n\n# decode the rlp data\nbin = Rlp.decode hex\n# => Bytes[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]\n\n# we expect a string, so we can try to convert it here\nstr = Rlp::Util.bin_to_str bin\n# => \"A cat with a short string.\"\n```\n\n# documentation\n\nthe full library documentation can be found here: [q9f.github.io/rlp.cr](https://q9f.github.io/rlp.cr/)\n\ngenerate a local copy with:\n\n```\ncrystal docs\n```\n\n# testing\n\nthe library is entirely specified through tests in `./spec`; run:\n\n```bash\ncrystal spec --verbose\n```\n\n# understand\n\nrecursive length prefixes are used by the ethereum protocol to store arbitrary data structures, e.g., signed transactions, and is a fundamental serialization used by ethereum's networking protocol `devp2p` which implements `rlpx`, the _recursive length prefix transfer protocol_.\n\n`rlp` can encode any data and data structure. the resulting data is a serialized byte-stream containing prefix bytes, header data, and actual data depending on the type and size of the encoded data.\n\n```crystal\nRlp.encode [42, \"eth\"]\n# => Bytes[197, 42, 131, 101, 116, 104]\n```\n\ndeserialization of `rlp`-encoded byte-streams allows for recovering the underlying data structure. however, `rlp` is kept minimalistic in its specification and is therefore agnostic to the data types used in the structures.\n\n```crystal\nRlp.decode Bytes[197, 42, 131, 101, 116, 104]\n# => [Bytes[42], Bytes[101, 116, 104]]\n```\n\nIt's up to applications using `rlp` to further specify protocols for decoding the actual data.\n\n```crystal\ndecoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]\nprotocol = [] of String | Int32 | BigInt\nprotocol << Rlp::Util.bin_to_int decoded[0]\nprotocol << Rlp::Util.bin_to_str decoded[1]\nprotocol\n# => [42, \"eth\"]\n```\n\n# contribute\n\ncreate a pull request, and make sure tests and linter passes.\n\nthis library with built with the help of the blog post by the mana team implementing [`rlp` in elixir](https://www.badykov.com/elixir/2018/05/06/rlp/) and coinmonks' [annotated version of the `rlp` specification](https://medium.com/coinmonks/data-structure-in-ethereum-episode-1-recursive-length-prefix-rlp-encoding-decoding-d1016832f919). ethereum classic's [`rlp` article](https://ethereumclassic.org/blog/2018-03-19-rlp/) allows for some sweet test cases.\n\nlicense: apache license v2.0\n\ncontributors: [**@q9f**](https://github.com/q9f/)\n","program":{"html_id":"github.com/q9f/rlp.cr/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"github.com/q9f/rlp.cr","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/rlp.cr/Rlp","path":"Rlp.html","kind":"module","full_name":"Rlp","name":"Rlp","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"array.cr","line_number":17,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/array.cr"},{"filename":"constants.cr","line_number":17,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/constants.cr"},{"filename":"rlp.cr","line_number":23,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr"},{"filename":"version.cr","line_number":17,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/version.cr"}],"repository_name":"github.com/q9f/rlp.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"EMPTY_ARRAY","name":"EMPTY_ARRAY","value":"Bytes[OFFSET_ARRAY]","doc":"An empty array is defined as `0xC0`.","summary":"An empty array is defined as 0xC0
.
"},{"id":"EMPTY_STRING","name":"EMPTY_STRING","value":"Bytes[OFFSET_STRING]","doc":"An empty string is defined as `0x80`.","summary":"An empty string is defined as 0x80
.
"},{"id":"LIMIT_LONG","name":"LIMIT_LONG","value":"(BigInt.new(256)) ** (BigInt.new(8))","doc":"The size limit of large data objects to be encoded is `256 ** 8`.","summary":"The size limit of large data objects to be encoded is 256 ** 8
.
"},{"id":"LIMIT_SHORT","name":"LIMIT_SHORT","value":"56","doc":"The size limit of small data objects to be encoded is `56`.","summary":"The size limit of small data objects to be encoded is 56
.
"},{"id":"OFFSET_ARRAY","name":"OFFSET_ARRAY","value":"192","doc":"The offset for array list encoding is `192`.","summary":"The offset for array list encoding is 192
.
"},{"id":"OFFSET_STRING","name":"OFFSET_STRING","value":"128","doc":"The offset for string literal encoding is `128`.","summary":"The offset for string literal encoding is 128
.
"},{"id":"VERSION","name":"VERSION","value":"\"0.1.2\"","doc":"The version of the `Rlp` module shard.","summary":"The version of the Rlp
module shard.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"The `Rlp` module implementing Ethereum's Recursive Length Prefix\nfor arbitrary data encoding and decoding.","summary":"The Rlp
module implementing Ethereum's Recursive Length Prefix for arbitrary data encoding and decoding.
","class_methods":[{"id":"decode(rlp:Bytes)-class-method","html_id":"decode(rlp:Bytes)-class-method","name":"decode","doc":"Decodes arbitrary data structures from a given binary\nrecursive length prefix data stream.\n\nParameters:\n* `rlp` (`Bytes`): the encoded `Rlp` data to decode.\n\n```\nRlp.decode Bytes[195, 193, 192, 192]\n# => [[[]], []]\n```\n\nNOTE: The returned data only restores the data structure.\nIt's up to the protocol to determine the meaning of the data\nas defined in Ethereum's design rationale.","summary":"Decodes arbitrary data structures from a given binary recursive length prefix data stream.
","abstract":false,"args":[{"name":"rlp","doc":null,"default_value":"","external_name":"rlp","restriction":"Bytes"}],"args_string":"(rlp : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L233","def":{"name":"decode","args":[{"name":"rlp","doc":null,"default_value":"","external_name":"rlp","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if rlp === EMPTY_STRING\n return \"\"\nelse\n if rlp === EMPTY_ARRAY\n return [] of RecursiveArray\n end\nend\nprefix = rlp.first\nlength = rlp.bytesize\nif prefix < OFFSET_STRING && (length === 1)\n return rlp\nelse\n if prefix < (OFFSET_STRING + LIMIT_SHORT)\n offset = 1\n return rlp[offset, length - offset]\n else\n if prefix < OFFSET_ARRAY\n offset = (1 + prefix) - 183\n return rlp[offset, length - offset]\n else\n result = [] of RecursiveArray\n if prefix < (OFFSET_ARRAY + LIMIT_SHORT)\n offset = 1\n rlp = rlp[offset, length - offset]\n else\n offset = (1 + prefix) - 247\n rlp = rlp[offset, length - offset]\n end\n while rlp.bytesize > 0\n prefix = rlp.first\n length = 0\n if prefix < OFFSET_STRING\n length = 1\n else\n if prefix < (OFFSET_STRING + LIMIT_SHORT)\n length = (1 + prefix) - OFFSET_STRING\n else\n if prefix < OFFSET_ARRAY\n header_size = prefix - 183\n header = rlp[1, header_size]\n length = (1 + header_size) + (Util.bin_to_int(header))\n else\n if prefix < (OFFSET_ARRAY + LIMIT_SHORT)\n length = (1 + prefix) - OFFSET_ARRAY\n else\n header_size = prefix - 247\n header = rlp[1, header_size]\n length = (1 + header_size) + (Util.bin_to_int(header))\n end\n end\n end\n end\n result << (decode(rlp[0, length]))\n offset = length\n length = rlp.size - length\n rlp = rlp[offset, length]\n end\n return result\n end\n end\nend\n"}},{"id":"decode(hex:String)-class-method","html_id":"decode(hex:String)-class-method","name":"decode","doc":"Decodes arbitrary data structures from a given hex-encoded\nrecursive length prefix data stream.\n\nParameters:\n* `hex` (`String`): the encoded `Rlp` data to decode.\n\n```\nRlp.decode \"c7c0c1c0c3c0c1c0\"\n# => [[], [[]], [[], [[]]]]\n```\n\nNOTE: The returned data only restores the data structure.\nIt's up to the protocol to determine the meaning of the data\nas defined in Ethereum's design rationale.","summary":"Decodes arbitrary data structures from a given hex-encoded recursive length prefix data stream.
","abstract":false,"args":[{"name":"hex","doc":null,"default_value":"","external_name":"hex","restriction":"String"}],"args_string":"(hex : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L326","def":{"name":"decode","args":[{"name":"hex","doc":null,"default_value":"","external_name":"hex","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return decode(Util.hex_to_bin(hex))"}},{"id":"encode(b:Bytes)-class-method","html_id":"encode(b:Bytes)-class-method","name":"encode","doc":"RLP-encodes binary `Bytes` data.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to encode.\n\n```\nRlp.encode Bytes[15, 66, 64]\n# => Bytes[131, 15, 66, 64]\n```","summary":"RLP-encodes binary Bytes
data.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L33","def":{"name":"encode","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (b.bytesize === 1) && b.first < OFFSET_STRING\n return b\nend\nif b.bytesize < LIMIT_SHORT\n prefix = UInt8.new(b.bytesize + OFFSET_STRING)\n p = Bytes[prefix]\n return Util.binary_add(p, b)\nend\nif b.bytesize < LIMIT_LONG\n data_size = b.bytesize\n header = Util.int_to_bin(data_size)\n prefix = UInt8.new(((header.bytesize + OFFSET_STRING) + LIMIT_SHORT) - 1)\n p = Bytes[prefix]\n header = Util.binary_add(p, header)\n return Util.binary_add(header, b)\nelse\n raise(\"Invalid data provided (size out of range: #{b.bytesize})\")\nend\n"}},{"id":"encode(l:Array)-class-method","html_id":"encode(l:Array)-class-method","name":"encode","doc":"RLP-encodes nested `Array` data.\n\nParameters:\n* `l` (`Array`): the nested `Array` data to encode.\n\n```\nRlp.encode [[\"\"], [\"\"]]\n# => Bytes[196, 193, 128, 193, 128]\n```","summary":"RLP-encodes nested Array
data.
","abstract":false,"args":[{"name":"l","doc":null,"default_value":"","external_name":"l","restriction":"Array"}],"args_string":"(l : Array)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L87","def":{"name":"encode","args":[{"name":"l","doc":null,"default_value":"","external_name":"l","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if l.empty?\n return EMPTY_ARRAY\nend\nbody = Slice(UInt8).empty\nl.each do |a|\n if body.size === 0\n body = encode(a)\n else\n body = Util.binary_add(body, encode(a))\n end\nend\nif body.bytesize < LIMIT_SHORT\n prefix = UInt8.new(body.bytesize + OFFSET_ARRAY)\n p = Bytes[prefix]\n return Util.binary_add(p, body)\nend\nif body.bytesize < LIMIT_LONG\n data_size = body.bytesize\n header = Util.int_to_bin(data_size)\n prefix = UInt8.new(((header.bytesize + OFFSET_ARRAY) + LIMIT_SHORT) - 1)\n p = Bytes[prefix]\n header = Util.binary_add(p, header)\n return Util.binary_add(header, body)\nelse\n raise(\"Invalid list provided (size out of range: #{body.bytesize})\")\nend\n"}},{"id":"encode(s:String)-class-method","html_id":"encode(s:String)-class-method","name":"encode","doc":"RLP-encodes `String` literals.\n\nParameters:\n* `s` (`String`): the `String` literal to encode.\n\n```\nRlp.encode \"dog\"\n# => Bytes[131, 100, 111, 103]\n```","summary":"RLP-encodes String
literals.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L151","def":{"name":"encode","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if s.empty?\n return EMPTY_STRING\nelse\n if s.size < LIMIT_LONG\n return encode(Util.str_to_bin(s))\n else\n raise(\"Invalid string provided (size out of range: #{s.size})\")\n end\nend"}},{"id":"encode(i:Int)-class-method","html_id":"encode(i:Int)-class-method","name":"encode","doc":"RLP-encodes scalar `Int` numbers.\n\nParameters:\n* `i` (`Int`): the scalar `Int` number to encode.\n\n```\nRlp.encode 1_000_000\n# => Bytes[131, 15, 66, 64]\n```","summary":"RLP-encodes scalar Int
numbers.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L172","def":{"name":"encode","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i === 0\n return EMPTY_STRING\nelse\n if i > 0 && i < LIMIT_LONG\n return encode(Util.int_to_bin(i))\n else\n raise(\"Invalid scalar provided (out of range: #{i})\")\n end\nend"}},{"id":"encode(c:Char)-class-method","html_id":"encode(c:Char)-class-method","name":"encode","doc":"RLP-encodes `Char` characters.\n\nParameters:\n* `c` (`Char`): the `Char` character to encode.\n\n```\nRlp.encode 'x'\n# => Bytes[120]\n```","summary":"RLP-encodes Char
characters.
","abstract":false,"args":[{"name":"c","doc":null,"default_value":"","external_name":"c","restriction":"Char"}],"args_string":"(c : Char)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L195","def":{"name":"encode","args":[{"name":"c","doc":null,"default_value":"","external_name":"c","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return encode(c.to_s)"}},{"id":"encode(o:Bool)-class-method","html_id":"encode(o:Bool)-class-method","name":"encode","doc":"RLP-encodes boolean `Bool` values.\n\nParameters:\n* `o` (`Bool`): the boolean `Bool` value to encode.\n\n```\nRlp.encode true\n# => Bytes[1]\n```","summary":"RLP-encodes boolean Bool
values.
","abstract":false,"args":[{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"Bool"}],"args_string":"(o : Bool)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L209","def":{"name":"encode","args":[{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if o\n return Bytes[1]\nelse\n return EMPTY_STRING\nend"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/rlp.cr/Rlp/RecursiveArray","path":"Rlp/RecursiveArray.html","kind":"alias","full_name":"Rlp::RecursiveArray","name":"RecursiveArray","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"array.cr","line_number":32,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/array.cr"}],"repository_name":"github.com/q9f/rlp.cr","program":false,"enum":false,"alias":true,"aliased":"(Array(Rlp::RecursiveArray) | Slice(UInt8) | String)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/rlp.cr/Rlp","kind":"module","full_name":"Rlp","name":"Rlp"},"doc":"An recursive array alias for arrays of unknown nesting depth.\n\n```crystal\na = [] of RecursiveArray\na << \"\"\na << Bytes[128]\na << [] of RecursiveArray\n```\n\nTODO: The recursive alias might be deprecated in future,\nref: [crystal-lang/crystal#5155](https://github.com/crystal-lang/crystal/issues/5155).\nit's worth considering a custom struct holding a `@data` property\nof type `String | Bytes | Array(RecursiveArray)` and forward missing methods,\nref: [crystal-lang/crystal#8719](https://github.com/crystal-lang/crystal/issues/8719).","summary":"An recursive array alias for arrays of unknown nesting depth.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/q9f/rlp.cr/Rlp/Util","path":"Rlp/Util.html","kind":"module","full_name":"Rlp::Util","name":"Util","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"util.cr","line_number":29,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr"}],"repository_name":"github.com/q9f/rlp.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/rlp.cr/Rlp","kind":"module","full_name":"Rlp","name":"Rlp"},"doc":"Exposes a set of utilities to ease the handling of different data types.\nIt comes in handy when building protocols further decoding RLP byte-streams.\n\n```\ndecoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]\npp decoded\n# => [Bytes[42], Bytes[101, 116, 104]]\n\nprotocol = [] of String | Int32 | BigInt\nprotocol << Rlp::Util.bin_to_int decoded[0]\nprotocol << Rlp::Util.bin_to_str decoded[1]\npp protocol\n# => [42, \"eth\"]\n```","summary":"Exposes a set of utilities to ease the handling of different data types.
","class_methods":[{"id":"bin_to_hex(b:Bytes)-class-method","html_id":"bin_to_hex(b:Bytes)-class-method","name":"bin_to_hex","doc":"Converts binary `Bytes` to a hex-encoded `String`.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_hex Bytes[4, 200, 29]\n# => \"04c81d\"\n```","summary":"Converts binary Bytes
to a hex-encoded String
.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L61","def":{"name":"bin_to_hex","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = b.hexstring\nif h.size.odd?\n h = \"0#{h}\"\nend\nreturn h\n"}},{"id":"bin_to_int(b:Bytes)-class-method","html_id":"bin_to_int(b:Bytes)-class-method","name":"bin_to_int","doc":"Converts binary `Bytes` to a `BigInt`.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_int Bytes[15, 66, 64]\n# => 1000000\n```","summary":"Converts binary Bytes
to a BigInt
.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L39","def":{"name":"bin_to_int","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return BigInt.new(b.hexstring, 16)"}},{"id":"bin_to_int(a)-class-method","html_id":"bin_to_int(a)-class-method","name":"bin_to_int","doc":"Overloads `bin_to_int` with arbitrary data types and raises if\ninput data is not binary.\n\nNOTE: Raises in any case if `a` actually contains non-binary or nested data.\nShouldn't be used if decoded `Rlp` data could contain nested data structures.","summary":"Overloads .bin_to_int
with arbitrary data types and raises if input data is not binary.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"args_string":"(a)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L48","def":{"name":"bin_to_int","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"raise(\"Cannot convert arbitrary data to numbers, please unpack first!\")"}},{"id":"bin_to_str(b:Bytes)-class-method","html_id":"bin_to_str(b:Bytes)-class-method","name":"bin_to_str","doc":"Converts binary `Bytes` to a `String` literal.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_str Bytes[97, 98, 99]\n# => \"abc\"\n```","summary":"Converts binary Bytes
to a String
literal.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L76","def":{"name":"bin_to_str","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return String.new(b)"}},{"id":"bin_to_str(a)-class-method","html_id":"bin_to_str(a)-class-method","name":"bin_to_str","doc":"Overloads `bin_to_str` with arbitrary data types and raises if\ninput data is not binary.\n\nNOTE: Raises in any case if `a` actually contains non-binary or nested data.\nShouldn't be used if decoded `Rlp` data could contain nested data structures.","summary":"Overloads .bin_to_str
with arbitrary data types and raises if input data is not binary.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"args_string":"(a)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L85","def":{"name":"bin_to_str","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"raise(\"Cannot convert arbitrary data to strings, please unpack first!\")"}},{"id":"binary_add(a:Bytes,b:Bytes)-class-method","html_id":"binary_add(a:Bytes,b:Bytes)-class-method","name":"binary_add","doc":"Concatenates two `Bytes` slices of `UInt8`.\n\n```\na = Bytes[131]\nb = Bytes[97, 98, 99]\nRlp::Util.binary_add a, b\n# => Bytes[131, 97, 98, 99]\n```","summary":"Concatenates two Bytes
slices of UInt8
.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"Bytes"},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(a : Bytes, b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L195","def":{"name":"binary_add","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"Bytes"},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"c = IO::Memory.new(a.bytesize + b.bytesize)\na.each do |v|\n c.write_bytes(UInt8.new(v))\nend\nb.each do |v|\n c.write_bytes(UInt8.new(v))\nend\nreturn c.to_slice\n"}},{"id":"hex_to_bin(h:String)-class-method","html_id":"hex_to_bin(h:String)-class-method","name":"hex_to_bin","doc":"Converts hex-encoded `String`s to binary `Bytes` data.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_bin \"04c81d\"\n# => Bytes[4, 200, 29]\n```","summary":"Converts hex-encoded String
s to binary Bytes
data.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L128","def":{"name":"hex_to_bin","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nreturn h.hexbytes\n"}},{"id":"hex_to_int(h:String)-class-method","html_id":"hex_to_int(h:String)-class-method","name":"hex_to_int","doc":"Converts hex-encoded `String`s to `BigInt`s.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_int \"04c81d\"\n# => 313373\n```","summary":"Converts hex-encoded String
s to BigInt
s.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L142","def":{"name":"hex_to_int","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nreturn BigInt.new(h, 16)\n"}},{"id":"hex_to_str(h:String)-class-method","html_id":"hex_to_str(h:String)-class-method","name":"hex_to_str","doc":"Converts hex-encoded `String`s to `String` literals.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_str \"646f67\"\n# => \"dog\"\n```","summary":"Converts hex-encoded String
s to String
literals.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L156","def":{"name":"hex_to_str","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nreturn String.new(h.hexbytes)\n"}},{"id":"int_to_bin(i:Int)-class-method","html_id":"int_to_bin(i:Int)-class-method","name":"int_to_bin","doc":"Converts integers to binary `Bytes`.\n\nParameters:\n* `i` (`Int`): the integer to convert.\n\n```\nRlp::Util.int_to_bin 1_000_000\n# => Bytes[15, 66, 64]\n```","summary":"Converts integers to binary Bytes
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L98","def":{"name":"int_to_bin","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = i.to_s(16)\nif h.size.odd?\n h = \"0#{h}\"\nend\nreturn h.hexbytes\n"}},{"id":"int_to_hex(i:Int)-class-method","html_id":"int_to_hex(i:Int)-class-method","name":"int_to_hex","doc":"Converts integers to hex-encoded `String`s.\n\nParameters:\n* `i` (`Int`): the integer to convert.\n\n```\nRlp::Util.int_to_hex 313_373\n# => \"04c81d\"\n```","summary":"Converts integers to hex-encoded String
s.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L113","def":{"name":"int_to_hex","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = i.to_s(16)\nif h.size.odd?\n h = \"0#{h}\"\nend\nreturn h\n"}},{"id":"str_to_bin(s:String)-class-method","html_id":"str_to_bin(s:String)-class-method","name":"str_to_bin","doc":"Converts `String` literals to binary `Bytes` data.\n\nParameters:\n* `s` (`String`): the `String` literal to convert.\n\n```\nRlp::Util.str_to_bin \"abc\"\n# => Bytes[97, 98, 99]\n```","summary":"Converts String
literals to binary Bytes
data.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L170","def":{"name":"str_to_bin","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return s.to_slice"}},{"id":"str_to_hex(s:String)-class-method","html_id":"str_to_hex(s:String)-class-method","name":"str_to_hex","doc":"Converts `String` literals to hex-encoded `String`s.\n\nParameters:\n* `s` (`String`): the `String` literal to convert.\n\n```\nRlp::Util.str_to_hex \"dog\"\n# => \"646f67\"\n```","summary":"Converts String
literals to hex-encoded String
s.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L183","def":{"name":"str_to_hex","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return s.to_slice.hexstring"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}}
\ No newline at end of file
+{"repository_name":"rlp","body":"# rlp.cr\n\n[![Build Status](https://img.shields.io/github/workflow/status/q9f/rlp.cr/Nightly)](https://github.com/q9f/rlp.cr/actions)\n[![Documentation](https://img.shields.io/badge/docs-html-black)](https://q9f.github.io/rlp.cr/)\n[![Release](https://img.shields.io/github/v/release/q9f/rlp.cr?include_prereleases&color=black)](https://github.com/q9f/rlp.cr/releases/latest)\n[![Language](https://img.shields.io/github/languages/top/q9f/rlp.cr?color=black)](https://github.com/q9f/rlp.cr/search?l=crystal)\n[![License](https://img.shields.io/github/license/q9f/rlp.cr.svg?color=black)](LICENSE)\n\na native library implementing `rlp` purely for the crystal language. `rlp` is ethereum's recursive length prefix used to encode arbitray data structures.\n\nthis library allows for rlp-encoding of:\n* binary data (assumed encoded)\n* boolean values (true, false)\n* scalars (positive integers)\n* string literals and characters\n* arrays containing any of the above\n* nested arrays containing any of the above\n\nthis library allows for decoding of:\n* rlp-encoded data in binary format\n* rlp-encoded data in hexadecimal string format\n\nnote, that decoded data is always binary as per ethereum's design rationale:\n\n> _\"RLP does not attempt to define any specific data types such as booleans, floats, doubles or even integers; instead, it simply exists to store structure, in the form of nested arrays, and leaves it up to the protocol to determine the meaning of the arrays\"_\n\n# installation\n\nadd the `rlp` library to your `shard.yml`\n\n```yaml\ndependencies:\n rlp:\n github: q9f/rlp.cr\n version: \"~> 0.1\"\n```\n\n# usage\n\n```crystal\n# import rlp\nrequire \"rlp\"\n```\n\nthis library exposes the following modules (in logical order):\n\n* `Rlp`: core library exposing `encode` and `decode` logic\n* `Rlp::Util`: a collection of utilities to ease the conversion between data types\n* `Rlp::RecursiveArray`: is a data type alias allowing for arrays of unknown nesting depth\n\nbasic usage:\n\n```crystal\n# rlp-encode a string\nrlp = Rlp.encode \"A cat with a short string.\"\n# => 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]\n\n# (optionally) get a hex representation of the rlp-encoded data\nhex = Rlp::Util.bin_to_hex rlp\n# => \"9a4120636174207769746820612073686f727420737472696e672e\"\n\n# decode the rlp data\nbin = Rlp.decode hex\n# => Bytes[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]\n\n# we expect a string, so we can try to convert it here\nstr = Rlp::Util.bin_to_str bin\n# => \"A cat with a short string.\"\n```\n\n# documentation\n\nthe full library documentation can be found here: [q9f.github.io/rlp.cr](https://q9f.github.io/rlp.cr/)\n\ngenerate a local copy with:\n\n```\ncrystal docs\n```\n\n# testing\n\nthe library is entirely specified through tests in `./spec`; run:\n\n```bash\ncrystal spec --verbose\n```\n\n# understand\n\nrecursive length prefixes are used by the ethereum protocol to store arbitrary data structures, e.g., signed transactions, and is a fundamental serialization used by ethereum's networking protocol `devp2p` which implements `rlpx`, the _recursive length prefix transfer protocol_.\n\n`rlp` can encode any data and data structure. the resulting data is a serialized byte-stream containing prefix bytes, header data, and actual data depending on the type and size of the encoded data.\n\n```crystal\nRlp.encode [42, \"eth\"]\n# => Bytes[197, 42, 131, 101, 116, 104]\n```\n\ndeserialization of `rlp`-encoded byte-streams allows for recovering the underlying data structure. however, `rlp` is kept minimalistic in its specification and is therefore agnostic to the data types used in the structures.\n\n```crystal\nRlp.decode Bytes[197, 42, 131, 101, 116, 104]\n# => [Bytes[42], Bytes[101, 116, 104]]\n```\n\nIt's up to applications using `rlp` to further specify protocols for decoding the actual data.\n\n```crystal\ndecoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]\nprotocol = [] of String | Int32 | BigInt\nprotocol << Rlp::Util.bin_to_int decoded[0]\nprotocol << Rlp::Util.bin_to_str decoded[1]\nprotocol\n# => [42, \"eth\"]\n```\n\n# contribute\n\ncreate a pull request, and make sure tests and linter passes.\n\nthis library with built with the help of the blog post by the mana team implementing [`rlp` in elixir](https://www.badykov.com/elixir/2018/05/06/rlp/) and coinmonks' [annotated version of the `rlp` specification](https://medium.com/coinmonks/data-structure-in-ethereum-episode-1-recursive-length-prefix-rlp-encoding-decoding-d1016832f919). ethereum classic's [`rlp` article](https://ethereumclassic.org/blog/2018-03-19-rlp/) allows for some sweet test cases.\n\nlicense: apache license v2.0\n\ncontributors: [**@q9f**](https://github.com/q9f/), [**@cserb**](https://github.com/cserb)\n","program":{"html_id":"rlp/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"rlp","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"rlp/Rlp","path":"Rlp.html","kind":"module","full_name":"Rlp","name":"Rlp","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/array.cr","line_number":17,"url":null},{"filename":"src/constants.cr","line_number":17,"url":null},{"filename":"src/rlp.cr","line_number":23,"url":null},{"filename":"src/version.cr","line_number":17,"url":null}],"repository_name":"rlp","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"EMPTY_ARRAY","name":"EMPTY_ARRAY","value":"Bytes[OFFSET_ARRAY]","doc":"An empty array is defined as `0xC0`.","summary":"An empty array is defined as 0xC0
.
"},{"id":"EMPTY_STRING","name":"EMPTY_STRING","value":"Bytes[OFFSET_STRING]","doc":"An empty string is defined as `0x80`.","summary":"An empty string is defined as 0x80
.
"},{"id":"LIMIT_LONG","name":"LIMIT_LONG","value":"(BigInt.new(256)) ** (BigInt.new(8))","doc":"The size limit of large data objects to be encoded is `256 ** 8`.","summary":"The size limit of large data objects to be encoded is 256 ** 8
.
"},{"id":"LIMIT_SHORT","name":"LIMIT_SHORT","value":"56","doc":"The size limit of small data objects to be encoded is `56`.","summary":"The size limit of small data objects to be encoded is 56
.
"},{"id":"OFFSET_ARRAY","name":"OFFSET_ARRAY","value":"192","doc":"The offset for array list encoding is `192`.","summary":"The offset for array list encoding is 192
.
"},{"id":"OFFSET_STRING","name":"OFFSET_STRING","value":"128","doc":"The offset for string literal encoding is `128`.","summary":"The offset for string literal encoding is 128
.
"},{"id":"VERSION","name":"VERSION","value":"\"0.1.8\"","doc":"The version of the `Rlp` module shard.","summary":"The version of the Rlp
module shard.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"The `Rlp` module implementing Ethereum's Recursive Length Prefix\nfor arbitrary data encoding and decoding.","summary":"The Rlp
module implementing Ethereum's Recursive Length Prefix for arbitrary data encoding and decoding.
","class_methods":[{"html_id":"decode(rlp:Bytes)-class-method","name":"decode","doc":"Decodes arbitrary data structures from a given binary\nrecursive length prefix data stream.\n\nParameters:\n* `rlp` (`Bytes`): the encoded `Rlp` data to decode.\n\n```\nRlp.decode Bytes[195, 193, 192, 192]\n# => [[[]], []]\n```\n\nNOTE: The returned data only restores the data structure.\nIt's up to the protocol to determine the meaning of the data\nas defined in Ethereum's design rationale.","summary":"Decodes arbitrary data structures from a given binary recursive length prefix data stream.
","abstract":false,"args":[{"name":"rlp","doc":null,"default_value":"","external_name":"rlp","restriction":"Bytes"}],"args_string":"(rlp : Bytes)","args_html":"(rlp : Bytes)","location":{"filename":"src/rlp.cr","line_number":233,"url":null},"def":{"name":"decode","args":[{"name":"rlp","doc":null,"default_value":"","external_name":"rlp","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if rlp === EMPTY_STRING\n return \"\"\nelse\n if rlp === EMPTY_ARRAY\n return [] of RecursiveArray\n end\nend\nprefix = rlp.first\nlength = rlp.bytesize\nif prefix < OFFSET_STRING && (length === 1)\n rlp\nelse\n if prefix < (OFFSET_STRING + LIMIT_SHORT)\n offset = 1\n rlp[offset, length - offset]\n else\n if prefix < OFFSET_ARRAY\n offset = (1 + prefix) - 183\n rlp[offset, length - offset]\n else\n result = [] of RecursiveArray\n if prefix < (OFFSET_ARRAY + LIMIT_SHORT)\n offset = 1\n rlp = rlp[offset, length - offset]\n else\n offset = (1 + prefix) - 247\n rlp = rlp[offset, length - offset]\n end\n while rlp.bytesize > 0\n prefix = rlp.first\n length = 0\n if prefix < OFFSET_STRING\n length = 1\n else\n if prefix < (OFFSET_STRING + LIMIT_SHORT)\n length = (1 + prefix) - OFFSET_STRING\n else\n if prefix < OFFSET_ARRAY\n header_size = prefix - 183\n header = rlp[1, header_size]\n length = (1 + header_size) + (Util.bin_to_int(header))\n else\n if prefix < (OFFSET_ARRAY + LIMIT_SHORT)\n length = (1 + prefix) - OFFSET_ARRAY\n else\n header_size = prefix - 247\n header = rlp[1, header_size]\n length = (1 + header_size) + (Util.bin_to_int(header))\n end\n end\n end\n end\n result << (decode(rlp[0, length]))\n offset = length\n length = rlp.size - length\n rlp = rlp[offset, length]\n end\n result\n end\n end\nend\n"}},{"html_id":"decode(hex:String)-class-method","name":"decode","doc":"Decodes arbitrary data structures from a given hex-encoded\nrecursive length prefix data stream.\n\nParameters:\n* `hex` (`String`): the encoded `Rlp` data to decode.\n\n```\nRlp.decode \"c7c0c1c0c3c0c1c0\"\n# => [[], [[]], [[], [[]]]]\n```\n\nNOTE: The returned data only restores the data structure.\nIt's up to the protocol to determine the meaning of the data\nas defined in Ethereum's design rationale.","summary":"Decodes arbitrary data structures from a given hex-encoded recursive length prefix data stream.
","abstract":false,"args":[{"name":"hex","doc":null,"default_value":"","external_name":"hex","restriction":"String"}],"args_string":"(hex : String)","args_html":"(hex : String)","location":{"filename":"src/rlp.cr","line_number":326,"url":null},"def":{"name":"decode","args":[{"name":"hex","doc":null,"default_value":"","external_name":"hex","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"decode(Util.hex_to_bin(hex))"}},{"html_id":"encode(b:Bytes)-class-method","name":"encode","doc":"RLP-encodes binary `Bytes` data.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to encode.\n\n```\nRlp.encode Bytes[15, 66, 64]\n# => Bytes[131, 15, 66, 64]\n```","summary":"RLP-encodes binary Bytes
data.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/rlp.cr","line_number":33,"url":null},"def":{"name":"encode","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (b.bytesize === 1) && b.first < OFFSET_STRING\n return b\nend\nif b.bytesize < LIMIT_SHORT\n prefix = UInt8.new(b.bytesize + OFFSET_STRING)\n p = Bytes[prefix]\n return Util.binary_add(p, b)\nend\nif b.bytesize < LIMIT_LONG\n data_size = b.bytesize\n header = Util.int_to_bin(data_size)\n prefix = UInt8.new(((header.bytesize + OFFSET_STRING) + LIMIT_SHORT) - 1)\n p = Bytes[prefix]\n header = Util.binary_add(p, header)\n Util.binary_add(header, b)\nelse\n raise(\"Invalid data provided (size out of range: #{b.bytesize})\")\nend\n"}},{"html_id":"encode(l:Array)-class-method","name":"encode","doc":"RLP-encodes nested `Array` data.\n\nParameters:\n* `l` (`Array`): the nested `Array` data to encode.\n\n```\nRlp.encode [[\"\"], [\"\"]]\n# => Bytes[196, 193, 128, 193, 128]\n```","summary":"RLP-encodes nested Array
data.
","abstract":false,"args":[{"name":"l","doc":null,"default_value":"","external_name":"l","restriction":"Array"}],"args_string":"(l : Array)","args_html":"(l : Array)","location":{"filename":"src/rlp.cr","line_number":87,"url":null},"def":{"name":"encode","args":[{"name":"l","doc":null,"default_value":"","external_name":"l","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if l.empty?\n return EMPTY_ARRAY\nend\nbody = Slice(UInt8).empty\nl.each do |a|\n if body.size === 0\n body = encode(a)\n else\n body = Util.binary_add(body, encode(a))\n end\nend\nif body.bytesize < LIMIT_SHORT\n prefix = UInt8.new(body.bytesize + OFFSET_ARRAY)\n p = Bytes[prefix]\n return Util.binary_add(p, body)\nend\nif body.bytesize < LIMIT_LONG\n data_size = body.bytesize\n header = Util.int_to_bin(data_size)\n prefix = UInt8.new(((header.bytesize + OFFSET_ARRAY) + LIMIT_SHORT) - 1)\n p = Bytes[prefix]\n header = Util.binary_add(p, header)\n Util.binary_add(header, body)\nelse\n raise(\"Invalid list provided (size out of range: #{body.bytesize})\")\nend\n"}},{"html_id":"encode(s:String)-class-method","name":"encode","doc":"RLP-encodes `String` literals.\n\nParameters:\n* `s` (`String`): the `String` literal to encode.\n\n```\nRlp.encode \"dog\"\n# => Bytes[131, 100, 111, 103]\n```","summary":"RLP-encodes String
literals.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","args_html":"(s : String)","location":{"filename":"src/rlp.cr","line_number":151,"url":null},"def":{"name":"encode","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if s.empty?\n EMPTY_STRING\nelse\n if s.size < LIMIT_LONG\n encode(Util.str_to_bin(s))\n else\n raise(\"Invalid string provided (size out of range: #{s.size})\")\n end\nend"}},{"html_id":"encode(i:Int)-class-method","name":"encode","doc":"RLP-encodes scalar `Int` numbers.\n\nParameters:\n* `i` (`Int`): the scalar `Int` number to encode.\n\n```\nRlp.encode 1_000_000\n# => Bytes[131, 15, 66, 64]\n```","summary":"RLP-encodes scalar Int
numbers.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","args_html":"(i : Int)","location":{"filename":"src/rlp.cr","line_number":172,"url":null},"def":{"name":"encode","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i === 0\n EMPTY_STRING\nelse\n if i > 0 && i < LIMIT_LONG\n encode(Util.int_to_bin(i))\n else\n raise(\"Invalid scalar provided (out of range: #{i})\")\n end\nend"}},{"html_id":"encode(c:Char)-class-method","name":"encode","doc":"RLP-encodes `Char` characters.\n\nParameters:\n* `c` (`Char`): the `Char` character to encode.\n\n```\nRlp.encode 'x'\n# => Bytes[120]\n```","summary":"RLP-encodes Char
characters.
","abstract":false,"args":[{"name":"c","doc":null,"default_value":"","external_name":"c","restriction":"Char"}],"args_string":"(c : Char)","args_html":"(c : Char)","location":{"filename":"src/rlp.cr","line_number":195,"url":null},"def":{"name":"encode","args":[{"name":"c","doc":null,"default_value":"","external_name":"c","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"encode(c.to_s)"}},{"html_id":"encode(o:Bool)-class-method","name":"encode","doc":"RLP-encodes boolean `Bool` values.\n\nParameters:\n* `o` (`Bool`): the boolean `Bool` value to encode.\n\n```\nRlp.encode true\n# => Bytes[1]\n```","summary":"RLP-encodes boolean Bool
values.
","abstract":false,"args":[{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"Bool"}],"args_string":"(o : Bool)","args_html":"(o : Bool)","location":{"filename":"src/rlp.cr","line_number":209,"url":null},"def":{"name":"encode","args":[{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if o\n Bytes[1]\nelse\n EMPTY_STRING\nend"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"rlp/Rlp/RecursiveArray","path":"Rlp/RecursiveArray.html","kind":"alias","full_name":"Rlp::RecursiveArray","name":"RecursiveArray","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/array.cr","line_number":32,"url":null}],"repository_name":"rlp","program":false,"enum":false,"alias":true,"aliased":"(Array(Rlp::RecursiveArray) | Slice(UInt8) | String)","aliased_html":"Array(Rlp::RecursiveArray) | Slice(UInt8) | String","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"rlp/Rlp","kind":"module","full_name":"Rlp","name":"Rlp"},"doc":"An recursive array alias for arrays of unknown nesting depth.\n\n```\na = [] of RecursiveArray\na << \"\"\na << Bytes[128]\na << [] of RecursiveArray\n```\n\nTODO: The recursive alias might be deprecated in future,\nref: [crystal-lang/crystal#5155](https://github.com/crystal-lang/crystal/issues/5155).\nit's worth considering a custom struct holding a `@data` property\nof type `String | Bytes | Array(RecursiveArray)` and forward missing methods,\nref: [crystal-lang/crystal#8719](https://github.com/crystal-lang/crystal/issues/8719).","summary":"An recursive array alias for arrays of unknown nesting depth.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"rlp/Rlp/Util","path":"Rlp/Util.html","kind":"module","full_name":"Rlp::Util","name":"Util","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/util.cr","line_number":29,"url":null}],"repository_name":"rlp","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"rlp/Rlp","kind":"module","full_name":"Rlp","name":"Rlp"},"doc":"Exposes a set of utilities to ease the handling of different data types.\nIt comes in handy when building protocols further decoding RLP byte-streams.\n\n```\ndecoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]\npp decoded\n# => [Bytes[42], Bytes[101, 116, 104]]\n\nprotocol = [] of String | Int32 | BigInt\nprotocol << Rlp::Util.bin_to_int decoded[0]\nprotocol << Rlp::Util.bin_to_str decoded[1]\npp protocol\n# => [42, \"eth\"]\n```","summary":"Exposes a set of utilities to ease the handling of different data types.
","class_methods":[{"html_id":"bin_to_hex(b:Bytes)-class-method","name":"bin_to_hex","doc":"Converts binary `Bytes` to a hex-encoded `String`.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_hex Bytes[4, 200, 29]\n# => \"04c81d\"\n```","summary":"Converts binary Bytes
to a hex-encoded String
.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/util.cr","line_number":61,"url":null},"def":{"name":"bin_to_hex","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = b.hexstring\nif h.size.odd?\n return \"0#{h}\"\nend\nh\n"}},{"html_id":"bin_to_int(b:Bytes)-class-method","name":"bin_to_int","doc":"Converts binary `Bytes` to a `BigInt`.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_int Bytes[15, 66, 64]\n# => 1000000\n```","summary":"Converts binary Bytes
to a BigInt
.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/util.cr","line_number":39,"url":null},"def":{"name":"bin_to_int","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"BigInt.new(b.hexstring, 16)"}},{"html_id":"bin_to_int(a)-class-method","name":"bin_to_int","doc":"Overloads `bin_to_int` with arbitrary data types and raises if\ninput data is not binary.\n\nNOTE: Raises in any case if `a` actually contains non-binary or nested data.\nShouldn't be used if decoded `Rlp` data could contain nested data structures.","summary":"Overloads .bin_to_int
with arbitrary data types and raises if input data is not binary.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"args_string":"(a)","args_html":"(a)","location":{"filename":"src/util.cr","line_number":48,"url":null},"def":{"name":"bin_to_int","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"raise(\"Cannot convert arbitrary data to numbers, please unpack first!\")"}},{"html_id":"bin_to_str(b:Bytes)-class-method","name":"bin_to_str","doc":"Converts binary `Bytes` to a `String` literal.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_str Bytes[97, 98, 99]\n# => \"abc\"\n```","summary":"Converts binary Bytes
to a String
literal.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/util.cr","line_number":76,"url":null},"def":{"name":"bin_to_str","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"String.new(b)"}},{"html_id":"bin_to_str(a)-class-method","name":"bin_to_str","doc":"Overloads `bin_to_str` with arbitrary data types and raises if\ninput data is not binary.\n\nNOTE: Raises in any case if `a` actually contains non-binary or nested data.\nShouldn't be used if decoded `Rlp` data could contain nested data structures.","summary":"Overloads .bin_to_str
with arbitrary data types and raises if input data is not binary.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"args_string":"(a)","args_html":"(a)","location":{"filename":"src/util.cr","line_number":85,"url":null},"def":{"name":"bin_to_str","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"raise(\"Cannot convert arbitrary data to strings, please unpack first!\")"}},{"html_id":"binary_add(a:Bytes,b:Bytes)-class-method","name":"binary_add","doc":"Concatenates two `Bytes` slices of `UInt8`.\n\n```\na = Bytes[131]\nb = Bytes[97, 98, 99]\nRlp::Util.binary_add a, b\n# => Bytes[131, 97, 98, 99]\n```","summary":"Concatenates two Bytes
slices of UInt8
.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"Bytes"},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(a : Bytes, b : Bytes)","args_html":"(a : Bytes, b : Bytes)","location":{"filename":"src/util.cr","line_number":195,"url":null},"def":{"name":"binary_add","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"Bytes"},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"c = IO::Memory.new(a.bytesize + b.bytesize)\na.each do |v|\n c.write_bytes(UInt8.new(v))\nend\nb.each do |v|\n c.write_bytes(UInt8.new(v))\nend\nc.to_slice\n"}},{"html_id":"hex_to_bin(h:String)-class-method","name":"hex_to_bin","doc":"Converts hex-encoded `String`s to binary `Bytes` data.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_bin \"04c81d\"\n# => Bytes[4, 200, 29]\n```","summary":"Converts hex-encoded String
s to binary Bytes
data.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/util.cr","line_number":128,"url":null},"def":{"name":"hex_to_bin","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nh.hexbytes\n"}},{"html_id":"hex_to_int(h:String)-class-method","name":"hex_to_int","doc":"Converts hex-encoded `String`s to `BigInt`s.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_int \"04c81d\"\n# => 313373\n```","summary":"Converts hex-encoded String
s to BigInt
s.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/util.cr","line_number":142,"url":null},"def":{"name":"hex_to_int","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nBigInt.new(h, 16)\n"}},{"html_id":"hex_to_str(h:String)-class-method","name":"hex_to_str","doc":"Converts hex-encoded `String`s to `String` literals.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_str \"646f67\"\n# => \"dog\"\n```","summary":"Converts hex-encoded String
s to String
literals.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/util.cr","line_number":156,"url":null},"def":{"name":"hex_to_str","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nString.new(h.hexbytes)\n"}},{"html_id":"int_to_bin(i:Int)-class-method","name":"int_to_bin","doc":"Converts integers to binary `Bytes`.\n\nParameters:\n* `i` (`Int`): the integer to convert.\n\n```\nRlp::Util.int_to_bin 1_000_000\n# => Bytes[15, 66, 64]\n```","summary":"Converts integers to binary Bytes
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","args_html":"(i : Int)","location":{"filename":"src/util.cr","line_number":98,"url":null},"def":{"name":"int_to_bin","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = i.to_s(16)\nif h.size.odd?\n h = \"0#{h}\"\nend\nh.hexbytes\n"}},{"html_id":"int_to_hex(i:Int)-class-method","name":"int_to_hex","doc":"Converts integers to hex-encoded `String`s.\n\nParameters:\n* `i` (`Int`): the integer to convert.\n\n```\nRlp::Util.int_to_hex 313_373\n# => \"04c81d\"\n```","summary":"Converts integers to hex-encoded String
s.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","args_html":"(i : Int)","location":{"filename":"src/util.cr","line_number":113,"url":null},"def":{"name":"int_to_hex","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = i.to_s(16)\nif h.size.odd?\n return \"0#{h}\"\nend\nh\n"}},{"html_id":"str_to_bin(s:String)-class-method","name":"str_to_bin","doc":"Converts `String` literals to binary `Bytes` data.\n\nParameters:\n* `s` (`String`): the `String` literal to convert.\n\n```\nRlp::Util.str_to_bin \"abc\"\n# => Bytes[97, 98, 99]\n```","summary":"Converts String
literals to binary Bytes
data.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","args_html":"(s : String)","location":{"filename":"src/util.cr","line_number":170,"url":null},"def":{"name":"str_to_bin","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"s.to_slice"}},{"html_id":"str_to_hex(s:String)-class-method","name":"str_to_hex","doc":"Converts `String` literals to hex-encoded `String`s.\n\nParameters:\n* `s` (`String`): the `String` literal to convert.\n\n```\nRlp::Util.str_to_hex \"dog\"\n# => \"646f67\"\n```","summary":"Converts String
literals to hex-encoded String
s.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","args_html":"(s : String)","location":{"filename":"src/util.cr","line_number":183,"url":null},"def":{"name":"str_to_hex","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"s.to_slice.hexstring"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}}
\ No newline at end of file
diff --git a/docs/js/doc.js b/docs/js/doc.js
index 8796e74..c0ebb1e 100644
--- a/docs/js/doc.js
+++ b/docs/js/doc.js
@@ -1,11 +1,11 @@
-window.CrystalDoc = (window.CrystalDoc || {});
+window.CrystalDocs = (window.CrystalDocs || {});
-CrystalDoc.base_path = (CrystalDoc.base_path || "");
+CrystalDocs.base_path = (CrystalDocs.base_path || "");
-CrystalDoc.searchIndex = (CrystalDoc.searchIndex || false);
-CrystalDoc.MAX_RESULTS_DISPLAY = 140;
+CrystalDocs.searchIndex = (CrystalDocs.searchIndex || false);
+CrystalDocs.MAX_RESULTS_DISPLAY = 140;
-CrystalDoc.runQuery = function(query) {
+CrystalDocs.runQuery = function(query) {
function searchType(type, query, results) {
var matches = [];
var matchedFields = [];
@@ -33,7 +33,7 @@ CrystalDoc.runQuery = function(query) {
}
if (matches.length > 0) {
results.push({
- id: type.id,
+ id: type.html_id,
result_type: "type",
kind: type.kind,
name: name,
@@ -96,14 +96,14 @@ CrystalDoc.runQuery = function(query) {
matches = matches.concat(typeMatches);
}
results.push({
- id: method.id,
+ id: method.html_id,
type: type.full_name,
result_type: kind,
name: method.name,
full_name: type.full_name + "#" + method.name,
args_string: method.args_string,
summary: method.summary,
- href: type.path + "#" + method.id,
+ href: type.path + "#" + method.html_id,
matched_fields: matchedFields,
matched_terms: matches
});
@@ -130,14 +130,14 @@ CrystalDoc.runQuery = function(query) {
matches = matches.concat(typeMatches);
}
results.push({
- id: constant.id,
+ id: constant.html_id,
type: type.full_name,
result_type: "constant",
name: constant.name,
full_name: type.full_name + "#" + constant.name,
value: constant.value,
summary: constant.summary,
- href: type.path + "#" + constant.id,
+ href: type.path + "#" + constant.html_id,
matched_fields: matchedFields,
matched_terms: matches
});
@@ -145,11 +145,11 @@ CrystalDoc.runQuery = function(query) {
}
var results = [];
- searchType(CrystalDoc.searchIndex.program, query, results);
+ searchType(CrystalDocs.searchIndex.program, query, results);
return results;
};
-CrystalDoc.rankResults = function(results, query) {
+CrystalDocs.rankResults = function(results, query) {
function uniqueArray(ar) {
var j = {};
@@ -171,42 +171,42 @@ CrystalDoc.rankResults = function(results, query) {
var bOnlyDocs = bHasDocs && b.matched_fields.length == 1;
if (a.result_type == "type" && b.result_type != "type" && !aOnlyDocs) {
- if(CrystalDoc.DEBUG) { console.log("a is type b not"); }
+ if(CrystalDocs.DEBUG) { console.log("a is type b not"); }
return -1;
} else if (b.result_type == "type" && a.result_type != "type" && !bOnlyDocs) {
- if(CrystalDoc.DEBUG) { console.log("b is type, a not"); }
+ if(CrystalDocs.DEBUG) { console.log("b is type, a not"); }
return 1;
}
if (a.matched_fields.includes("name")) {
if (b.matched_fields.includes("name")) {
- var a_name = (CrystalDoc.prefixForType(a.result_type) || "") + ((a.result_type == "type") ? a.full_name : a.name);
- var b_name = (CrystalDoc.prefixForType(b.result_type) || "") + ((b.result_type == "type") ? b.full_name : b.name);
+ var a_name = (CrystalDocs.prefixForType(a.result_type) || "") + ((a.result_type == "type") ? a.full_name : a.name);
+ var b_name = (CrystalDocs.prefixForType(b.result_type) || "") + ((b.result_type == "type") ? b.full_name : b.name);
a_name = a_name.toLowerCase();
b_name = b_name.toLowerCase();
for(var i = 0; i < query.normalizedTerms.length; i++) {
var term = query.terms[i].replace(/^::?|::?$/, "");
var a_orig_index = a_name.indexOf(term);
var b_orig_index = b_name.indexOf(term);
- if(CrystalDoc.DEBUG) { console.log("term: " + term + " a: " + a_name + " b: " + b_name); }
- if(CrystalDoc.DEBUG) { console.log(a_orig_index, b_orig_index, a_orig_index - b_orig_index); }
+ if(CrystalDocs.DEBUG) { console.log("term: " + term + " a: " + a_name + " b: " + b_name); }
+ if(CrystalDocs.DEBUG) { console.log(a_orig_index, b_orig_index, a_orig_index - b_orig_index); }
if (a_orig_index >= 0) {
if (b_orig_index >= 0) {
- if(CrystalDoc.DEBUG) { console.log("both have exact match", a_orig_index > b_orig_index ? -1 : 1); }
+ if(CrystalDocs.DEBUG) { console.log("both have exact match", a_orig_index > b_orig_index ? -1 : 1); }
if(a_orig_index != b_orig_index) {
- if(CrystalDoc.DEBUG) { console.log("both have exact match at different positions", a_orig_index > b_orig_index ? 1 : -1); }
+ if(CrystalDocs.DEBUG) { console.log("both have exact match at different positions", a_orig_index > b_orig_index ? 1 : -1); }
return a_orig_index > b_orig_index ? 1 : -1;
}
} else {
- if(CrystalDoc.DEBUG) { console.log("a has exact match, b not"); }
+ if(CrystalDocs.DEBUG) { console.log("a has exact match, b not"); }
return -1;
}
} else if (b_orig_index >= 0) {
- if(CrystalDoc.DEBUG) { console.log("b has exact match, a not"); }
+ if(CrystalDocs.DEBUG) { console.log("b has exact match, a not"); }
return 1;
}
}
} else {
- if(CrystalDoc.DEBUG) { console.log("a has match in name, b not"); }
+ if(CrystalDocs.DEBUG) { console.log("a has match in name, b not"); }
return -1;
}
} else if (
@@ -217,19 +217,19 @@ CrystalDoc.rankResults = function(results, query) {
}
if (matchedTermsDiff != 0 || (aHasDocs != bHasDocs)) {
- if(CrystalDoc.DEBUG) { console.log("matchedTermsDiff: " + matchedTermsDiff, aHasDocs, bHasDocs); }
+ if(CrystalDocs.DEBUG) { console.log("matchedTermsDiff: " + matchedTermsDiff, aHasDocs, bHasDocs); }
return matchedTermsDiff;
}
var matchedFieldsDiff = b.matched_fields.length - a.matched_fields.length;
if (matchedFieldsDiff != 0) {
- if(CrystalDoc.DEBUG) { console.log("matched to different number of fields: " + matchedFieldsDiff); }
+ if(CrystalDocs.DEBUG) { console.log("matched to different number of fields: " + matchedFieldsDiff); }
return matchedFieldsDiff > 0 ? 1 : -1;
}
var nameCompare = a.name.localeCompare(b.name);
if(nameCompare != 0){
- if(CrystalDoc.DEBUG) { console.log("nameCompare resulted in: " + a.name + "<=>" + b.name + ": " + nameCompare); }
+ if(CrystalDocs.DEBUG) { console.log("nameCompare resulted in: " + a.name + "<=>" + b.name + ": " + nameCompare); }
return nameCompare > 0 ? 1 : -1;
}
@@ -238,7 +238,7 @@ CrystalDoc.rankResults = function(results, query) {
var term = query.terms[i];
var aIndex = a.args_string.indexOf(term);
var bIndex = b.args_string.indexOf(term);
- if(CrystalDoc.DEBUG) { console.log("index of " + term + " in args_string: " + aIndex + " - " + bIndex); }
+ if(CrystalDocs.DEBUG) { console.log("index of " + term + " in args_string: " + aIndex + " - " + bIndex); }
if(aIndex >= 0){
if(bIndex >= 0){
if(aIndex != bIndex){
@@ -267,7 +267,7 @@ CrystalDoc.rankResults = function(results, query) {
return results;
};
-CrystalDoc.prefixForType = function(type) {
+CrystalDocs.prefixForType = function(type) {
switch (type) {
case "instance_method":
return "#";
@@ -282,14 +282,14 @@ CrystalDoc.prefixForType = function(type) {
}
};
-CrystalDoc.displaySearchResults = function(results, query) {
+CrystalDocs.displaySearchResults = function(results, query) {
function sanitize(html){
return html.replace(/<(?!\/?code)[^>]+>/g, "");
}
// limit results
- if (results.length > CrystalDoc.MAX_RESULTS_DISPLAY) {
- results = results.slice(0, CrystalDoc.MAX_RESULTS_DISPLAY);
+ if (results.length > CrystalDocs.MAX_RESULTS_DISPLAY) {
+ results = results.slice(0, CrystalDocs.MAX_RESULTS_DISPLAY);
}
var $frag = document.createDocumentFragment();
@@ -297,12 +297,12 @@ CrystalDoc.displaySearchResults = function(results, query) {
$resultsElem.innerHTML = "";
results.forEach(function(result, i) {
- var url = CrystalDoc.base_path + result.href;
+ var url = CrystalDocs.base_path + result.href;
var type = false;
var title = query.highlight(result.result_type == "type" ? result.full_name : result.name);
- var prefix = CrystalDoc.prefixForType(result.result_type);
+ var prefix = CrystalDocs.prefixForType(result.result_type);
if (prefix) {
title = "" + prefix + "" + title;
}
@@ -351,10 +351,10 @@ CrystalDoc.displaySearchResults = function(results, query) {
$resultsElem.appendChild($frag);
- CrystalDoc.toggleResultsList(true);
+ CrystalDocs.toggleResultsList(true);
};
-CrystalDoc.toggleResultsList = function(visible) {
+CrystalDocs.toggleResultsList = function(visible) {
if (visible) {
document.querySelector(".types-list").classList.add("hidden");
document.querySelector(".search-results").classList.remove("hidden");
@@ -364,20 +364,20 @@ CrystalDoc.toggleResultsList = function(visible) {
}
};
-CrystalDoc.Query = function(string) {
+CrystalDocs.Query = function(string) {
this.original = string;
this.terms = string.split(/\s+/).filter(function(word) {
- return CrystalDoc.Query.stripModifiers(word).length > 0;
+ return CrystalDocs.Query.stripModifiers(word).length > 0;
});
- var normalized = this.terms.map(CrystalDoc.Query.normalizeTerm);
+ var normalized = this.terms.map(CrystalDocs.Query.normalizeTerm);
this.normalizedTerms = normalized;
function runMatcher(field, matcher) {
if (!field) {
return false;
}
- var normalizedValue = CrystalDoc.Query.normalizeTerm(field);
+ var normalizedValue = CrystalDocs.Query.normalizeTerm(field);
var matches = [];
normalized.forEach(function(term) {
@@ -435,7 +435,7 @@ CrystalDoc.Query = function(string) {
methodName = term.substring(i+1);
if(termType != "") {
- if(CrystalDoc.Query.normalizeTerm(type.full_name).indexOf(termType) < 0){
+ if(CrystalDocs.Query.normalizeTerm(type.full_name).indexOf(termType) < 0){
return false;
}
}
@@ -461,10 +461,10 @@ CrystalDoc.Query = function(string) {
);
};
};
-CrystalDoc.Query.normalizeTerm = function(term) {
+CrystalDocs.Query.normalizeTerm = function(term) {
return term.toLowerCase();
};
-CrystalDoc.Query.stripModifiers = function(term) {
+CrystalDocs.Query.stripModifiers = function(term) {
switch (term[0]) {
case "#":
case ".":
@@ -476,34 +476,34 @@ CrystalDoc.Query.stripModifiers = function(term) {
}
}
-CrystalDoc.search = function(string) {
- if(!CrystalDoc.searchIndex) {
- console.log("CrystalDoc search index not initialized, delaying search");
+CrystalDocs.search = function(string) {
+ if(!CrystalDocs.searchIndex) {
+ console.log("CrystalDocs search index not initialized, delaying search");
- document.addEventListener("CrystalDoc:loaded", function listener(){
- document.removeEventListener("CrystalDoc:loaded", listener);
- CrystalDoc.search(string);
+ document.addEventListener("CrystalDocs:loaded", function listener(){
+ document.removeEventListener("CrystalDocs:loaded", listener);
+ CrystalDocs.search(string);
});
return;
}
- document.dispatchEvent(new Event("CrystalDoc:searchStarted"));
+ document.dispatchEvent(new Event("CrystalDocs:searchStarted"));
- var query = new CrystalDoc.Query(string);
- var results = CrystalDoc.runQuery(query);
- results = CrystalDoc.rankResults(results, query);
- CrystalDoc.displaySearchResults(results, query);
+ var query = new CrystalDocs.Query(string);
+ var results = CrystalDocs.runQuery(query);
+ results = CrystalDocs.rankResults(results, query);
+ CrystalDocs.displaySearchResults(results, query);
- document.dispatchEvent(new Event("CrystalDoc:searchPerformed"));
+ document.dispatchEvent(new Event("CrystalDocs:searchPerformed"));
};
-CrystalDoc.initializeIndex = function(data) {
- CrystalDoc.searchIndex = data;
+CrystalDocs.initializeIndex = function(data) {
+ CrystalDocs.searchIndex = data;
- document.dispatchEvent(new Event("CrystalDoc:loaded"));
+ document.dispatchEvent(new Event("CrystalDocs:loaded"));
};
-CrystalDoc.loadIndex = function() {
+CrystalDocs.loadIndex = function() {
function loadJSON(file, callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
@@ -523,7 +523,7 @@ CrystalDoc.loadIndex = function() {
}
function parseJSON(json) {
- CrystalDoc.initializeIndex(JSON.parse(json));
+ CrystalDocs.initializeIndex(JSON.parse(json));
}
for(var i = 0; i < document.scripts.length; i++){
@@ -546,7 +546,7 @@ CrystalDoc.loadIndex = function() {
// Callback for jsonp
function crystal_doc_search_index_callback(data) {
- CrystalDoc.initializeIndex(data);
+ CrystalDocs.initializeIndex(data);
}
Navigator = function(sidebar, searchInput, list, leaveSearchScope){
@@ -555,23 +555,23 @@ Navigator = function(sidebar, searchInput, list, leaveSearchScope){
var performingSearch = false;
- document.addEventListener('CrystalDoc:searchStarted', function(){
+ document.addEventListener('CrystalDocs:searchStarted', function(){
performingSearch = true;
});
- document.addEventListener('CrystalDoc:searchDebounceStarted', function(){
+ document.addEventListener('CrystalDocs:searchDebounceStarted', function(){
performingSearch = true;
});
- document.addEventListener('CrystalDoc:searchPerformed', function(){
+ document.addEventListener('CrystalDocs:searchPerformed', function(){
performingSearch = false;
});
- document.addEventListener('CrystalDoc:searchDebounceStopped', function(event){
+ document.addEventListener('CrystalDocs:searchDebounceStopped', function(event){
performingSearch = false;
});
function delayWhileSearching(callback) {
if(performingSearch){
- document.addEventListener('CrystalDoc:searchPerformed', function listener(){
- document.removeEventListener('CrystalDoc:searchPerformed', listener);
+ document.addEventListener('CrystalDocs:searchPerformed', function listener(){
+ document.removeEventListener('CrystalDocs:searchPerformed', listener);
// add some delay to let search results display kick in
setTimeout(callback, 100);
@@ -783,6 +783,74 @@ Navigator = function(sidebar, searchInput, list, leaveSearchScope){
this.move();
};
+CrystalDocs.initializeVersions = function () {
+ function loadJSON(file, callback) {
+ var xobj = new XMLHttpRequest();
+ xobj.overrideMimeType("application/json");
+ xobj.open("GET", file, true);
+ xobj.onreadystatechange = function() {
+ if (xobj.readyState == 4 && xobj.status == "200") {
+ callback(xobj.responseText);
+ }
+ };
+ xobj.send(null);
+ }
+
+ function parseJSON(json) {
+ CrystalDocs.loadConfig(JSON.parse(json));
+ }
+
+ $elem = document.querySelector("html > head > meta[name=\"crystal_docs.json_config_url\"]")
+ if ($elem == undefined) {
+ return
+ }
+ jsonURL = $elem.getAttribute("content")
+ if (jsonURL && jsonURL != "") {
+ loadJSON(jsonURL, parseJSON);
+ }
+}
+
+CrystalDocs.loadConfig = function (config) {
+ var projectVersions = config["versions"]
+ var currentVersion = document.querySelector("html > head > meta[name=\"crystal_docs.project_version\"]").getAttribute("content")
+
+ var currentVersionInList = projectVersions.find(function (element) {
+ return element.name == currentVersion
+ })
+
+ if (!currentVersionInList) {
+ projectVersions.unshift({ name: currentVersion, url: '#' })
+ }
+
+ $version = document.querySelector(".project-summary > .project-version")
+ $version.innerHTML = ""
+
+ $select = document.createElement("select")
+ $select.classList.add("project-versions-nav")
+ $select.addEventListener("change", function () {
+ window.location.href = this.value
+ })
+ projectVersions.forEach(function (version) {
+ $item = document.createElement("option")
+ $item.setAttribute("value", version.url)
+ $item.append(document.createTextNode(version.name))
+
+ if (version.name == currentVersion) {
+ $item.setAttribute("selected", true)
+ $item.setAttribute("disabled", true)
+ }
+ $select.append($item)
+ });
+ $form = document.createElement("form")
+ $form.setAttribute("autocomplete", "off")
+ $form.append($select)
+ $version.append($form)
+}
+
+document.addEventListener("DOMContentLoaded", function () {
+ CrystalDocs.initializeVersions()
+})
+
var UsageModal = function(title, content) {
var $body = document.body;
var self = this;
@@ -840,7 +908,7 @@ document.addEventListener('DOMContentLoaded', function() {
};
}
- var repositoryName = document.querySelector('#repository-name').getAttribute('content');
+ var repositoryName = document.querySelector('[name=repository-name]').getAttribute('content');
var typesList = document.querySelector('.types-list');
var searchInput = document.querySelector('.search-input');
var parents = document.querySelectorAll('.types-list li.parent');
@@ -883,28 +951,28 @@ document.addEventListener('DOMContentLoaded', function() {
}
var leaveSearchScope = function(){
- CrystalDoc.toggleResultsList(false);
+ CrystalDocs.toggleResultsList(false);
window.focus();
}
var navigator = new Navigator(document.querySelector('.types-list'), searchInput, document.querySelector(".search-results"), leaveSearchScope);
- CrystalDoc.loadIndex();
+ CrystalDocs.loadIndex();
var searchTimeout;
var lastSearchText = false;
var performSearch = function() {
- document.dispatchEvent(new Event("CrystalDoc:searchDebounceStarted"));
+ document.dispatchEvent(new Event("CrystalDocs:searchDebounceStarted"));
clearTimeout(searchTimeout);
searchTimeout = setTimeout(function() {
var text = searchInput.value;
if(text == "") {
- CrystalDoc.toggleResultsList(false);
+ CrystalDocs.toggleResultsList(false);
}else if(text == lastSearchText){
- document.dispatchEvent(new Event("CrystalDoc:searchDebounceStopped"));
+ document.dispatchEvent(new Event("CrystalDocs:searchDebounceStopped"));
}else{
- CrystalDoc.search(text);
+ CrystalDocs.search(text);
navigator.highlightFirst();
searchInput.focus();
}
@@ -920,7 +988,7 @@ document.addEventListener('DOMContentLoaded', function() {
var searchQuery = location.hash.substring(3);
history.pushState({searchQuery: searchQuery}, "Search for " + searchQuery, location.href.replace(/#q=.*/, ""));
searchInput.value = searchQuery;
- document.addEventListener('CrystalDoc:loaded', performSearch);
+ document.addEventListener('CrystalDocs:loaded', performSearch);
}
if (searchInput.value.length == 0) {
@@ -1006,11 +1074,10 @@ document.addEventListener('DOMContentLoaded', function() {
var scrollToEntryFromLocationHash = function() {
var hash = window.location.hash;
if (hash) {
- var targetAnchor = unescape(hash.substr(1));
- var targetEl = document.querySelectorAll('.entry-detail[id="' + targetAnchor + '"]');
-
- if (targetEl && targetEl.length > 0) {
- targetEl[0].offsetParent.scrollTop = targetEl[0].offsetTop;
+ var targetAnchor = decodeURI(hash.substr(1));
+ var targetEl = document.getElementById(targetAnchor)
+ if (targetEl) {
+ targetEl.offsetParent.scrollTop = targetEl.offsetTop;
}
}
};
diff --git a/docs/search-index.js b/docs/search-index.js
index 3741f74..10cb784 100644
--- a/docs/search-index.js
+++ b/docs/search-index.js
@@ -1 +1 @@
-crystal_doc_search_index_callback({"repository_name":"github.com/q9f/rlp.cr","body":"# rlp.cr\n\n[![Build Status](https://img.shields.io/github/workflow/status/q9f/rlp.cr/Nightly)](https://github.com/q9f/rlp.cr/actions)\n[![Documentation](https://img.shields.io/badge/docs-html-black)](https://q9f.github.io/rlp.cr/)\n[![Release](https://img.shields.io/github/v/release/q9f/rlp.cr?include_prereleases&color=black)](https://github.com/q9f/rlp.cr/releases/latest)\n[![Language](https://img.shields.io/github/languages/top/q9f/rlp.cr?color=black)](https://github.com/q9f/rlp.cr/search?l=crystal)\n[![License](https://img.shields.io/github/license/q9f/rlp.cr.svg?color=black)](LICENSE)\n\na native library implementing `rlp` purely for the crystal language. `rlp` is ethereum's recursive length prefix used to encode arbitray data structures.\n\nthis library allows for rlp-encoding of:\n* binary data (assumed encoded)\n* boolean values (true, false)\n* scalars (positive integers)\n* string literals and characters\n* arrays containing any of the above\n* nested arrays containing any of the above\n\nthis library allows for decoding of:\n* rlp-encoded data in binary format\n* rlp-encoded data in hexadecimal string format\n\nnote, that decoded data is always binary as per ethereum's design rationale:\n\n> _\"RLP does not attempt to define any specific data types such as booleans, floats, doubles or even integers; instead, it simply exists to store structure, in the form of nested arrays, and leaves it up to the protocol to determine the meaning of the arrays\"_\n\n# installation\n\nadd the `rlp` library to your `shard.yml`\n\n```yaml\ndependencies:\n rlp:\n github: q9f/rlp.cr\n version: \"~> 0.1\"\n```\n\n# usage\n\n```crystal\n# import rlp\nrequire \"rlp\"\n```\n\nthis library exposes the following modules (in logical order):\n\n* `Rlp`: core library exposing `encode` and `decode` logic\n* `Rlp::Util`: a collection of utilities to ease the conversion between data types\n* `Rlp::RecursiveArray`: is a data type alias allowing for arrays of unknown nesting depth\n\nbasic usage:\n\n```crystal\n# rlp-encode a string\nrlp = Rlp.encode \"A cat with a short string.\"\n# => 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]\n\n# (optionally) get a hex representation of the rlp-encoded data\nhex = Rlp::Util.bin_to_hex rlp\n# => \"9a4120636174207769746820612073686f727420737472696e672e\"\n\n# decode the rlp data\nbin = Rlp.decode hex\n# => Bytes[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]\n\n# we expect a string, so we can try to convert it here\nstr = Rlp::Util.bin_to_str bin\n# => \"A cat with a short string.\"\n```\n\n# documentation\n\nthe full library documentation can be found here: [q9f.github.io/rlp.cr](https://q9f.github.io/rlp.cr/)\n\ngenerate a local copy with:\n\n```\ncrystal docs\n```\n\n# testing\n\nthe library is entirely specified through tests in `./spec`; run:\n\n```bash\ncrystal spec --verbose\n```\n\n# understand\n\nrecursive length prefixes are used by the ethereum protocol to store arbitrary data structures, e.g., signed transactions, and is a fundamental serialization used by ethereum's networking protocol `devp2p` which implements `rlpx`, the _recursive length prefix transfer protocol_.\n\n`rlp` can encode any data and data structure. the resulting data is a serialized byte-stream containing prefix bytes, header data, and actual data depending on the type and size of the encoded data.\n\n```crystal\nRlp.encode [42, \"eth\"]\n# => Bytes[197, 42, 131, 101, 116, 104]\n```\n\ndeserialization of `rlp`-encoded byte-streams allows for recovering the underlying data structure. however, `rlp` is kept minimalistic in its specification and is therefore agnostic to the data types used in the structures.\n\n```crystal\nRlp.decode Bytes[197, 42, 131, 101, 116, 104]\n# => [Bytes[42], Bytes[101, 116, 104]]\n```\n\nIt's up to applications using `rlp` to further specify protocols for decoding the actual data.\n\n```crystal\ndecoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]\nprotocol = [] of String | Int32 | BigInt\nprotocol << Rlp::Util.bin_to_int decoded[0]\nprotocol << Rlp::Util.bin_to_str decoded[1]\nprotocol\n# => [42, \"eth\"]\n```\n\n# contribute\n\ncreate a pull request, and make sure tests and linter passes.\n\nthis library with built with the help of the blog post by the mana team implementing [`rlp` in elixir](https://www.badykov.com/elixir/2018/05/06/rlp/) and coinmonks' [annotated version of the `rlp` specification](https://medium.com/coinmonks/data-structure-in-ethereum-episode-1-recursive-length-prefix-rlp-encoding-decoding-d1016832f919). ethereum classic's [`rlp` article](https://ethereumclassic.org/blog/2018-03-19-rlp/) allows for some sweet test cases.\n\nlicense: apache license v2.0\n\ncontributors: [**@q9f**](https://github.com/q9f/)\n","program":{"html_id":"github.com/q9f/rlp.cr/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"github.com/q9f/rlp.cr","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/rlp.cr/Rlp","path":"Rlp.html","kind":"module","full_name":"Rlp","name":"Rlp","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"array.cr","line_number":17,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/array.cr"},{"filename":"constants.cr","line_number":17,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/constants.cr"},{"filename":"rlp.cr","line_number":23,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr"},{"filename":"version.cr","line_number":17,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/version.cr"}],"repository_name":"github.com/q9f/rlp.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"EMPTY_ARRAY","name":"EMPTY_ARRAY","value":"Bytes[OFFSET_ARRAY]","doc":"An empty array is defined as `0xC0`.","summary":"An empty array is defined as 0xC0
.
"},{"id":"EMPTY_STRING","name":"EMPTY_STRING","value":"Bytes[OFFSET_STRING]","doc":"An empty string is defined as `0x80`.","summary":"An empty string is defined as 0x80
.
"},{"id":"LIMIT_LONG","name":"LIMIT_LONG","value":"(BigInt.new(256)) ** (BigInt.new(8))","doc":"The size limit of large data objects to be encoded is `256 ** 8`.","summary":"The size limit of large data objects to be encoded is 256 ** 8
.
"},{"id":"LIMIT_SHORT","name":"LIMIT_SHORT","value":"56","doc":"The size limit of small data objects to be encoded is `56`.","summary":"The size limit of small data objects to be encoded is 56
.
"},{"id":"OFFSET_ARRAY","name":"OFFSET_ARRAY","value":"192","doc":"The offset for array list encoding is `192`.","summary":"The offset for array list encoding is 192
.
"},{"id":"OFFSET_STRING","name":"OFFSET_STRING","value":"128","doc":"The offset for string literal encoding is `128`.","summary":"The offset for string literal encoding is 128
.
"},{"id":"VERSION","name":"VERSION","value":"\"0.1.2\"","doc":"The version of the `Rlp` module shard.","summary":"The version of the Rlp
module shard.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"The `Rlp` module implementing Ethereum's Recursive Length Prefix\nfor arbitrary data encoding and decoding.","summary":"The Rlp
module implementing Ethereum's Recursive Length Prefix for arbitrary data encoding and decoding.
","class_methods":[{"id":"decode(rlp:Bytes)-class-method","html_id":"decode(rlp:Bytes)-class-method","name":"decode","doc":"Decodes arbitrary data structures from a given binary\nrecursive length prefix data stream.\n\nParameters:\n* `rlp` (`Bytes`): the encoded `Rlp` data to decode.\n\n```\nRlp.decode Bytes[195, 193, 192, 192]\n# => [[[]], []]\n```\n\nNOTE: The returned data only restores the data structure.\nIt's up to the protocol to determine the meaning of the data\nas defined in Ethereum's design rationale.","summary":"Decodes arbitrary data structures from a given binary recursive length prefix data stream.
","abstract":false,"args":[{"name":"rlp","doc":null,"default_value":"","external_name":"rlp","restriction":"Bytes"}],"args_string":"(rlp : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L233","def":{"name":"decode","args":[{"name":"rlp","doc":null,"default_value":"","external_name":"rlp","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if rlp === EMPTY_STRING\n return \"\"\nelse\n if rlp === EMPTY_ARRAY\n return [] of RecursiveArray\n end\nend\nprefix = rlp.first\nlength = rlp.bytesize\nif prefix < OFFSET_STRING && (length === 1)\n return rlp\nelse\n if prefix < (OFFSET_STRING + LIMIT_SHORT)\n offset = 1\n return rlp[offset, length - offset]\n else\n if prefix < OFFSET_ARRAY\n offset = (1 + prefix) - 183\n return rlp[offset, length - offset]\n else\n result = [] of RecursiveArray\n if prefix < (OFFSET_ARRAY + LIMIT_SHORT)\n offset = 1\n rlp = rlp[offset, length - offset]\n else\n offset = (1 + prefix) - 247\n rlp = rlp[offset, length - offset]\n end\n while rlp.bytesize > 0\n prefix = rlp.first\n length = 0\n if prefix < OFFSET_STRING\n length = 1\n else\n if prefix < (OFFSET_STRING + LIMIT_SHORT)\n length = (1 + prefix) - OFFSET_STRING\n else\n if prefix < OFFSET_ARRAY\n header_size = prefix - 183\n header = rlp[1, header_size]\n length = (1 + header_size) + (Util.bin_to_int(header))\n else\n if prefix < (OFFSET_ARRAY + LIMIT_SHORT)\n length = (1 + prefix) - OFFSET_ARRAY\n else\n header_size = prefix - 247\n header = rlp[1, header_size]\n length = (1 + header_size) + (Util.bin_to_int(header))\n end\n end\n end\n end\n result << (decode(rlp[0, length]))\n offset = length\n length = rlp.size - length\n rlp = rlp[offset, length]\n end\n return result\n end\n end\nend\n"}},{"id":"decode(hex:String)-class-method","html_id":"decode(hex:String)-class-method","name":"decode","doc":"Decodes arbitrary data structures from a given hex-encoded\nrecursive length prefix data stream.\n\nParameters:\n* `hex` (`String`): the encoded `Rlp` data to decode.\n\n```\nRlp.decode \"c7c0c1c0c3c0c1c0\"\n# => [[], [[]], [[], [[]]]]\n```\n\nNOTE: The returned data only restores the data structure.\nIt's up to the protocol to determine the meaning of the data\nas defined in Ethereum's design rationale.","summary":"Decodes arbitrary data structures from a given hex-encoded recursive length prefix data stream.
","abstract":false,"args":[{"name":"hex","doc":null,"default_value":"","external_name":"hex","restriction":"String"}],"args_string":"(hex : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L326","def":{"name":"decode","args":[{"name":"hex","doc":null,"default_value":"","external_name":"hex","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return decode(Util.hex_to_bin(hex))"}},{"id":"encode(b:Bytes)-class-method","html_id":"encode(b:Bytes)-class-method","name":"encode","doc":"RLP-encodes binary `Bytes` data.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to encode.\n\n```\nRlp.encode Bytes[15, 66, 64]\n# => Bytes[131, 15, 66, 64]\n```","summary":"RLP-encodes binary Bytes
data.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L33","def":{"name":"encode","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (b.bytesize === 1) && b.first < OFFSET_STRING\n return b\nend\nif b.bytesize < LIMIT_SHORT\n prefix = UInt8.new(b.bytesize + OFFSET_STRING)\n p = Bytes[prefix]\n return Util.binary_add(p, b)\nend\nif b.bytesize < LIMIT_LONG\n data_size = b.bytesize\n header = Util.int_to_bin(data_size)\n prefix = UInt8.new(((header.bytesize + OFFSET_STRING) + LIMIT_SHORT) - 1)\n p = Bytes[prefix]\n header = Util.binary_add(p, header)\n return Util.binary_add(header, b)\nelse\n raise(\"Invalid data provided (size out of range: #{b.bytesize})\")\nend\n"}},{"id":"encode(l:Array)-class-method","html_id":"encode(l:Array)-class-method","name":"encode","doc":"RLP-encodes nested `Array` data.\n\nParameters:\n* `l` (`Array`): the nested `Array` data to encode.\n\n```\nRlp.encode [[\"\"], [\"\"]]\n# => Bytes[196, 193, 128, 193, 128]\n```","summary":"RLP-encodes nested Array
data.
","abstract":false,"args":[{"name":"l","doc":null,"default_value":"","external_name":"l","restriction":"Array"}],"args_string":"(l : Array)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L87","def":{"name":"encode","args":[{"name":"l","doc":null,"default_value":"","external_name":"l","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if l.empty?\n return EMPTY_ARRAY\nend\nbody = Slice(UInt8).empty\nl.each do |a|\n if body.size === 0\n body = encode(a)\n else\n body = Util.binary_add(body, encode(a))\n end\nend\nif body.bytesize < LIMIT_SHORT\n prefix = UInt8.new(body.bytesize + OFFSET_ARRAY)\n p = Bytes[prefix]\n return Util.binary_add(p, body)\nend\nif body.bytesize < LIMIT_LONG\n data_size = body.bytesize\n header = Util.int_to_bin(data_size)\n prefix = UInt8.new(((header.bytesize + OFFSET_ARRAY) + LIMIT_SHORT) - 1)\n p = Bytes[prefix]\n header = Util.binary_add(p, header)\n return Util.binary_add(header, body)\nelse\n raise(\"Invalid list provided (size out of range: #{body.bytesize})\")\nend\n"}},{"id":"encode(s:String)-class-method","html_id":"encode(s:String)-class-method","name":"encode","doc":"RLP-encodes `String` literals.\n\nParameters:\n* `s` (`String`): the `String` literal to encode.\n\n```\nRlp.encode \"dog\"\n# => Bytes[131, 100, 111, 103]\n```","summary":"RLP-encodes String
literals.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L151","def":{"name":"encode","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if s.empty?\n return EMPTY_STRING\nelse\n if s.size < LIMIT_LONG\n return encode(Util.str_to_bin(s))\n else\n raise(\"Invalid string provided (size out of range: #{s.size})\")\n end\nend"}},{"id":"encode(i:Int)-class-method","html_id":"encode(i:Int)-class-method","name":"encode","doc":"RLP-encodes scalar `Int` numbers.\n\nParameters:\n* `i` (`Int`): the scalar `Int` number to encode.\n\n```\nRlp.encode 1_000_000\n# => Bytes[131, 15, 66, 64]\n```","summary":"RLP-encodes scalar Int
numbers.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L172","def":{"name":"encode","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i === 0\n return EMPTY_STRING\nelse\n if i > 0 && i < LIMIT_LONG\n return encode(Util.int_to_bin(i))\n else\n raise(\"Invalid scalar provided (out of range: #{i})\")\n end\nend"}},{"id":"encode(c:Char)-class-method","html_id":"encode(c:Char)-class-method","name":"encode","doc":"RLP-encodes `Char` characters.\n\nParameters:\n* `c` (`Char`): the `Char` character to encode.\n\n```\nRlp.encode 'x'\n# => Bytes[120]\n```","summary":"RLP-encodes Char
characters.
","abstract":false,"args":[{"name":"c","doc":null,"default_value":"","external_name":"c","restriction":"Char"}],"args_string":"(c : Char)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L195","def":{"name":"encode","args":[{"name":"c","doc":null,"default_value":"","external_name":"c","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return encode(c.to_s)"}},{"id":"encode(o:Bool)-class-method","html_id":"encode(o:Bool)-class-method","name":"encode","doc":"RLP-encodes boolean `Bool` values.\n\nParameters:\n* `o` (`Bool`): the boolean `Bool` value to encode.\n\n```\nRlp.encode true\n# => Bytes[1]\n```","summary":"RLP-encodes boolean Bool
values.
","abstract":false,"args":[{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"Bool"}],"args_string":"(o : Bool)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/rlp.cr#L209","def":{"name":"encode","args":[{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if o\n return Bytes[1]\nelse\n return EMPTY_STRING\nend"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/rlp.cr/Rlp/RecursiveArray","path":"Rlp/RecursiveArray.html","kind":"alias","full_name":"Rlp::RecursiveArray","name":"RecursiveArray","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"array.cr","line_number":32,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/array.cr"}],"repository_name":"github.com/q9f/rlp.cr","program":false,"enum":false,"alias":true,"aliased":"(Array(Rlp::RecursiveArray) | Slice(UInt8) | String)","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/rlp.cr/Rlp","kind":"module","full_name":"Rlp","name":"Rlp"},"doc":"An recursive array alias for arrays of unknown nesting depth.\n\n```crystal\na = [] of RecursiveArray\na << \"\"\na << Bytes[128]\na << [] of RecursiveArray\n```\n\nTODO: The recursive alias might be deprecated in future,\nref: [crystal-lang/crystal#5155](https://github.com/crystal-lang/crystal/issues/5155).\nit's worth considering a custom struct holding a `@data` property\nof type `String | Bytes | Array(RecursiveArray)` and forward missing methods,\nref: [crystal-lang/crystal#8719](https://github.com/crystal-lang/crystal/issues/8719).","summary":"An recursive array alias for arrays of unknown nesting depth.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/q9f/rlp.cr/Rlp/Util","path":"Rlp/Util.html","kind":"module","full_name":"Rlp::Util","name":"Util","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"util.cr","line_number":29,"url":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr"}],"repository_name":"github.com/q9f/rlp.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/rlp.cr/Rlp","kind":"module","full_name":"Rlp","name":"Rlp"},"doc":"Exposes a set of utilities to ease the handling of different data types.\nIt comes in handy when building protocols further decoding RLP byte-streams.\n\n```\ndecoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]\npp decoded\n# => [Bytes[42], Bytes[101, 116, 104]]\n\nprotocol = [] of String | Int32 | BigInt\nprotocol << Rlp::Util.bin_to_int decoded[0]\nprotocol << Rlp::Util.bin_to_str decoded[1]\npp protocol\n# => [42, \"eth\"]\n```","summary":"Exposes a set of utilities to ease the handling of different data types.
","class_methods":[{"id":"bin_to_hex(b:Bytes)-class-method","html_id":"bin_to_hex(b:Bytes)-class-method","name":"bin_to_hex","doc":"Converts binary `Bytes` to a hex-encoded `String`.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_hex Bytes[4, 200, 29]\n# => \"04c81d\"\n```","summary":"Converts binary Bytes
to a hex-encoded String
.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L61","def":{"name":"bin_to_hex","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = b.hexstring\nif h.size.odd?\n h = \"0#{h}\"\nend\nreturn h\n"}},{"id":"bin_to_int(b:Bytes)-class-method","html_id":"bin_to_int(b:Bytes)-class-method","name":"bin_to_int","doc":"Converts binary `Bytes` to a `BigInt`.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_int Bytes[15, 66, 64]\n# => 1000000\n```","summary":"Converts binary Bytes
to a BigInt
.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L39","def":{"name":"bin_to_int","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return BigInt.new(b.hexstring, 16)"}},{"id":"bin_to_int(a)-class-method","html_id":"bin_to_int(a)-class-method","name":"bin_to_int","doc":"Overloads `bin_to_int` with arbitrary data types and raises if\ninput data is not binary.\n\nNOTE: Raises in any case if `a` actually contains non-binary or nested data.\nShouldn't be used if decoded `Rlp` data could contain nested data structures.","summary":"Overloads .bin_to_int
with arbitrary data types and raises if input data is not binary.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"args_string":"(a)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L48","def":{"name":"bin_to_int","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"raise(\"Cannot convert arbitrary data to numbers, please unpack first!\")"}},{"id":"bin_to_str(b:Bytes)-class-method","html_id":"bin_to_str(b:Bytes)-class-method","name":"bin_to_str","doc":"Converts binary `Bytes` to a `String` literal.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_str Bytes[97, 98, 99]\n# => \"abc\"\n```","summary":"Converts binary Bytes
to a String
literal.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L76","def":{"name":"bin_to_str","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return String.new(b)"}},{"id":"bin_to_str(a)-class-method","html_id":"bin_to_str(a)-class-method","name":"bin_to_str","doc":"Overloads `bin_to_str` with arbitrary data types and raises if\ninput data is not binary.\n\nNOTE: Raises in any case if `a` actually contains non-binary or nested data.\nShouldn't be used if decoded `Rlp` data could contain nested data structures.","summary":"Overloads .bin_to_str
with arbitrary data types and raises if input data is not binary.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"args_string":"(a)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L85","def":{"name":"bin_to_str","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"raise(\"Cannot convert arbitrary data to strings, please unpack first!\")"}},{"id":"binary_add(a:Bytes,b:Bytes)-class-method","html_id":"binary_add(a:Bytes,b:Bytes)-class-method","name":"binary_add","doc":"Concatenates two `Bytes` slices of `UInt8`.\n\n```\na = Bytes[131]\nb = Bytes[97, 98, 99]\nRlp::Util.binary_add a, b\n# => Bytes[131, 97, 98, 99]\n```","summary":"Concatenates two Bytes
slices of UInt8
.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"Bytes"},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(a : Bytes, b : Bytes)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L195","def":{"name":"binary_add","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"Bytes"},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"c = IO::Memory.new(a.bytesize + b.bytesize)\na.each do |v|\n c.write_bytes(UInt8.new(v))\nend\nb.each do |v|\n c.write_bytes(UInt8.new(v))\nend\nreturn c.to_slice\n"}},{"id":"hex_to_bin(h:String)-class-method","html_id":"hex_to_bin(h:String)-class-method","name":"hex_to_bin","doc":"Converts hex-encoded `String`s to binary `Bytes` data.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_bin \"04c81d\"\n# => Bytes[4, 200, 29]\n```","summary":"Converts hex-encoded String
s to binary Bytes
data.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L128","def":{"name":"hex_to_bin","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nreturn h.hexbytes\n"}},{"id":"hex_to_int(h:String)-class-method","html_id":"hex_to_int(h:String)-class-method","name":"hex_to_int","doc":"Converts hex-encoded `String`s to `BigInt`s.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_int \"04c81d\"\n# => 313373\n```","summary":"Converts hex-encoded String
s to BigInt
s.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L142","def":{"name":"hex_to_int","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nreturn BigInt.new(h, 16)\n"}},{"id":"hex_to_str(h:String)-class-method","html_id":"hex_to_str(h:String)-class-method","name":"hex_to_str","doc":"Converts hex-encoded `String`s to `String` literals.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_str \"646f67\"\n# => \"dog\"\n```","summary":"Converts hex-encoded String
s to String
literals.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L156","def":{"name":"hex_to_str","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nreturn String.new(h.hexbytes)\n"}},{"id":"int_to_bin(i:Int)-class-method","html_id":"int_to_bin(i:Int)-class-method","name":"int_to_bin","doc":"Converts integers to binary `Bytes`.\n\nParameters:\n* `i` (`Int`): the integer to convert.\n\n```\nRlp::Util.int_to_bin 1_000_000\n# => Bytes[15, 66, 64]\n```","summary":"Converts integers to binary Bytes
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L98","def":{"name":"int_to_bin","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = i.to_s(16)\nif h.size.odd?\n h = \"0#{h}\"\nend\nreturn h.hexbytes\n"}},{"id":"int_to_hex(i:Int)-class-method","html_id":"int_to_hex(i:Int)-class-method","name":"int_to_hex","doc":"Converts integers to hex-encoded `String`s.\n\nParameters:\n* `i` (`Int`): the integer to convert.\n\n```\nRlp::Util.int_to_hex 313_373\n# => \"04c81d\"\n```","summary":"Converts integers to hex-encoded String
s.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L113","def":{"name":"int_to_hex","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = i.to_s(16)\nif h.size.odd?\n h = \"0#{h}\"\nend\nreturn h\n"}},{"id":"str_to_bin(s:String)-class-method","html_id":"str_to_bin(s:String)-class-method","name":"str_to_bin","doc":"Converts `String` literals to binary `Bytes` data.\n\nParameters:\n* `s` (`String`): the `String` literal to convert.\n\n```\nRlp::Util.str_to_bin \"abc\"\n# => Bytes[97, 98, 99]\n```","summary":"Converts String
literals to binary Bytes
data.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L170","def":{"name":"str_to_bin","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return s.to_slice"}},{"id":"str_to_hex(s:String)-class-method","html_id":"str_to_hex(s:String)-class-method","name":"str_to_hex","doc":"Converts `String` literals to hex-encoded `String`s.\n\nParameters:\n* `s` (`String`): the `String` literal to convert.\n\n```\nRlp::Util.str_to_hex \"dog\"\n# => \"646f67\"\n```","summary":"Converts String
literals to hex-encoded String
s.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","source_link":"https://github.com/q9f/rlp.cr/blob/5a44229dd0d4942943a70aaecb7e729013a91a97/src/util.cr#L183","def":{"name":"str_to_hex","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"return s.to_slice.hexstring"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}})
\ No newline at end of file
+crystal_doc_search_index_callback({"repository_name":"rlp","body":"# rlp.cr\n\n[![Build Status](https://img.shields.io/github/workflow/status/q9f/rlp.cr/Nightly)](https://github.com/q9f/rlp.cr/actions)\n[![Documentation](https://img.shields.io/badge/docs-html-black)](https://q9f.github.io/rlp.cr/)\n[![Release](https://img.shields.io/github/v/release/q9f/rlp.cr?include_prereleases&color=black)](https://github.com/q9f/rlp.cr/releases/latest)\n[![Language](https://img.shields.io/github/languages/top/q9f/rlp.cr?color=black)](https://github.com/q9f/rlp.cr/search?l=crystal)\n[![License](https://img.shields.io/github/license/q9f/rlp.cr.svg?color=black)](LICENSE)\n\na native library implementing `rlp` purely for the crystal language. `rlp` is ethereum's recursive length prefix used to encode arbitray data structures.\n\nthis library allows for rlp-encoding of:\n* binary data (assumed encoded)\n* boolean values (true, false)\n* scalars (positive integers)\n* string literals and characters\n* arrays containing any of the above\n* nested arrays containing any of the above\n\nthis library allows for decoding of:\n* rlp-encoded data in binary format\n* rlp-encoded data in hexadecimal string format\n\nnote, that decoded data is always binary as per ethereum's design rationale:\n\n> _\"RLP does not attempt to define any specific data types such as booleans, floats, doubles or even integers; instead, it simply exists to store structure, in the form of nested arrays, and leaves it up to the protocol to determine the meaning of the arrays\"_\n\n# installation\n\nadd the `rlp` library to your `shard.yml`\n\n```yaml\ndependencies:\n rlp:\n github: q9f/rlp.cr\n version: \"~> 0.1\"\n```\n\n# usage\n\n```crystal\n# import rlp\nrequire \"rlp\"\n```\n\nthis library exposes the following modules (in logical order):\n\n* `Rlp`: core library exposing `encode` and `decode` logic\n* `Rlp::Util`: a collection of utilities to ease the conversion between data types\n* `Rlp::RecursiveArray`: is a data type alias allowing for arrays of unknown nesting depth\n\nbasic usage:\n\n```crystal\n# rlp-encode a string\nrlp = Rlp.encode \"A cat with a short string.\"\n# => 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]\n\n# (optionally) get a hex representation of the rlp-encoded data\nhex = Rlp::Util.bin_to_hex rlp\n# => \"9a4120636174207769746820612073686f727420737472696e672e\"\n\n# decode the rlp data\nbin = Rlp.decode hex\n# => Bytes[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]\n\n# we expect a string, so we can try to convert it here\nstr = Rlp::Util.bin_to_str bin\n# => \"A cat with a short string.\"\n```\n\n# documentation\n\nthe full library documentation can be found here: [q9f.github.io/rlp.cr](https://q9f.github.io/rlp.cr/)\n\ngenerate a local copy with:\n\n```\ncrystal docs\n```\n\n# testing\n\nthe library is entirely specified through tests in `./spec`; run:\n\n```bash\ncrystal spec --verbose\n```\n\n# understand\n\nrecursive length prefixes are used by the ethereum protocol to store arbitrary data structures, e.g., signed transactions, and is a fundamental serialization used by ethereum's networking protocol `devp2p` which implements `rlpx`, the _recursive length prefix transfer protocol_.\n\n`rlp` can encode any data and data structure. the resulting data is a serialized byte-stream containing prefix bytes, header data, and actual data depending on the type and size of the encoded data.\n\n```crystal\nRlp.encode [42, \"eth\"]\n# => Bytes[197, 42, 131, 101, 116, 104]\n```\n\ndeserialization of `rlp`-encoded byte-streams allows for recovering the underlying data structure. however, `rlp` is kept minimalistic in its specification and is therefore agnostic to the data types used in the structures.\n\n```crystal\nRlp.decode Bytes[197, 42, 131, 101, 116, 104]\n# => [Bytes[42], Bytes[101, 116, 104]]\n```\n\nIt's up to applications using `rlp` to further specify protocols for decoding the actual data.\n\n```crystal\ndecoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]\nprotocol = [] of String | Int32 | BigInt\nprotocol << Rlp::Util.bin_to_int decoded[0]\nprotocol << Rlp::Util.bin_to_str decoded[1]\nprotocol\n# => [42, \"eth\"]\n```\n\n# contribute\n\ncreate a pull request, and make sure tests and linter passes.\n\nthis library with built with the help of the blog post by the mana team implementing [`rlp` in elixir](https://www.badykov.com/elixir/2018/05/06/rlp/) and coinmonks' [annotated version of the `rlp` specification](https://medium.com/coinmonks/data-structure-in-ethereum-episode-1-recursive-length-prefix-rlp-encoding-decoding-d1016832f919). ethereum classic's [`rlp` article](https://ethereumclassic.org/blog/2018-03-19-rlp/) allows for some sweet test cases.\n\nlicense: apache license v2.0\n\ncontributors: [**@q9f**](https://github.com/q9f/), [**@cserb**](https://github.com/cserb)\n","program":{"html_id":"rlp/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"rlp","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"rlp/Rlp","path":"Rlp.html","kind":"module","full_name":"Rlp","name":"Rlp","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/array.cr","line_number":17,"url":null},{"filename":"src/constants.cr","line_number":17,"url":null},{"filename":"src/rlp.cr","line_number":23,"url":null},{"filename":"src/version.cr","line_number":17,"url":null}],"repository_name":"rlp","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"EMPTY_ARRAY","name":"EMPTY_ARRAY","value":"Bytes[OFFSET_ARRAY]","doc":"An empty array is defined as `0xC0`.","summary":"An empty array is defined as 0xC0
.
"},{"id":"EMPTY_STRING","name":"EMPTY_STRING","value":"Bytes[OFFSET_STRING]","doc":"An empty string is defined as `0x80`.","summary":"An empty string is defined as 0x80
.
"},{"id":"LIMIT_LONG","name":"LIMIT_LONG","value":"(BigInt.new(256)) ** (BigInt.new(8))","doc":"The size limit of large data objects to be encoded is `256 ** 8`.","summary":"The size limit of large data objects to be encoded is 256 ** 8
.
"},{"id":"LIMIT_SHORT","name":"LIMIT_SHORT","value":"56","doc":"The size limit of small data objects to be encoded is `56`.","summary":"The size limit of small data objects to be encoded is 56
.
"},{"id":"OFFSET_ARRAY","name":"OFFSET_ARRAY","value":"192","doc":"The offset for array list encoding is `192`.","summary":"The offset for array list encoding is 192
.
"},{"id":"OFFSET_STRING","name":"OFFSET_STRING","value":"128","doc":"The offset for string literal encoding is `128`.","summary":"The offset for string literal encoding is 128
.
"},{"id":"VERSION","name":"VERSION","value":"\"0.1.8\"","doc":"The version of the `Rlp` module shard.","summary":"The version of the Rlp
module shard.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"The `Rlp` module implementing Ethereum's Recursive Length Prefix\nfor arbitrary data encoding and decoding.","summary":"The Rlp
module implementing Ethereum's Recursive Length Prefix for arbitrary data encoding and decoding.
","class_methods":[{"html_id":"decode(rlp:Bytes)-class-method","name":"decode","doc":"Decodes arbitrary data structures from a given binary\nrecursive length prefix data stream.\n\nParameters:\n* `rlp` (`Bytes`): the encoded `Rlp` data to decode.\n\n```\nRlp.decode Bytes[195, 193, 192, 192]\n# => [[[]], []]\n```\n\nNOTE: The returned data only restores the data structure.\nIt's up to the protocol to determine the meaning of the data\nas defined in Ethereum's design rationale.","summary":"Decodes arbitrary data structures from a given binary recursive length prefix data stream.
","abstract":false,"args":[{"name":"rlp","doc":null,"default_value":"","external_name":"rlp","restriction":"Bytes"}],"args_string":"(rlp : Bytes)","args_html":"(rlp : Bytes)","location":{"filename":"src/rlp.cr","line_number":233,"url":null},"def":{"name":"decode","args":[{"name":"rlp","doc":null,"default_value":"","external_name":"rlp","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if rlp === EMPTY_STRING\n return \"\"\nelse\n if rlp === EMPTY_ARRAY\n return [] of RecursiveArray\n end\nend\nprefix = rlp.first\nlength = rlp.bytesize\nif prefix < OFFSET_STRING && (length === 1)\n rlp\nelse\n if prefix < (OFFSET_STRING + LIMIT_SHORT)\n offset = 1\n rlp[offset, length - offset]\n else\n if prefix < OFFSET_ARRAY\n offset = (1 + prefix) - 183\n rlp[offset, length - offset]\n else\n result = [] of RecursiveArray\n if prefix < (OFFSET_ARRAY + LIMIT_SHORT)\n offset = 1\n rlp = rlp[offset, length - offset]\n else\n offset = (1 + prefix) - 247\n rlp = rlp[offset, length - offset]\n end\n while rlp.bytesize > 0\n prefix = rlp.first\n length = 0\n if prefix < OFFSET_STRING\n length = 1\n else\n if prefix < (OFFSET_STRING + LIMIT_SHORT)\n length = (1 + prefix) - OFFSET_STRING\n else\n if prefix < OFFSET_ARRAY\n header_size = prefix - 183\n header = rlp[1, header_size]\n length = (1 + header_size) + (Util.bin_to_int(header))\n else\n if prefix < (OFFSET_ARRAY + LIMIT_SHORT)\n length = (1 + prefix) - OFFSET_ARRAY\n else\n header_size = prefix - 247\n header = rlp[1, header_size]\n length = (1 + header_size) + (Util.bin_to_int(header))\n end\n end\n end\n end\n result << (decode(rlp[0, length]))\n offset = length\n length = rlp.size - length\n rlp = rlp[offset, length]\n end\n result\n end\n end\nend\n"}},{"html_id":"decode(hex:String)-class-method","name":"decode","doc":"Decodes arbitrary data structures from a given hex-encoded\nrecursive length prefix data stream.\n\nParameters:\n* `hex` (`String`): the encoded `Rlp` data to decode.\n\n```\nRlp.decode \"c7c0c1c0c3c0c1c0\"\n# => [[], [[]], [[], [[]]]]\n```\n\nNOTE: The returned data only restores the data structure.\nIt's up to the protocol to determine the meaning of the data\nas defined in Ethereum's design rationale.","summary":"Decodes arbitrary data structures from a given hex-encoded recursive length prefix data stream.
","abstract":false,"args":[{"name":"hex","doc":null,"default_value":"","external_name":"hex","restriction":"String"}],"args_string":"(hex : String)","args_html":"(hex : String)","location":{"filename":"src/rlp.cr","line_number":326,"url":null},"def":{"name":"decode","args":[{"name":"hex","doc":null,"default_value":"","external_name":"hex","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"decode(Util.hex_to_bin(hex))"}},{"html_id":"encode(b:Bytes)-class-method","name":"encode","doc":"RLP-encodes binary `Bytes` data.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to encode.\n\n```\nRlp.encode Bytes[15, 66, 64]\n# => Bytes[131, 15, 66, 64]\n```","summary":"RLP-encodes binary Bytes
data.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/rlp.cr","line_number":33,"url":null},"def":{"name":"encode","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (b.bytesize === 1) && b.first < OFFSET_STRING\n return b\nend\nif b.bytesize < LIMIT_SHORT\n prefix = UInt8.new(b.bytesize + OFFSET_STRING)\n p = Bytes[prefix]\n return Util.binary_add(p, b)\nend\nif b.bytesize < LIMIT_LONG\n data_size = b.bytesize\n header = Util.int_to_bin(data_size)\n prefix = UInt8.new(((header.bytesize + OFFSET_STRING) + LIMIT_SHORT) - 1)\n p = Bytes[prefix]\n header = Util.binary_add(p, header)\n Util.binary_add(header, b)\nelse\n raise(\"Invalid data provided (size out of range: #{b.bytesize})\")\nend\n"}},{"html_id":"encode(l:Array)-class-method","name":"encode","doc":"RLP-encodes nested `Array` data.\n\nParameters:\n* `l` (`Array`): the nested `Array` data to encode.\n\n```\nRlp.encode [[\"\"], [\"\"]]\n# => Bytes[196, 193, 128, 193, 128]\n```","summary":"RLP-encodes nested Array
data.
","abstract":false,"args":[{"name":"l","doc":null,"default_value":"","external_name":"l","restriction":"Array"}],"args_string":"(l : Array)","args_html":"(l : Array)","location":{"filename":"src/rlp.cr","line_number":87,"url":null},"def":{"name":"encode","args":[{"name":"l","doc":null,"default_value":"","external_name":"l","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if l.empty?\n return EMPTY_ARRAY\nend\nbody = Slice(UInt8).empty\nl.each do |a|\n if body.size === 0\n body = encode(a)\n else\n body = Util.binary_add(body, encode(a))\n end\nend\nif body.bytesize < LIMIT_SHORT\n prefix = UInt8.new(body.bytesize + OFFSET_ARRAY)\n p = Bytes[prefix]\n return Util.binary_add(p, body)\nend\nif body.bytesize < LIMIT_LONG\n data_size = body.bytesize\n header = Util.int_to_bin(data_size)\n prefix = UInt8.new(((header.bytesize + OFFSET_ARRAY) + LIMIT_SHORT) - 1)\n p = Bytes[prefix]\n header = Util.binary_add(p, header)\n Util.binary_add(header, body)\nelse\n raise(\"Invalid list provided (size out of range: #{body.bytesize})\")\nend\n"}},{"html_id":"encode(s:String)-class-method","name":"encode","doc":"RLP-encodes `String` literals.\n\nParameters:\n* `s` (`String`): the `String` literal to encode.\n\n```\nRlp.encode \"dog\"\n# => Bytes[131, 100, 111, 103]\n```","summary":"RLP-encodes String
literals.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","args_html":"(s : String)","location":{"filename":"src/rlp.cr","line_number":151,"url":null},"def":{"name":"encode","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if s.empty?\n EMPTY_STRING\nelse\n if s.size < LIMIT_LONG\n encode(Util.str_to_bin(s))\n else\n raise(\"Invalid string provided (size out of range: #{s.size})\")\n end\nend"}},{"html_id":"encode(i:Int)-class-method","name":"encode","doc":"RLP-encodes scalar `Int` numbers.\n\nParameters:\n* `i` (`Int`): the scalar `Int` number to encode.\n\n```\nRlp.encode 1_000_000\n# => Bytes[131, 15, 66, 64]\n```","summary":"RLP-encodes scalar Int
numbers.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","args_html":"(i : Int)","location":{"filename":"src/rlp.cr","line_number":172,"url":null},"def":{"name":"encode","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i === 0\n EMPTY_STRING\nelse\n if i > 0 && i < LIMIT_LONG\n encode(Util.int_to_bin(i))\n else\n raise(\"Invalid scalar provided (out of range: #{i})\")\n end\nend"}},{"html_id":"encode(c:Char)-class-method","name":"encode","doc":"RLP-encodes `Char` characters.\n\nParameters:\n* `c` (`Char`): the `Char` character to encode.\n\n```\nRlp.encode 'x'\n# => Bytes[120]\n```","summary":"RLP-encodes Char
characters.
","abstract":false,"args":[{"name":"c","doc":null,"default_value":"","external_name":"c","restriction":"Char"}],"args_string":"(c : Char)","args_html":"(c : Char)","location":{"filename":"src/rlp.cr","line_number":195,"url":null},"def":{"name":"encode","args":[{"name":"c","doc":null,"default_value":"","external_name":"c","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"encode(c.to_s)"}},{"html_id":"encode(o:Bool)-class-method","name":"encode","doc":"RLP-encodes boolean `Bool` values.\n\nParameters:\n* `o` (`Bool`): the boolean `Bool` value to encode.\n\n```\nRlp.encode true\n# => Bytes[1]\n```","summary":"RLP-encodes boolean Bool
values.
","abstract":false,"args":[{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"Bool"}],"args_string":"(o : Bool)","args_html":"(o : Bool)","location":{"filename":"src/rlp.cr","line_number":209,"url":null},"def":{"name":"encode","args":[{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if o\n Bytes[1]\nelse\n EMPTY_STRING\nend"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"rlp/Rlp/RecursiveArray","path":"Rlp/RecursiveArray.html","kind":"alias","full_name":"Rlp::RecursiveArray","name":"RecursiveArray","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/array.cr","line_number":32,"url":null}],"repository_name":"rlp","program":false,"enum":false,"alias":true,"aliased":"(Array(Rlp::RecursiveArray) | Slice(UInt8) | String)","aliased_html":"Array(Rlp::RecursiveArray) | Slice(UInt8) | String","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"rlp/Rlp","kind":"module","full_name":"Rlp","name":"Rlp"},"doc":"An recursive array alias for arrays of unknown nesting depth.\n\n```\na = [] of RecursiveArray\na << \"\"\na << Bytes[128]\na << [] of RecursiveArray\n```\n\nTODO: The recursive alias might be deprecated in future,\nref: [crystal-lang/crystal#5155](https://github.com/crystal-lang/crystal/issues/5155).\nit's worth considering a custom struct holding a `@data` property\nof type `String | Bytes | Array(RecursiveArray)` and forward missing methods,\nref: [crystal-lang/crystal#8719](https://github.com/crystal-lang/crystal/issues/8719).","summary":"An recursive array alias for arrays of unknown nesting depth.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"rlp/Rlp/Util","path":"Rlp/Util.html","kind":"module","full_name":"Rlp::Util","name":"Util","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/util.cr","line_number":29,"url":null}],"repository_name":"rlp","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"rlp/Rlp","kind":"module","full_name":"Rlp","name":"Rlp"},"doc":"Exposes a set of utilities to ease the handling of different data types.\nIt comes in handy when building protocols further decoding RLP byte-streams.\n\n```\ndecoded = Rlp.decode Bytes[197, 42, 131, 101, 116, 104]\npp decoded\n# => [Bytes[42], Bytes[101, 116, 104]]\n\nprotocol = [] of String | Int32 | BigInt\nprotocol << Rlp::Util.bin_to_int decoded[0]\nprotocol << Rlp::Util.bin_to_str decoded[1]\npp protocol\n# => [42, \"eth\"]\n```","summary":"Exposes a set of utilities to ease the handling of different data types.
","class_methods":[{"html_id":"bin_to_hex(b:Bytes)-class-method","name":"bin_to_hex","doc":"Converts binary `Bytes` to a hex-encoded `String`.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_hex Bytes[4, 200, 29]\n# => \"04c81d\"\n```","summary":"Converts binary Bytes
to a hex-encoded String
.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/util.cr","line_number":61,"url":null},"def":{"name":"bin_to_hex","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = b.hexstring\nif h.size.odd?\n return \"0#{h}\"\nend\nh\n"}},{"html_id":"bin_to_int(b:Bytes)-class-method","name":"bin_to_int","doc":"Converts binary `Bytes` to a `BigInt`.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_int Bytes[15, 66, 64]\n# => 1000000\n```","summary":"Converts binary Bytes
to a BigInt
.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/util.cr","line_number":39,"url":null},"def":{"name":"bin_to_int","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"BigInt.new(b.hexstring, 16)"}},{"html_id":"bin_to_int(a)-class-method","name":"bin_to_int","doc":"Overloads `bin_to_int` with arbitrary data types and raises if\ninput data is not binary.\n\nNOTE: Raises in any case if `a` actually contains non-binary or nested data.\nShouldn't be used if decoded `Rlp` data could contain nested data structures.","summary":"Overloads .bin_to_int
with arbitrary data types and raises if input data is not binary.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"args_string":"(a)","args_html":"(a)","location":{"filename":"src/util.cr","line_number":48,"url":null},"def":{"name":"bin_to_int","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"raise(\"Cannot convert arbitrary data to numbers, please unpack first!\")"}},{"html_id":"bin_to_str(b:Bytes)-class-method","name":"bin_to_str","doc":"Converts binary `Bytes` to a `String` literal.\n\nParameters:\n* `b` (`Bytes`): the binary `Bytes` data to convert.\n\n```\nRlp::Util.bin_to_str Bytes[97, 98, 99]\n# => \"abc\"\n```","summary":"Converts binary Bytes
to a String
literal.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/util.cr","line_number":76,"url":null},"def":{"name":"bin_to_str","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"String.new(b)"}},{"html_id":"bin_to_str(a)-class-method","name":"bin_to_str","doc":"Overloads `bin_to_str` with arbitrary data types and raises if\ninput data is not binary.\n\nNOTE: Raises in any case if `a` actually contains non-binary or nested data.\nShouldn't be used if decoded `Rlp` data could contain nested data structures.","summary":"Overloads .bin_to_str
with arbitrary data types and raises if input data is not binary.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"args_string":"(a)","args_html":"(a)","location":{"filename":"src/util.cr","line_number":85,"url":null},"def":{"name":"bin_to_str","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"raise(\"Cannot convert arbitrary data to strings, please unpack first!\")"}},{"html_id":"binary_add(a:Bytes,b:Bytes)-class-method","name":"binary_add","doc":"Concatenates two `Bytes` slices of `UInt8`.\n\n```\na = Bytes[131]\nb = Bytes[97, 98, 99]\nRlp::Util.binary_add a, b\n# => Bytes[131, 97, 98, 99]\n```","summary":"Concatenates two Bytes
slices of UInt8
.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"Bytes"},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(a : Bytes, b : Bytes)","args_html":"(a : Bytes, b : Bytes)","location":{"filename":"src/util.cr","line_number":195,"url":null},"def":{"name":"binary_add","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"Bytes"},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"c = IO::Memory.new(a.bytesize + b.bytesize)\na.each do |v|\n c.write_bytes(UInt8.new(v))\nend\nb.each do |v|\n c.write_bytes(UInt8.new(v))\nend\nc.to_slice\n"}},{"html_id":"hex_to_bin(h:String)-class-method","name":"hex_to_bin","doc":"Converts hex-encoded `String`s to binary `Bytes` data.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_bin \"04c81d\"\n# => Bytes[4, 200, 29]\n```","summary":"Converts hex-encoded String
s to binary Bytes
data.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/util.cr","line_number":128,"url":null},"def":{"name":"hex_to_bin","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nh.hexbytes\n"}},{"html_id":"hex_to_int(h:String)-class-method","name":"hex_to_int","doc":"Converts hex-encoded `String`s to `BigInt`s.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_int \"04c81d\"\n# => 313373\n```","summary":"Converts hex-encoded String
s to BigInt
s.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/util.cr","line_number":142,"url":null},"def":{"name":"hex_to_int","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nBigInt.new(h, 16)\n"}},{"html_id":"hex_to_str(h:String)-class-method","name":"hex_to_str","doc":"Converts hex-encoded `String`s to `String` literals.\n\nParameters:\n* `h` (`String`): the hex-encoded `String` to convert.\n\n```\nRlp::Util.hex_to_str \"646f67\"\n# => \"dog\"\n```","summary":"Converts hex-encoded String
s to String
literals.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/util.cr","line_number":156,"url":null},"def":{"name":"hex_to_str","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if h.size.odd?\n h = \"0#{h}\"\nend\nString.new(h.hexbytes)\n"}},{"html_id":"int_to_bin(i:Int)-class-method","name":"int_to_bin","doc":"Converts integers to binary `Bytes`.\n\nParameters:\n* `i` (`Int`): the integer to convert.\n\n```\nRlp::Util.int_to_bin 1_000_000\n# => Bytes[15, 66, 64]\n```","summary":"Converts integers to binary Bytes
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","args_html":"(i : Int)","location":{"filename":"src/util.cr","line_number":98,"url":null},"def":{"name":"int_to_bin","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = i.to_s(16)\nif h.size.odd?\n h = \"0#{h}\"\nend\nh.hexbytes\n"}},{"html_id":"int_to_hex(i:Int)-class-method","name":"int_to_hex","doc":"Converts integers to hex-encoded `String`s.\n\nParameters:\n* `i` (`Int`): the integer to convert.\n\n```\nRlp::Util.int_to_hex 313_373\n# => \"04c81d\"\n```","summary":"Converts integers to hex-encoded String
s.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"args_string":"(i : Int)","args_html":"(i : Int)","location":{"filename":"src/util.cr","line_number":113,"url":null},"def":{"name":"int_to_hex","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h = i.to_s(16)\nif h.size.odd?\n return \"0#{h}\"\nend\nh\n"}},{"html_id":"str_to_bin(s:String)-class-method","name":"str_to_bin","doc":"Converts `String` literals to binary `Bytes` data.\n\nParameters:\n* `s` (`String`): the `String` literal to convert.\n\n```\nRlp::Util.str_to_bin \"abc\"\n# => Bytes[97, 98, 99]\n```","summary":"Converts String
literals to binary Bytes
data.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","args_html":"(s : String)","location":{"filename":"src/util.cr","line_number":170,"url":null},"def":{"name":"str_to_bin","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"s.to_slice"}},{"html_id":"str_to_hex(s:String)-class-method","name":"str_to_hex","doc":"Converts `String` literals to hex-encoded `String`s.\n\nParameters:\n* `s` (`String`): the `String` literal to convert.\n\n```\nRlp::Util.str_to_hex \"dog\"\n# => \"646f67\"\n```","summary":"Converts String
literals to hex-encoded String
s.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","args_html":"(s : String)","location":{"filename":"src/util.cr","line_number":183,"url":null},"def":{"name":"str_to_hex","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"s.to_slice.hexstring"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}})
\ No newline at end of file