Skip to content

Conversation

@mcr
Copy link

@mcr mcr commented Apr 4, 2022

Given a rust debug {:x?} dump like:

voucher: [d2, 84, 43, a1, 1, 26, a0, 58, 2a, a1, 19, 9, c5, a3, 1, 69, 70, 72, 6f, 78, 69, 6d, 69, 74, 79, 2, c1, 1a, 5f, 50, 1d, d2, d, 71, 30, 30, 2d, 44, 30, 2d, 45, 35, 2d, 46, 32, 2d, 30, 30, 2d, 30, 32, 40]

I want to examine it with pretty2diag.rb. I remove the , from the output, since that's not accepted, but get complaints about it being too short. After some head scratching, I realize that the single hex digits are the problem:

d2 84 43 a1 01 26 a0 58 2a a1 19 09 c5 a3 01 69 70 72 6f 78 69 6d 69 74 79 02 c1 1a 5f 50 1d d2 0d 71 30 30 2d 44 30 2d 45 35 2d 46 32 2d 30 30 2d 30 32 40

and this works.

Looking at pretty2diag.rb, I see that it insists on every byte having two digits. Well... that is good if there are no spaces.
After thinking about this for a bit, I think that if we accept space as being the second digit, then it works out right, but I don't have enough test data to be sure about this.

@mcr mcr marked this pull request as draft April 4, 2022 21:56
@cabo
Copy link
Owner

cabo commented Apr 6, 2022

Mixing two-character undelimited and single-char delimited sounds a bit dangerous.
I think I'd rather add a separate tool that does the middle part of

$ pbpaste | ruby -e "print ARGF.read.scan(/[0-9a-f]+/).map { _1.to_i(16).chr(Encoding::BINARY)}.join" | cbor2diag.rb -e
18([<< {1: -7} >>, {}, << {2501: {1: "proximity", 2: 1(1599086034), 13: "00-D0-E5-F2-00-02"}} >>, h''])

(I copied your array so I could pbpaste it into the pipeline.)

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