!homDUJhmxHaZNgyLVA:matrix.org

binrw

162 Members
Official Matrix channel for the binread & binrw Rust libraries. Bridged to Discord. https://github.com/jam1garner/binrw/12 Servers

Load older messages


SenderMessageTime
29 Jan 2024
@snover:matrix.orgsnover 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
@alavie:matrix.orgalicewould it be too much to ask why? i'm honestly still very hazy on the wot Args stuff works04:19:32
@alavie:matrix.orgalicehm, doesn't fix it though04:21:43
@snover:matrix.orgsnover
#[binrw]
#[br(import_raw(r: <T as BinRead>::Args<'_>))]
#[bw(import_raw(r: <T as BinWrite>::Args<'_>))]
enum RWOption<T>
where
    T: BinWrite + BinRead,
{
    #[brw(magic = 0xffu8)]
    Some(#[br(args_raw = r)] #[bw(args_raw = r)] T),
    #[brw(magic = 0x00u8)]
    None,
}
04:22:02
@snover:matrix.orgsnover 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
@alavie:matrix.orgaliceoh! that seems to work!04:24:00
@alavie:matrix.orgalice
In reply to @snover:matrix.org
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
ah ofc! that makes sense ^^
04:24:13
@alavie:matrix.orgaliceahhh, this actually works! thank you so much ^^ been banging my head against this for a while04:35:18
@snover:matrix.orgsnoverof course! i’m glad you are finding binrw useful.04:36:38
@alavie:matrix.orgaliceit's been wonderful! i'm a sucker for terse code and not having duplicated models and binrw has really delivered04:37:35
6 Feb 2024
@krensito:matrix.orgckrenslehner joined the room.07:48:19
@krensito:matrix.orgckrenslehner

Hello!
I am trying to parse a struct containing a slice.
I am using the deku crate right now. However, I want to dig into binrw more and I wonder how you would convert this struct in the intended way. I searched this channel and found something about a Cursor, but still I am a bit confused.

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:

#[derive(Debug, PartialEq, DekuRead)]
struct Test<'a> {
    pub size: u8,
    pub id: u16,
    #[deku(count = "*size - 2")]
    pub value: &'a [u8],
}

Thank you!
Cheers, Christian

10:21:07
@krensito:matrix.orgckrenslehner *

Hello!
I am trying to parse a struct containing a slice.
I am using the deku crate right now. However, I want to dig into binrw more and I wonder how you would convert this struct in the intended way. I searched this channel and found something about a Cursor, but still I am a bit confused.

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:

#[derive(Debug, PartialEq, DekuRead)]
struct Test<'a> {
    pub size: u8,
    pub id: u16,
    #[deku(count = "*size - 2")]
    pub value: &'a [u8],
}

Thank you!
Cheers, Christian

10:21:26
@krensito:matrix.orgckrenslehner *

Hello!
I am trying to parse a struct containing a slice.
I am using the deku crate right now. However, I want to dig into binrw more and I wonder how you would convert this struct in the intended way. I searched this channel and found something about a Cursor, but still I am a bit confused.

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:

#[derive(Debug, PartialEq, DekuRead)]
struct Test<'a> {
    pub size: u8,
    pub id: u16,
    #[deku(count = "*size - 2")]
    pub value: &'a [u8],
}

Thank you!
Cheers, Christian

10:21:50
@snover:matrix.orgsnover 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
@krensito:matrix.orgckrenslehner 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
@krensito:matrix.orgckrenslehner * 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:matrix.orgbadrb set a profile picture.09:59:29
@snover:matrix.orgsnover 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:matrix.orgrgnbHello, 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:matrix.orgrgnbhttps://docs.rs/binrw/latest/binrw/docs/attribute/index.html#verifying-a-checksum04:54:44
@rgnb:matrix.orgrgnbfound an example :) 04:54:53
17 Mar 2024
@bksalman:matrix.orgBKSalman joined the room.16:12:14
1 Apr 2024
@artemis21:matrix.orgAMV changed their display name from Artemis to AMV.14:51:29
14 Apr 2024
@vhdirk:matrix.orgDirk Van Haerenborgh joined the room.10:47:37
16 Apr 2024
@vhdirk:matrix.orgDirk Van HaerenborghHi! Are there any plans to have a tighter integration for working with bitfields?11:36:08
@vhdirk:matrix.orgDirk Van HaerenborghI'm currently using deku in https://crates.io/crates/dash, but from reading the docs, I think binrw could make the api a lot more ergonomic11:38:14
@vhdirk:matrix.orgDirk Van Haerenborghyet my first attempts to combine binrw with modular_bitfield immediately yielded some errors (I have to look at it again); basically I couldn't get it to work11:40:07
@snover:matrix.orgsnover Dirk Van Haerenborgh: There is an example in the documentation of using this crate, what is not working for you? 15:40:13
@vhdirk:matrix.orgDirk Van HaerenborghThe example is for structs. I was trying to use bitfieldspecifier for an enum15:44:06

Show newer messages


Back to Room ListRoom Version: 6