Giter VIP home page Giter VIP logo

Comments (3)

Antikyth avatar Antikyth commented on July 28, 2024

The derive macro for cornflakes::ByteSize will probably be useful reference.

from xrb.

Antikyth avatar Antikyth commented on July 28, 2024

Examples

The code needs to generate the implementation for length() so that can sum the byte sizes, like in this example. The cornflakes::ByteSize trait is how you can get the byte size for any type that is (de)serialized:

pub trait ByteSize {
    fn byte_size(&self) -> usize;
}

And here is an actual example of one of the tests written to ensure that this is implemented correctly:

#[test]
fn reparent_window_length_is_correct() {
    // header (total: 4 bytes):
    // - major opcode (the request's "ID"): u8, 1 byte
    // - empty (for this request)
    // - length of the request: u16, 2 bytes (that's what we're calculating)
    let reparent_window = ReparentWindow {
        target: Window::new(0), // 4 bytes (`u32` wrapper)
        new_parent: Window::new(0), // 4 bytes (`u32` wrapper)
        new_x: 0, // 2 bytes (`u16`)
        new_y: 0, // 2 bytes (`u16`)
    };

    // total is 4 + 4 + 2 + 2 + (header: 4) = 16

    // length of a message is in multiples of 4 bytes, so the length should be 16 / 4 = 4
    assert_eq!(reparent_window.length(), 4);
}

from xrb.

Antikyth avatar Antikyth commented on July 28, 2024

This is complete.

from xrb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.