简介
我正在尝试解码十六进制数据,但似乎出现了一个错误,就像results中显示的奇怪数据一样。
这是真的吗?
因为如果您查看十六进制编辑器,它看起来与不同的
目标
目标是能够正确地解码和重新编码。
图书馆
解码器
const encoded = '646563376466306366356337666138333036626432383062646634666161393794000000840000008E06EA623666613634613632376334616237613300000000000000000000000000000000000000000000000001000000E6969800312E383500000000C80200000000000028151517313635663738333737353635383163310000000000000000000000000000000002000000366B17186566373463346331393162343939663661653865373863643038366532393763'
let result = []
const decode = ByteBufferJS.fromHex(encoded, ByteBufferJS.LITTLE_ENDIAN)
result.push(decode.readString(32)) // signature
result.push(decode.readLong().toInt())
result.push(decode.readInt()) // timestamp
result.push(decode.readString(16)) // mac
result.push(decode.readString(24)) // unknown
result.push(decode.readInt()) // platform
result.push(decode.readInt()) // agent_id
result.push(decode.readString(4)) // version
result.push(decode.readInt()) // unknown
result.push(decode.readInt()) // unknown
result.push(decode.readInt()) // unknown
result.push(decode.readInt()) // user_id
result.push(decode.readString(16)) // token
result.push(decode.readString(16)) // mac
result.push(decode.readInt()) // unknown
result.push(decode.readInt()) // user_destination
result.push(decode.readString(32)) // unknown
console.log(result)结果
[
'dec7df0cf5c7fa8306bd280bdf4faa97',
148,
1659504270,
'6fa64a627c4ab7a3',
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
1,
10000102,
'1.85',
0,
712,
0,
387257640,
'165f7837756581c1',
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
2,
404187958,
'ef74c4c191b499f6ae8e78cd086e297c'
]六角编辑器
发布于 2022-08-03 10:49:48
看上去:
result.push(decode.readString(32)) // signature给予:
[
'dec7df0cf5c7fa8306bd280bdf4faa97',
// ...
]它是该十六进制编码数据的ASCII表示形式的前32个字符。
查看您正在使用的库的API,即- https://github.com/protobufjs/bytebuffer.js/wiki/API#bytebufferreadstringlength-metrics-offset -我可以看到这32个引用了要从缓冲区中提取的字符数,这正是它所做的,而且是正确的。
这里没有问题..。
https://stackoverflow.com/questions/73220161
复制相似问题