-
Notifications
You must be signed in to change notification settings - Fork 4
/
scalars_with_different_size_builder.rs
59 lines (52 loc) · 1.92 KB
/
scalars_with_different_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 Account {
pub year: u32,
pub balance: u64,
}
impl Account {
const VT_YEAR: usize = 4;
const SIZE_YEAR: usize = 4;
const ALIGNMENT_YEAR: usize = 4;
const VT_BALANCE: usize = 6;
const SIZE_BALANCE: usize = 8;
const ALIGNMENT_BALANCE: usize = 8;
const ALIGNMENT: usize = 8;
}
impl<'c> Component<'c> for Account {
fn build(self: Box<Self>, builder: &mut Builder<'c>) -> usize {
let vtable_start = {
let mut vtable = builder.start_vtable();
if self.balance != 0u64 {
vtable.add_field(Self::VT_BALANCE, Self::SIZE_BALANCE, Self::ALIGNMENT_BALANCE);
}
if self.year != 0u32 {
vtable.add_field(Self::VT_YEAR, Self::SIZE_YEAR, Self::ALIGNMENT_YEAR);
}
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.balance != 0u64 {
builder.align(Self::ALIGNMENT_BALANCE);
builder.push_scalar(self.balance);
}
if self.year != 0u32 {
builder.align(Self::ALIGNMENT_YEAR);
builder.push_scalar(self.year);
}
table_start
}
}
}