rlp 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rlp/decode.rb +66 -0
- data/lib/rlp/version.rb +1 -1
- data/lib/rlp.rb +3 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fad92357be8370fb91160e0771665036fb97fd3d
|
4
|
+
data.tar.gz: 1b8d1f21cb5b22c865126c9bf66644d871a11d7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c6b2f55c20bde762dd57d50ae9ae50b3bd97bc6ad25659b5fdb79a715e7298ab5cf333ebea19911fba1bfd7619b121d545bb17b52e04df58a818438f0fc70ff
|
7
|
+
data.tar.gz: 4d30b64dc2a491288d7e049512842360658d494722ce0d81e22b20ca3097df4ce81f15a8d3505f8104f631236534c01a3fb62a5a5049986006c9d0931f055c13
|
data/lib/rlp/decode.rb
CHANGED
@@ -82,6 +82,72 @@ module RLP
|
|
82
82
|
rlp
|
83
83
|
end
|
84
84
|
|
85
|
+
def append(rlp, obj)
|
86
|
+
type, len, pos = consume_length_prefix rlp, 0
|
87
|
+
raise DecodingError.new("Trying to append to a non-list!", rlp) if type != :list
|
88
|
+
|
89
|
+
rlpdata = rlp[pos..-1] + RLP.encode(obj)
|
90
|
+
prefix = length_prefix rlpdata.size, LIST_PREFIX_OFFSET
|
91
|
+
|
92
|
+
prefix + rlpdata
|
93
|
+
end
|
94
|
+
|
95
|
+
def insert(rlp, index, obj)
|
96
|
+
type, len, pos = consume_length_prefix rlp, 0
|
97
|
+
raise DecodingError.new("Trying to insert to a non-list!", rlp) if type != :list
|
98
|
+
|
99
|
+
beginpos = pos
|
100
|
+
index.times do |i|
|
101
|
+
_, _len, _pos = consume_length_prefix rlp, pos
|
102
|
+
pos = _pos + _len
|
103
|
+
break if _pos >= rlp.size
|
104
|
+
end
|
105
|
+
|
106
|
+
rlpdata = rlp[beginpos...pos] + RLP.encode(obj) + rlp[pos..-1]
|
107
|
+
prefix = length_prefix rlpdata.size, LIST_PREFIX_OFFSET
|
108
|
+
|
109
|
+
prefix + rlpdata
|
110
|
+
end
|
111
|
+
|
112
|
+
def pop(rlp, index=2**50)
|
113
|
+
type, len, pos = consume_length_prefix rlp, 0
|
114
|
+
raise DecodingError.new("Trying to pop from a non-list!", rlp) if type != :list
|
115
|
+
|
116
|
+
beginpos = pos
|
117
|
+
index.times do |i|
|
118
|
+
_, _len, _pos = consume_length_prefix rlp, pos
|
119
|
+
break if _len + _pos >= rlp.size
|
120
|
+
pos = _len + _pos
|
121
|
+
end
|
122
|
+
|
123
|
+
_, _len, _pos = consume_length_prefix rlp, pos
|
124
|
+
rlpdata = rlp[beginpos...pos] + rlp[(_len+_pos)..-1]
|
125
|
+
prefix = length_prefix rlpdata.size, LIST_PREFIX_OFFSET
|
126
|
+
|
127
|
+
prefix + rlpdata
|
128
|
+
end
|
129
|
+
|
130
|
+
def compare_length(rlp, length)
|
131
|
+
type, len, pos = consume_length_prefix rlp, 0
|
132
|
+
raise DecodingError.new("Trying to compare length of non-list!", rlp) if type != :list
|
133
|
+
|
134
|
+
return (length == 0 ? 0 : -length/length.abs) if rlp == EMPTYLIST
|
135
|
+
|
136
|
+
beginpos = pos
|
137
|
+
len = 0
|
138
|
+
loop do
|
139
|
+
return 1 if len > length
|
140
|
+
|
141
|
+
_, _len, _pos = consume_length_prefix rlp, pos
|
142
|
+
len += 1
|
143
|
+
|
144
|
+
break if _len + _pos >= rlp.size
|
145
|
+
pos = _len + _pos
|
146
|
+
end
|
147
|
+
|
148
|
+
len == length ? 0 : -1
|
149
|
+
end
|
150
|
+
|
85
151
|
private
|
86
152
|
|
87
153
|
##
|
data/lib/rlp/version.rb
CHANGED
data/lib/rlp.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rlp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Xie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.4.5
|
102
|
+
rubygems_version: 2.4.5.1
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: The ruby RLP serialization library.
|