smessmer / binary-layout

The binary-layout library allows type-safe, inplace, zero-copy access to structured binary data. You define a custom data layout and give it a slice of binary data, and it will allow you to read and write the fields defined in the layout from the binary data without having to copy any of the data. It's similar to transmuting to/from a #[repr(packed)] struct, but much safer.
Apache License 2.0
66 stars 9 forks source link

f32/f64 support? #6

Closed ckaran closed 2 years ago

ckaran commented 2 years ago

I'm not sure if this is truly possible, but have you considered support for f32 and f64? I know that IEEE 754 is supposed to be a standard, but I don't know for certain that every bit pattern is fully specified within the standard, which is why I'm hesitant suggesting using the builtin conversion methods; the bit patterns might not transfer across platforms the way that integers will.

smessmer commented 2 years ago

f64::to_be_bytes seems to use f64::to_bits internally and that has some comments on portability: https://doc.rust-lang.org/std/primitive.f64.html#method.from_bits

I think this sounds ok so if you create a PR, I'll merge it. We should probably add some documentation for the portability concerns though.

ckaran commented 2 years ago

OK, thank you. Work has suddenly gotten hot again, so it may be a while before I'm able to get to this. If you get to it before I do, then thank you! If not, whenever I have time again, I'll submit another PR.

smessmer commented 2 years ago

ok no worries, I released version 2.1.0 with your i128/u128 changes in the meantime.

ckaran commented 2 years ago

8 seems to be working (modulo rustfmt).