From 9a7ec44b66adfc6064e4ee11c75bc1c5fa73d1f6 Mon Sep 17 00:00:00 2001 From: Alberto Restifo Date: Sun, 19 Apr 2020 13:45:07 +0200 Subject: [PATCH] Fix bytes decoding --- spec/cbor/lexer_spec.cr | 4 ++-- src/cbor/lexer.cr | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/cbor/lexer_spec.cr b/spec/cbor/lexer_spec.cr index cd42687..5772685 100644 --- a/spec/cbor/lexer_spec.cr +++ b/spec/cbor/lexer_spec.cr @@ -56,8 +56,8 @@ describe CBOR::Lexer do # { %(23(h'01020304')), "d7 44 01 02 03 04"}, # { %(24(h'6449455446')), "d8 18 45 64 49 45 54 46"}, # { %(32("http://www.example.com")), "d8 20 76 68 74 74 70 3a 2f 2f 77 77 77 2e 65 78 61 6d 70 6c 65 2e 63 6f 6d" }, - # { %(h''), "40" }, - # { %(h'01020304'), "44 01 02 03 04" }, + { %(h''), "40" }, + { %(h'01020304'), "44 01 02 03 04" }, # { %(""), "60" }, # { %("a"), "61 61" }, # { %("IETF"), "64 49 45 54 46" }, diff --git a/src/cbor/lexer.cr b/src/cbor/lexer.cr index ebd480b..f182910 100644 --- a/src/cbor/lexer.cr +++ b/src/cbor/lexer.cr @@ -71,8 +71,8 @@ class CBOR::Lexer when 0x3b consume_int(to_negative_int(read(UInt64))) when 0x40..0x57 - # Reads a single byte which is offset by 0x40 - Token::BytesT.new(@current_byte_number, value: Bytes[current_byte - 0x40]) + # read current_byte - 0x40 bytes ahead + consume_binary(current_byte - 0x40) when 0x58 consume_binary(read(UInt8)) when 0x59