如何使用perl库解码cbor编码的十六进制字符串?

问题描述 投票:0回答:1

84A81A3000000318801A1000000218201A700001F7011A70000007011A600002BD1B00000189DB192D791A2000000141001A2000000441021A200000 06410140A040 上面是我的 cbor 编码的十六进制字符串。

使用 CBOR::XS 解码时,我希望输出如下所示

[{805306371: 128, 268435458: 32, 1879048695: 1, 1879048199: 1, 1610613437: 1691598007673, 536870913: h'00', 536870916: h '02', 536870918: h'01'}, h'', { }, h'']

但是我收到一个错误 CBOR 对象之后的垃圾,位于 new.pl 第 6 行的偏移量 2(八位字节 0x41)处。

use CBOR::XS;
# Replace this with your CBOR-encoded hex data
my $hex_data = "84A81A3000000318801A1000000218201A700001F7011A70000007011A600002BD1B00000189DB192D791A2000000141001A2000000441021A20000006410140A040";

# Decode CBOR data
my $decoded_data = CBOR::XS::decode_cbor($hex_data);
# Manually format the decoded data
use Data::Dumper;

print Dumper($decoded_data);

请帮忙

84A81A3000000318801A1000000218201A700001F7011A70000007011A600002BD1B00000189DB192D791A2000000141001A2000000441021A200000 06410140A040 上面是我的 cbor 编码的十六进制字符串。

使用 CBOR::XS 解码时,我希望输出如下所示

[{805306371: 128, 268435458: 32, 1879048695: 1, 1879048199: 1, 1610613437: 1691598007673, 536870913: h'00', 536870916: h '02', 536870918: h'01'}, h'', { }, h'']

但是我收到一个错误 CBOR 对象之后的垃圾,位于 new.pl 第 6 行的偏移量 2(八位字节 0x41)处。

use CBOR::XS;
# Replace this with your CBOR-encoded hex data
my $hex_data = "84A81A3000000318801A1000000218201A700001F7011A70000007011A600002BD1B00000189DB192D791A2000000141001A2000000441021A20000006410140A040";

# Decode CBOR data
my $decoded_data = CBOR::XS::decode_cbor($hex_data);
# Manually format the decoded data
use Data::Dumper;

print Dumper($decoded_data);

请帮忙

84 # 数组(4) A8#地图(8) 1A 30000003 # 无符号(805306371) 18 80 # 无符号(128) 1A 10000002 # 无符号(268435458) 18 20 # 无符号(32) 1A 700001F7 # 无符号(1879048695) 01 # 无符号(1) 1A 70000007 # 无符号(1879048199) 01 # 无符号(1) 1A 600002BD # 无符号(1610613437) 1B 00000189DB192D79 # 无符号(1691598007673) 1A 20000001 # 无符号(536870913) 41 # 字节(1) 00 #“\u0000” 1A 20000004 # 无符号(536870916) 41 # 字节(1) 02#“\u0002” 1A 20000006 # 无符号(536870918) 41 # 字节(1) 01#“\u0001” 40 # 字节(0) #“” A0 # 地图(0) 40 # 字节(0) #“” 这里它无法解析 41 个标签

perl decoding cbor
1个回答
0
投票

子进程不需要字节的十六进制表示,而是字节本身。

my $data = pack "H*", $hex_data;
© www.soinside.com 2019 - 2024. All rights reserved.