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

Feature request: encode/decode from fixed size arrays #210

Closed
antonilol opened this issue Aug 16, 2024 · 1 comment
Closed

Feature request: encode/decode from fixed size arrays #210

antonilol opened this issue Aug 16, 2024 · 1 comment

Comments

@antonilol
Copy link

antonilol commented Aug 16, 2024

It would be useful to have functions that convert between [u8; N] and number primitive types, where N is the size in bytes of that number type.

Public api example:

pub trait ByteOrder: // ...
{
    // ...

    fn encode_u16(n: u16) -> [u8; 2];
    fn encode_i64(n: i64) -> [u8; 8];
    fn decode_f32(buf: [u8; 4]) -> f32;
    // etc
}

These can be directly implemented with from_le_bytes or from_be_bytes from the standard library.

The names of the functions can be different than I suggest here, decode_f32(buf: [u8; 4]) -> f32 is very close to fn read_f32(buf: &[u8]) -> f32, the only real difference is that the size of the input buffer is fixed.

@antonilol
Copy link
Author

just found out this is a duplicate of #163 and #96 (closed because rust was in a too early stage?)

@antonilol antonilol closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2024
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

1 participant