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

A way to store a byte array #37

Open
rubend056 opened this issue Mar 28, 2024 · 3 comments
Open

A way to store a byte array #37

rubend056 opened this issue Mar 28, 2024 · 3 comments

Comments

@rubend056
Copy link

rubend056 commented Mar 28, 2024

Is there a way to store a byte array of a specific size?

I'm asking because I wanted to implement the ToRecord trait for my own struct Limb:

impl ToRecord for &Limb {
	fn store(&self, buf: &mut std::vec::Vec<u8>) {
		buf.write(&postcard::to_vec::<_, 32>(self).unwrap()).unwrap();
	}
	fn format_char(&self) -> u8 {
		b'L'
	}
	fn size(&self) -> usize {
		32
	}
	fn variable_size(&self) -> bool {
		false
	}
}

but I got a panic on row_format.rs on line 151:
panic!("invalid format character '{}'", a);

There seems to be more to extending the formats stored than just implementing ToRecord/FromRecord. Is there an easier way to do this? Or should I just use 's' with base64 encoding?

@njaard
Copy link
Owner

njaard commented Apr 5, 2024

Sorry about my delay in responding.

The code in row_format.rs is necessary for receiving information from command-line tools.

Anyway, I've added this feature in the byte-arrays branch

Let me know if that works for you and I will merge it.

@rubend056
Copy link
Author

Wow thank you for the work you put into this :)

Since then I've been using 's' with a base64 encoding, it seems you're doing the same but with a different format_char 'B'.

Would your implementation have any performance/size benefits over just using 's' with base64?

@njaard
Copy link
Owner

njaard commented May 3, 2024

I conducted an experiment to see if compressing a base64 string with LZ4 results in the same size as compressing the same data when represented in binary, and it's about 30% more.

So, yes, there's a size benefit of not using base64, and converting to base64 probably has cost as well.

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