Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force pack as binary #86

Open
adrianroe opened this issue Dec 3, 2019 · 2 comments
Open

Force pack as binary #86

adrianroe opened this issue Dec 3, 2019 · 2 comments

Comments

@adrianroe
Copy link

adrianroe commented Dec 3, 2019

I'm trying to pack the following data structure.

#{<<"Coalesce">> => true,
  <<"Name">> => <<"streamAvailable">>,
  <<"Payload">> =>
      term_to_binary({streamAvailable,{streamId,<<"stream1">>},<<"172.16.169.1">>})
}.

In a perfect world I would use '{pack_str, from_binary}' but it then tries to pack Payload as a string and fails on the 'unicode:characters_to_binary' check. Is there a way to force Payload to be encoded as a binary while allowing the others to remain strings?

Thanks for the efforts on a great library!

@iAchilles
Copy link

@adrianroe Hi, did you resolve this issue?

@bwegh
Copy link

bwegh commented Jan 11, 2025

For anyone running into this issue:
you can mark specific binaries as string using the undocumented {pack_str, from_tagged_list}

Data = #{{string, <<"Coalesce">>} => true,
  {string, <<"Name">>} => {string, <<"streamAvailable">>},
  {string, <<"Payload">>} =>
      term_to_binary({streamAvailable,{streamId,<<"stream1">>},<<"172.16.169.1">>})
},                
mspack.pack(Data,[{pack_str, from_tagged_list}].

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

No branches or pull requests

3 participants