Skip to content

Support for encoding/decoding bytes #9

Merged
emmanuelm41 merged 8 commits intomasterfrom
feature/support-bytes
Jun 24, 2022
Merged

Support for encoding/decoding bytes #9
emmanuelm41 merged 8 commits intomasterfrom
feature/support-bytes

Conversation

@rllola
Copy link
Copy Markdown
Contributor

@rllola rllola commented Jun 23, 2022

  • Encode bytes
  • Encode tests for bytes
  • Decode bytes
  • Decode test bytes

🔗 zboto Link

Comment thread assembly/encoder.ts Outdated
@rllola rllola requested a review from emmanuelm41 June 23, 2022 16:35
Libraries should not have a lock file
Comment thread assembly/decoder.ts
Comment on lines 209 to 241
case 3:
// https://github.com/AssemblyScript/assemblyscript/issues/1609
const utf16data: i32[] = [];
let data: Uint8Array = new Uint8Array(0);
if (length < 0) {
while ((length = this.readIndefiniteStringLength(majorType)) >= 0)
this.appendUtf16Data(utf16data, length);
} else{
this.appendUtf16Data(utf16data, length);
while ((length = this.readIndefiniteStringLength(majorType)) >= 0) {
let tmp = new Uint8Array((data.byteLength+length) as u32)
tmp.set(data)
tmp.set(this.readArrayBuffer(length as u32), data.byteLength)
data = tmp
}
} else {
let tmp = new Uint8Array(length as u32)
tmp.set(this.readArrayBuffer(length as u32))
data = tmp
}

if(this.handler.stack.length > 0){
if (this.handler.peek.isObj) {
if (this.lastKey == "") {
this.lastKey = String.fromCharCodes(utf16data)
this.lastKey = String.UTF8.decode(data.buffer)
} else {
this.handler.setString(this.lastKey, String.fromCharCodes(utf16data))
this.handler.setString(this.lastKey, String.UTF8.decode(data.buffer))
this.lastKey = ""
}
}
if(this.handler.peek.isArr){
this.handler.setString(this.lastKey, String.fromCharCodes(utf16data))
this.handler.setString(this.lastKey, String.UTF8.decode(data.buffer))
this.lastKey = ""
}
}
else
this.handler.setString("", String.fromCharCodes(utf16data))
this.handler.setString("", String.UTF8.decode(data.buffer))

return
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that we loose utf16 support with this implementation?

Copy link
Copy Markdown
Member

@emmanuelm41 emmanuelm41 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice features added! Great work :D

@emmanuelm41 emmanuelm41 merged commit c2a6277 into master Jun 24, 2022
@emmanuelm41 emmanuelm41 deleted the feature/support-bytes branch June 24, 2022 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants