我通过蓝牙连接了一个脉搏血氧计。在角web蓝牙https://github.com/manekinekko/angular-web-bluetooth之后,我调用value ()方法。我有一个答案:
DataView(7)
buffer: ArrayBuffer(7)
byteLength: 7
[[Prototype]]: ArrayBuffer
[[Int8Array]]: Int8Array(7)
0: 86
1: 84
2: 77
3: 32
4: 50
5: 48
6: 70
buffer:
ArrayBuffer(7)
byteLength: 7
byteOffset: 0
length: 7
Symbol(Symbol.toStringTag): (…)
[[Prototype]]: TypedArray
[[Uint8Array]]: Uint8Array(7)
0: 86
1: 84
2: 77
3: 32
4: 50
5: 48
6: 70
buffer:
ArrayBuffer(7)
byteLength: 7
byteOffset: 0
length: 7
Symbol(Symbol.toStringTag): (…)
[[Prototype]]: TypedArray
[[ArrayBufferByteLength]]: 7
[[ArrayBufferData]]: 144
byteLength: 7
byteOffset: 0如何将ArrayBuffer解码为可读的值格式?
发布于 2021-12-15 18:46:34
您的DataView的底层ArrayBuffer值可以用TypedArrays读取:
new Uint8Array(dataView.buffer).toString()不能直接读取或写入ArrayBuffers。为此使用了一个“视图”接口,例如类型化数组视图或DataView。
const buffer = new ArrayBuffer(5)
const decoder = new TextDecoder()
// Set byte array (8 bits per item) with ASCII number code of character
const bytes = new Uint8Array(buffer)
Array.from('hello').forEach((c, i) => bytes[i] = c.charCodeAt(0))
console.log(bytes.toString(), decoder.decode(buffer))
// Use DataView to set new values
const view = new DataView(buffer)
Array.from('apple').forEach((c, i) => view.setUint8(i, c.charCodeAt(0)))
console.log(bytes.toString(), decoder.decode(buffer))
https://stackoverflow.com/questions/70363290
复制相似问题