lib/eth/rlp/decoder.rb
def consume_length_prefix(rlp, start)
        b0 = rlp[start].ord
        if b0 < Constant::PRIMITIVE_PREFIX_OFFSET

          # single byte
          [:str, 1, start]
        elsif b0 < Constant::PRIMITIVE_PREFIX_OFFSET + Constant::SHORT_LENGTH_LIMIT
          raise DecodingError, "Encoded as short string although single byte was possible" if (b0 - Constant::PRIMITIVE_PREFIX_OFFSET == 1) && rlp[start + 1].ord < Constant::PRIMITIVE_PREFIX_OFFSET

          # short string
          [:str, b0 - Constant::PRIMITIVE_PREFIX_OFFSET, start + 1]
        elsif b0 < Constant::LIST_PREFIX_OFFSET
          enforce_no_zero_bytes rlp, start

          # long string
          ll = b0 - Constant::PRIMITIVE_PREFIX_OFFSET - Constant::SHORT_LENGTH_LIMIT + 1
          l = Util.big_endian_to_int rlp[(start + 1)...(start + 1 + ll)]
          raise DecodingError, "Long string prefix used for short string" if l < Constant::SHORT_LENGTH_LIMIT
          [:str, l, start + 1 + ll]
        elsif b0 < Constant::LIST_PREFIX_OFFSET + Constant::SHORT_LENGTH_LIMIT

          # short list
          [:list, b0 - Constant::LIST_PREFIX_OFFSET, start + 1]
        else
          enforce_no_zero_bytes rlp, start

          # long list
          ll = b0 - Constant::LIST_PREFIX_OFFSET - Constant::SHORT_LENGTH_LIMIT + 1
          l = Util.big_endian_to_int rlp[(start + 1)...(start + 1 + ll)]
          raise DecodingError, "Long list prefix used for short list" if l < Constant::SHORT_LENGTH_LIMIT
          [:list, l, start + 1 + ll]
        end
      end
# Consume an RLP length prefix at the given position.
Consume an RLP length prefix at the given position.
Consume an RLP length prefix at the given position .
def consume_length_prefix(rlp, start)
        b0 = rlp[start].ord
        if b0 < Constant::PRIMITIVE_PREFIX_OFFSET
          [:str, 1, start]
        elsif b0 < Constant::PRIMITIVE_PREFIX_OFFSET + Constant::SHORT_LENGTH_LIMIT
          raise DecodingError, "Encoded as short string although single byte was possible" if (b0 - Constant::PRIMITIVE_PREFIX_OFFSET == 1) && rlp[start + 1].ord < Constant::PRIMITIVE_PREFIX_OFFSET
          [:str, b0 - Constant::PRIMITIVE_PREFIX_OFFSET, start + 1]
        elsif b0 < Constant::LIST_PREFIX_OFFSET
          enforce_no_zero_bytes rlp, start
          ll = b0 - Constant::PRIMITIVE_PREFIX_OFFSET - Constant::SHORT_LENGTH_LIMIT + 1
          l = Util.big_endian_to_int rlp[(start + 1)...(start + 1 + ll)]
          raise DecodingError, "Long string prefix used for short string" if l < Constant::SHORT_LENGTH_LIMIT
          [:str, l, start + 1 + ll]
        elsif b0 < Constant::LIST_PREFIX_OFFSET + Constant::SHORT_LENGTH_LIMIT
          [:list, b0 - Constant::LIST_PREFIX_OFFSET, start + 1]
        else
          enforce_no_zero_bytes rlp, start
          ll = b0 - Constant::LIST_PREFIX_OFFSET - Constant::SHORT_LENGTH_LIMIT + 1
          l = Util.big_endian_to_int rlp[(start + 1)...(start + 1 + ll)]
          raise DecodingError, "Long list prefix used for short list" if l < Constant::SHORT_LENGTH_LIMIT
          [:list, l, start + 1 + ll]
        end
      end
def consume_length_prefix ( rlp , start ) b0 = rlp [ start ] . ord if b0 < Constant :: PRIMITIVE_PREFIX_OFFSET [ :str , 1 , start ] elsif b0 < Constant :: PRIMITIVE_PREFIX_OFFSET + Constant :: SHORT_LENGTH_LIMIT raise DecodingError , "Encoded as short string although single byte was possible" if ( b0 - Constant :: PRIMITIVE_PREFIX_OFFSET == 1 ) && rlp [ start + 1 ] . ord < Constant :: PRIMITIVE_PREFIX_OFFSET [ :str , b0 - Constant :: PRIMITIVE_PREFIX_OFFSET , start + 1 ] elsif b0 < Constant :: LIST_PREFIX_OFFSET enforce_no_zero_bytes rlp , start ll = b0 - Constant :: PRIMITIVE_PREFIX_OFFSET - Constant :: SHORT_LENGTH_LIMIT + 1 l = Util . big_endian_to_int rlp [ ( start + 1 ) ... ( start + 1 + ll ) ] raise DecodingError , "Long string prefix used for short string" if l < Constant :: SHORT_LENGTH_LIMIT [ :str , l , start + 1 + ll ] elsif b0 < Constant :: LIST_PREFIX_OFFSET + Constant :: SHORT_LENGTH_LIMIT [ :list , b0 - Constant :: LIST_PREFIX_OFFSET , start + 1 ] else enforce_no_zero_bytes rlp , start ll = b0 - Constant :: LIST_PREFIX_OFFSET - Constant :: SHORT_LENGTH_LIMIT + 1 l = Util . big_endian_to_int rlp [ ( start + 1 ) ... ( start + 1 + ll ) ] raise DecodingError , "Long list prefix used for short list" if l < Constant :: SHORT_LENGTH_LIMIT [ :list , l , start + 1 + ll ] end end
Consume an RLP length prefix at the given position.
Consume an RLP length prefix at the given position .
# single byte # short string # long string # short list # long list
rlp
start