Comments (3)
The derive macro for cornflakes::ByteSize
will probably be useful reference.
from xrb.
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.
This is complete.
from xrb.
Related Issues (20)
- Provide default implementation of `length()` in message traits HOT 1
- XRBK macro: conditionally enable parsing based on given derive traits
- Some structs in the connection module have private fields
- XRBK macro: design and implement syntax for Request errors
- Doc examples for `{Request, Reply}::length` fail
- Implement `ConfigureWindow` mask and values as a set
- Implement `GraphicsContext` mask and values as a set HOT 1
- Implement keyboard control mask and values as a set
- Document sets HOT 1
- Remove old, replaced masks HOT 1
- Fix the `x11_size` used in sets
- XRBK: use generics in errors instead of requiring casting
- Use types for each kind of unit
- Rename `Color` to `ColorId`
- Add aliases for all types for their X11 protocol names
- Make sets work in `const` contexts
- Use explicit unused bytes instead of inferred for most padding
- XRBK macro: restructure around a mode system
- XRBK macro: rewrite with `chumsky` crate
- Dynamically assign major opcodes for extensions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xrb.