use_cbor_discriminator: now works with imbricated classes.
parent
a058ab3ccf
commit
bdc14a1d20
|
@ -2,9 +2,17 @@ class CBOR::Decoder
|
|||
@lexer : Lexer
|
||||
getter current_token : Token::T?
|
||||
|
||||
def reset
|
||||
# Decode until a certain point in the history (use_cbor_discriminator helper).
|
||||
def reset(value : Int32 | Int64 = 0)
|
||||
@lexer.reset
|
||||
@current_token = @lexer.next_token
|
||||
while pos < value
|
||||
@current_token = @lexer.next_token
|
||||
end
|
||||
end
|
||||
|
||||
# Give the current position in the decoder (use_cbor_discriminator helper).
|
||||
def pos
|
||||
@lexer.io.pos
|
||||
end
|
||||
|
||||
def initialize(input)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class CBOR::Lexer
|
||||
property io : IO
|
||||
def self.new(slice : Bytes)
|
||||
new IO::Memory.new(slice)
|
||||
end
|
||||
|
@ -8,8 +9,8 @@ class CBOR::Lexer
|
|||
def initialize(@io : IO)
|
||||
end
|
||||
|
||||
def reset
|
||||
@io.seek 0
|
||||
def reset(value : Int32 | Int64 = 0)
|
||||
@io.seek value
|
||||
@eof = false
|
||||
end
|
||||
|
||||
|
|
|
@ -353,8 +353,9 @@ module CBOR
|
|||
|
||||
# SLOW. Read everything, get the type, read everything again.
|
||||
def self.new(decoder : ::CBOR::Decoder)
|
||||
current_offset = decoder.pos
|
||||
if v = decoder.read_value
|
||||
decoder.reset
|
||||
decoder.reset current_offset
|
||||
case v
|
||||
when Hash(CBOR::Type, CBOR::Type)
|
||||
discriminator_value = v[{{field.id.stringify}}]?
|
||||
|
|
Loading…
Reference in New Issue