Sender | Message | Time |
---|---|---|
29 Jan 2024 | ||
alice | hey! i'm wondering if there's a convenient way to have an Option<SomeT> in my #[binrw] struct that acts like a normal enum instead of optionally writing a value. e.g. have some magic byte to indicate the presence of a value and then either the value or all zeroes | 04:04:45 |
snover | I’m having a little trouble understanding the request | 04:09:27 |
snover | you want the write-implementation to emit zeros for None ? | 04:10:03 |
alice | yes! and ofc one that then also reads back to None when the binary is all zeroes | 04:10:40 |
alice | and i'm totally okay with having an extra byte to mark which variant it is, i'm not too concerned about size | 04:11:04 |
alice | i tried making my own Option-esque wrapper but running into some really weird type issues... :/
(along with an but when i try to use it the type checker isn't happy. even just doing
| 04:11:07 |
alice | basically, i want to be able to (de)serialise Option<T> to a fixed length binary | 04:12:40 |
snover | to derive this way you will at least need to #[br(import_raw(args: <T as BinRead>::Args<'_>>)) and similar for binwrite and forward them to T , though i am not sure if this will solve complaint from the compiler | 04:17:29 |
alice | would it be too much to ask why? i'm honestly still very hazy on the wot Args stuff works | 04:19:32 |
alice | hm, doesn't fix it though | 04:21:43 |
snover |
| 04:22:02 |
snover | the reason why is that T has arguments to parse or write T , so if you are going to encapsulate T , then you need to be able to provide the arguments to parse or write T to T | 04:23:05 |
alice | oh! that seems to work! | 04:24:00 |
alice | In reply to @snover:matrix.orgah ofc! that makes sense ^^ | 04:24:13 |
alice | ahhh, this actually works! thank you so much ^^ been banging my head against this for a while | 04:35:18 |
snover | of course! i’m glad you are finding binrw useful. | 04:36:38 |
alice | it's been wonderful! i'm a sucker for terse code and not having duplicated models and binrw has really delivered | 04:37:35 |
6 Feb 2024 | ||
ckrenslehner joined the room. | 07:48:19 | |
ckrenslehner | Hello! I want to use binrw as static library within a armv7 embedded project which is setup in C and CMake. I know that there is a global allocator and everything, but I wanted to explore the idea of using binrw in this no_std context and how I could approach things. The struct:
Thank you! | 10:21:07 |
ckrenslehner | * Hello! I want to use binrw as static library within a armv7 embedded project which is setup in C and CMake. I know that there is a global allocator and everything, but I wanted to explore the idea of using binrw in this no_std context and how I could approach things. The struct:
Thank you! | 10:21:26 |
ckrenslehner | * Hello! I want to use binrw as static library within a armv7 embedded project which is setup in C and CMake. I know that there is a global allocator and everything, but I wanted to explore the idea of using binrw in this no_std context and how I could approach things. The struct:
Thank you! | 10:21:50 |
snover | ckrenslehner: binrw reads and writes data from streams, so you would not be storing a slice, since the expectation is that the stream is copied from rather than borrowed from, as it is not possible to borrow from e.g. a network stream, file, etc. | 16:54:44 |
9 Feb 2024 | ||
ckrenslehner | snover: thank you for your response and sry for the late reply. Ok I understand. The whole file is already saved within the RAM of the C code of my embedded project. So maybe I can get this running via implementing BinRead in some way. :-) | 09:28:07 |
ckrenslehner | * snover: thank you for your response and sry for the late reply. Ok I understand. The whole file is already saved within the RAM of the C code of my embedded project. So maybe I can get this running via implementing BinRead and some FFI in some way. :-) | 09:31:09 |
badrb set a profile picture. | 09:59:29 | |
snover | ckrenslehner: if you don’t plan on ever reading data from anywhere other than memory, and you don’t need anything beyond than a way to represent the memory as a struct, you may just want to use something like zerocopy instead, which will be faster | 16:10:16 |
14 Feb 2024 | ||
rgnb | Hello, I am trying to read a struct of various data and a XOR-32 checksum of all the bytes prior at the end. What is the best way to implement verifying this checksum? | 04:51:13 |
rgnb | https://docs.rs/binrw/latest/binrw/docs/attribute/index.html#verifying-a-checksum | 04:54:44 |
rgnb | found an example :) | 04:54:53 |
17 Mar 2024 | ||
BKSalman joined the room. | 16:12:14 |