Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for binary encoding #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions decode/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions decode/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}