Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umbracle/fastrlp
Fast RLP encoder/decoder
https://github.com/umbracle/fastrlp
ethereum fast go rlp
Last synced: 4 days ago
JSON representation
Fast RLP encoder/decoder
- Host: GitHub
- URL: https://github.com/umbracle/fastrlp
- Owner: umbracle
- License: apache-2.0
- Created: 2019-10-15T10:38:28.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-18T21:58:02.000Z (11 months ago)
- Last Synced: 2024-06-18T16:55:19.621Z (5 months ago)
- Topics: ethereum, fast, go, rlp
- Language: Go
- Size: 72.3 KB
- Stars: 25
- Watchers: 2
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FastRlp
FastRlp is a high performant encoding/decoding library for the RLP Ethereum format. This library is based on [fastjson](https://github.com/valyala/fastjson).
## Usage
FastRlp does not uses reflect to avoid bottlenecks. It provides a single value primitive that can be encoded or decoded into any specific type.
Encode:
```
a := &fastrlp.Arena{}// Encode a uint
v := a.NewUint(300)
buf := v.MarshalTo(nil)// Encode an array
v = a.NewArray()
v.Set(a.NewUint(300))
buf = v.MarshalTo(nil)
```You can find more examples [here](https://github.com/umbracle/fastrlp/blob/master/arena_test.go#L53).
Decode:
```
p := &fastrlp.Parser{}
v, err := p.Parse([]byte{0x01})
if err != nil {
panic(err)
}num, err := v.GetUint64()
if err != nil {
panic(err)
}
fmt.Println(num)
```## Benchmark
```
$ go-rlp-test go test -v ./. -run=XX -bench=.
goos: linux
goarch: amd64
pkg: github.com/ferranbt/go-rlp-test
BenchmarkDecode100HeadersGeth-8 10000 196183 ns/op 32638 B/op 1002 allocs/op
BenchmarkEncode100HeadersGeth-8 10000 179328 ns/op 88471 B/op 1003 allocs/op
BenchmarkDecode100HeadersFastRlp-8 30000 57179 ns/op 16 B/op 0 allocs/op
BenchmarkEncode100HeadersFastRlp-8 30000 43967 ns/op 23 B/op 0 allocs/op
PASS
ok github.com/ferranbt/go-rlp-test 7.890s
```