Skip to content

No way to (de)serialize a String from binary data? #187

Closed Answered by csnover
AbstractUmbra asked this question in Q&A
Discussion options

You must be logged in to vote

String has no default implementation because there is no obvious canonical representation of string data like there is for most other primitive types. Strings may be null-terminated, dollar-sign-terminated, length-prefixed (Pascal), fixed-length space-padded, fixed-length null-padded, length-prefixed and null-terminated, delimited with quotes, in a big block with a separate lookup table, etc. The encoding could be UTF-8, WTF-8, UTF-16, Win-1252, MacRoman, ISO-8859, Shift-JIS, EBCDIC, etc.

If you have a fixed-length array containing string data you know is ASCII or UTF-8 then you can do basically what you are now, or you can do something like #[br(try_map = |data: [u8; 16]| str::from_utf8(…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by AbstractUmbra
Comment options

You must be logged in to vote
2 replies
@csnover
Comment options

csnover Mar 15, 2023
Collaborator

@AbstractUmbra
Comment options

Comment options

You must be logged in to vote
2 replies
@csnover
Comment options

csnover Mar 20, 2023
Collaborator

@scarletcafe
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #186 on March 15, 2023 05:05.