Skip to content

flutter解析二进制消息 #3

@liang199966

Description

@liang199966

tlv2String(tlvBuffer: ArrayBufferLike) {
const typeBuffer = new Uint8Array(tlvBuffer, 0, 4);
const lengthBuffer = new Uint8Array(tlvBuffer, 4, 4);
const valueBuffer = new Uint8Array(tlvBuffer, 8);

let type = '';
for (let i = 0; i < typeBuffer.length; i++) {
  type += String.fromCharCode(typeBuffer[i]);
}

const length =
  (lengthBuffer[0] << 24) | (lengthBuffer[1] << 16) | (lengthBuffer[2] << 8) | lengthBuffer[3];

const value = new TextDecoder().decode(valueBuffer.subarray(0, length));

return { type, value };

}转为flutter代码解析为啥会越界 flutter解析二进制消息数据没有代码提供吗?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions