Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

Derive macros for reading and writing #5

Closed
Antikyth opened this issue Sep 8, 2022 · 2 comments
Closed

Derive macros for reading and writing #5

Antikyth opened this issue Sep 8, 2022 · 2 comments
Assignees
Labels
help wanted Extra attention is needed task An essential task for a planned milestone.

Comments

@Antikyth
Copy link
Collaborator

Antikyth commented Sep 8, 2022

A.k.a. serialize and deserialize traits. Might want to do #3 first?

@Antikyth Antikyth self-assigned this Sep 8, 2022
@Antikyth Antikyth added this to the 0.1.0 milestone Sep 8, 2022
@Antikyth
Copy link
Collaborator Author

This is code that can derive implementations of cornflakes::Readable and cornflakes::Writable.

Examples

#[derive(Readable, Writable)]
pub struct CharInfo {
    pub left_side_bearing: i16,
    pub right_side_bearing: i16,
    pub character_width: i16,
    pub ascent: i16,
    pub descent: i16,
    pub attributes: u16,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut buffer1: Vec<u8> = vec![];

    let char_info = CharInfo {
        left_side_bearing: 0,
        right_side_bearing: 0,
        character_width: 10,
        ascent: 0,
        descent: 0,
        attributes: 0,
    };

    buffer1.write(char_info)?;

    let mut buffer2: Vec<u8> = vec![];

    buffer2.write_i16(0)?;
    buffer2.write_i16(0)?;
    buffer2.write_i16(10)?;
    buffer2.write_i16(0)?;
    buffer2.write_i16(0)?;
    buffer2.write_u16(0)?;

    assert_eq!(buffer1, buffer2);
}

@Antikyth
Copy link
Collaborator Author

Antikyth commented Jan 1, 2023

Completed in #31

@Antikyth Antikyth closed this as completed Jan 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed task An essential task for a planned milestone.
Projects
None yet
Development

No branches or pull requests

1 participant