File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ func Decode(r io.Reader, val interface{}) error {
90
90
// DecodeBytes parses RLP data from b into val. Please see package-level documentation for
91
91
// the decoding rules. The input must contain exactly one value and no trailing data.
92
92
func DecodeBytes (b []byte , val interface {}) error {
93
- r := bytes . NewReader ( b )
93
+ r := ( * sliceReader )( & b )
94
94
95
95
stream := streamPool .Get ().(* Stream )
96
96
defer streamPool .Put (stream )
@@ -99,7 +99,7 @@ func DecodeBytes(b []byte, val interface{}) error {
99
99
if err := stream .Decode (val ); err != nil {
100
100
return err
101
101
}
102
- if r . Len ( ) > 0 {
102
+ if len ( b ) > 0 {
103
103
return ErrMoreThanOneValue
104
104
}
105
105
return nil
@@ -1182,3 +1182,23 @@ func (s *Stream) listLimit() (inList bool, limit uint64) {
1182
1182
}
1183
1183
return true , s .stack [len (s .stack )- 1 ]
1184
1184
}
1185
+
1186
+ type sliceReader []byte
1187
+
1188
+ func (sr * sliceReader ) Read (b []byte ) (int , error ) {
1189
+ if len (* sr ) == 0 {
1190
+ return 0 , io .EOF
1191
+ }
1192
+ n := copy (b , * sr )
1193
+ * sr = (* sr )[n :]
1194
+ return n , nil
1195
+ }
1196
+
1197
+ func (sr * sliceReader ) ReadByte () (byte , error ) {
1198
+ if len (* sr ) == 0 {
1199
+ return 0 , io .EOF
1200
+ }
1201
+ b := (* sr )[0 ]
1202
+ * sr = (* sr )[1 :]
1203
+ return b , nil
1204
+ }
You can’t perform that action at this time.
0 commit comments