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

Support for binary data defined with the '!!binary' YAML tag #175

Open
LonerDan opened this issue Nov 16, 2021 · 2 comments
Open

Support for binary data defined with the '!!binary' YAML tag #175

LonerDan opened this issue Nov 16, 2021 · 2 comments
Milestone

Comments

@LonerDan
Copy link

Hello,
would it be possible to implement a support for loading data defined using the YAML tag 'binary' defined here? Does the underlying libyaml library handle those tags in any way that can be leveraged in cyaml?
It would be nice to simply define a uint8_t pointer and size_t value in an user structure and have it automatically populated by this library without having to base64 decode it manually.

@tlsa
Copy link
Owner

tlsa commented Nov 16, 2021

That's a good idea, I could make a CYAML_BINARY type that does that.

At the moment, it would load as a string, and you would need to base64 decode manually.

I'll have a bit more of a think about it and get back to you. I want to avoid breaking the ABI if I can.

@tlsa
Copy link
Owner

tlsa commented Nov 16, 2021

Once we have CYAML_BINARY, the YAML !!binary tag becomes redundant.

It would be simple to implement CYAML_BINARY in the same way as CYAML_SEQUENCE is implemented at the moment. However, CYAML_SEQUENCE has the limitation that you can't have a CYAML_SEQUENCE directly inside a CYAML_SEQUENCE. The same restriction would apply here, so a CYAML_BINARY would not be allowed directly inside a CYAML_SEQUENCE.

That means the following would not be possible:

- !!binary "DEADBEEF"
- !!binary "CAFEF00D"

It would to be a sequence of mappings containing the binary data, for example:

- data: !!binary "DEADBEEF"
- data: !!binary "CAFEF00D"

This is because the mapping allows a structure to be used, which allows the data length to be stored in a structure.

So for an array of binaries, the client data structure would need to be something like:

struct binary {
	uint8_t data;
	size_t len;
};

struct my_prog_data {
	struct binary *binary;
	size_t binary_count;
};

@tlsa tlsa added this to the Version 2 milestone May 29, 2023
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

2 participants