-
Notifications
You must be signed in to change notification settings - Fork 4
/
string_builder.rs
53 lines (46 loc) · 1.7 KB
/
string_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
//! 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 Author {
pub name: String,
}
impl Author {
const VT_NAME: usize = 4;
const SIZE_NAME: usize = 4;
const ALIGNMENT_NAME: usize = 4;
const ALIGNMENT: usize = 4;
}
impl<'c> Component<'c> for Author {
fn build(self: Box<Self>, builder: &mut Builder<'c>) -> usize {
let vtable_start = {
let mut vtable = builder.start_vtable();
if !self.name.is_empty() {
vtable.add_field(Self::VT_NAME, Self::SIZE_NAME, Self::ALIGNMENT_NAME);
}
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.name.is_empty() {
builder.align(Self::ALIGNMENT_NAME);
let offset_position = builder.tell();
builder.pad(Self::SIZE_NAME);
builder.push_component(DesignatedComponent::new(
offset_position,
Box::new(StringComponent::new(self.name))
));
}
table_start
}
}
}