Class: Marshalsea::Marshal::Parser
- Inherits:
-
Object
- Object
- Marshalsea::Marshal::Parser
- Includes:
- Constants
- Defined in:
- lib/marshalsea/marshal/parser.rb
Constant Summary
Constants included from Constants
Constants::BIGNUM_SIGNS, Constants::BIGNUM_SIGN_NEGATIVE, Constants::BIGNUM_SIGN_POSITIVE, Constants::BIGNUM_WORD_BYTES, Constants::BITS_PER_BYTE, Constants::BYTE_MODULUS, Constants::BYTE_SIGN_THRESHOLD, Constants::CLASS_NAME_TYPES, Constants::DEFAULT_MAX_DEPTH, Constants::FIXNUM_INLINE_OFFSET, Constants::FIXNUM_MAX_INLINE, Constants::FIXNUM_MAX_WIDTH, Constants::FIXNUM_MIN_INLINE, Constants::FLOAT_DECIMAL_PREFIX, Constants::FLOAT_HEX_PREFIX, Constants::FLOAT_INFINITY, Constants::FLOAT_LEADING_SPACE, Constants::FLOAT_NAN, Constants::FLOAT_NEGATIVE_INFINITY, Constants::GATED_SINK_TAGS, Constants::HEADER_LENGTH, Constants::MAJOR_VERSION, Constants::MINOR_VERSION, Constants::NUL_BYTE, Constants::RANGE_CLASS_NAME, Constants::RANGE_ENDPOINT_IVARS, Constants::REGISTERED_WRAPPER_TYPES, Constants::ROLE_ANOMALY, Constants::ROLE_ARRAY, Constants::ROLE_BIGNUM, Constants::ROLE_HASH, Constants::ROLE_IVAR, Constants::ROLE_LENGTH, Constants::ROLE_STRUCT, Constants::SINK_METHODS, Constants::SINK_TAGS, Constants::TAG_ARRAY, Constants::TAG_BIGNUM, Constants::TAG_CLASS, Constants::TAG_DATA, Constants::TAG_EXTENDED, Constants::TAG_FALSE, Constants::TAG_FIXNUM, Constants::TAG_FLOAT, Constants::TAG_HASH, Constants::TAG_HASH_DEFAULT, Constants::TAG_IVAR, Constants::TAG_MODULE, Constants::TAG_MODULE_OLD, Constants::TAG_NIL, Constants::TAG_OBJECT, Constants::TAG_OBJECT_LINK, Constants::TAG_REGEXP, Constants::TAG_STRING, Constants::TAG_STRUCT, Constants::TAG_SYMBOL, Constants::TAG_SYMLINK, Constants::TAG_TRUE, Constants::TAG_USERCLASS, Constants::TAG_USERDEF, Constants::TAG_USERMARSHAL
Instance Method Summary collapse
-
#initialize(source, max_depth: nil, limits: Limits.new) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(source, max_depth: nil, limits: Limits.new) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/marshalsea/marshal/parser.rb', line 10 def initialize(source, max_depth: nil, limits: Limits.new) raise InputTypeError, "expected String, got #{source.class}" unless source.is_a?(String) @limits = limits @max_depth = max_depth || limits.max_depth enforce_size(source) @source = source.dup.force_encoding(Encoding::BINARY) @budget = Budget.new(limits) @position = 0 @symbols = [] @objects = [] @role_anomalies = [] end |
Instance Method Details
#parse ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/marshalsea/marshal/parser.rb', line 24 def parse read_header root = read_value(1) raise TrailingBytesError, "#{remaining} unread bytes" unless remaining.zero? root.each(&:seal) Result.new(root, major: @major, minor: @minor, role_anomalies: @role_anomalies.freeze).freeze end |