-
Notifications
You must be signed in to change notification settings - Fork 4
/
scalars_with_same_size_builder.rs
59 lines (52 loc) · 1.82 KB
/
scalars_with_same_size_builder.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! This file is auto-generated by cfbc.
pub mod example {
#![allow(unused_imports, clippy::large_enum_variant)]
use cfb::builder::{
Builder, Component, DesignatedComponent, NestedBufferComponent, ReferenceVectorComponent,
ScalarVectorComponent, StringComponent,
};
use cfb::scalar::Scalar;
use cfb::types::{SOffset, SIZE_OF_SOFFSET};
#[cfg(not(target_endian = "little"))]
use std::mem::transmute;
#[derive(Default, Clone, Debug, PartialEq)]
pub struct Point {
pub x: u64,
pub y: u64,
}
impl Point {
const VT_X: usize = 4;
const SIZE_X: usize = 8;
const ALIGNMENT_X: usize = 8;
const VT_Y: usize = 6;
const SIZE_Y: usize = 8;
const ALIGNMENT_Y: usize = 8;
const ALIGNMENT: usize = 8;
}
impl<'c> Component<'c> for Point {
fn build(self: Box<Self>, builder: &mut Builder<'c>) -> usize {
let vtable_start = {
let mut vtable = builder.start_vtable();
if self.x != 0u64 {
vtable.add_field(Self::VT_X, Self::SIZE_X, Self::ALIGNMENT_X);
}
if self.y != 0u64 {
vtable.add_field(Self::VT_Y, Self::SIZE_Y, Self::ALIGNMENT_Y);
}
vtable.finish()
};
builder.align_after(SIZE_OF_SOFFSET, Self::ALIGNMENT);
let table_start = builder.tell();
builder.push_scalar((table_start - vtable_start) as SOffset);
if self.x != 0u64 {
builder.align(Self::ALIGNMENT_X);
builder.push_scalar(self.x);
}
if self.y != 0u64 {
builder.align(Self::ALIGNMENT_Y);
builder.push_scalar(self.y);
}
table_start
}
}
}