From 254367c03490dd1b926160e724ae32d08efdaae4 Mon Sep 17 00:00:00 2001 From: Oleksandr Kushchenko Date: Thu, 14 Dec 2023 02:29:28 +0000 Subject: [PATCH] Add support for binary encoding --- decode/constants.go | 2 ++ decode/decoder.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/decode/constants.go b/decode/constants.go index db5a46e..bb0903e 100644 --- a/decode/constants.go +++ b/decode/constants.go @@ -13,6 +13,8 @@ const SHARED_STRING_REFERENCE_LONG_2 = 0xED const SHARED_STRING_REFERENCE_LONG_3 = 0xEE const SHARED_STRING_REFERENCE_LONG_4 = 0xEF const STRING_END byte = 0xFC +const START_BINARY byte = 0xFD +const END_BINARY byte = 0xFF const EMPTY_STRING byte = 0x20 const NULL byte = 0x21 diff --git a/decode/decoder.go b/decode/decoder.go index 1d7e685..cffda04 100644 --- a/decode/decoder.go +++ b/decode/decoder.go @@ -107,7 +107,22 @@ func (d *Decoder) parseBinaryLongTextStructureValues(smileBytes []byte) ([]byte, return smileBytes[2:], value, err case LONG_UTF8: return readVariableLengthText(smileBytes) + case START_BINARY: + return d.parseBinary(smileBytes[1:]) } return nil, nil, fmt.Errorf("unknown byte '%X' in parseBinaryLongTextStructureValues\n", nextByte) } + +func (d *Decoder) parseBinary(smileBytes []byte) ([]byte, interface{}, error) { + smileBytes, length, err := readVarInt(smileBytes, true) + if err != nil { + return smileBytes, nil, err + } + data := smileBytes[:length*2] + smileBytes = smileBytes[length*2:] + if smileBytes[0] == END_BINARY { + return smileBytes[1:], data, nil + } + return smileBytes, data, nil +}