Skip to content

Commit 62be68e

Browse files
committed
Generate unpack_with
1 parent 9c14d33 commit 62be68e

File tree

10 files changed

+448
-82
lines changed

10 files changed

+448
-82
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot_flatbuffers"
3-
version = "0.13.2"
3+
version = "0.13.3"
44
edition = "2021"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"

codegen/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl Generator for EnumBindGenerator {
248248
&self.file_contents
249249
}
250250

251-
fn add_get_size_derive(&self, path: &Path) {
251+
fn modify_source(&self, path: &Path) {
252252
let mut contents = fs::read_to_string(path).unwrap();
253253

254254
#[cfg(windows)]

codegen/generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub trait Generator {
66
fn struct_name(&self) -> &str;
77
fn file_contents(&self) -> &Vec<Cow<'static, str>>;
88

9-
fn add_get_size_derive(&self, path: &Path);
9+
fn modify_source(&self, path: &Path);
1010
fn generate_definition(&mut self);
1111
fn generate_from_flat_impls(&mut self);
1212
fn generate_to_flat_impls(&mut self);
@@ -23,7 +23,7 @@ pub trait Generator {
2323
}
2424

2525
fn generate(&mut self, filepath: &Path) -> io::Result<()> {
26-
self.add_get_size_derive(filepath);
26+
self.modify_source(filepath);
2727
self.generate_definition();
2828
self.generate_from_flat_impls();
2929
self.generate_to_flat_impls();

codegen/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ pub enum PythonBindType {
2727

2828
impl PythonBindType {
2929
pub const BASE_TYPES: [&'static str; 6] = ["bool", "i32", "u32", "f32", "String", "u8"];
30-
pub const FROZEN_TYPES: [&'static str; 21] = [
30+
pub const FROZEN_TYPES: [&'static str; 6] = [
3131
"GoalInfo",
32+
"BoostPad",
33+
"FieldInfo",
34+
"ControllableInfo",
35+
"ControllableTeamInfo",
36+
"PlayerClass",
37+
];
38+
pub const NO_SET_TYPES: [&'static str; 16] = [
39+
"Physics",
3240
"GamePacket",
3341
"PlayerInfo",
3442
"ScoreInfo",
@@ -41,13 +49,8 @@ impl PythonBindType {
4149
"BoostPadState",
4250
"MatchInfo",
4351
"TeamInfo",
44-
"Physics",
4552
"Vector2",
46-
"ControllableInfo",
47-
"ControllableTeamInfo",
48-
"BoostPad",
4953
"PredictionSlice",
50-
"FieldInfo",
5154
"BallPrediction",
5255
];
5356
pub const UNIONS: [&'static str; 4] = [

codegen/pyi.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,26 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
310310
}
311311
}
312312

313-
write_str!(file, " def pack(self) -> bytes: ...");
313+
write_str!(file, " def pack(self) -> bytes:");
314+
write_str!(file, " \"\"\"");
315+
write_str!(file, " Serializes this instance into a byte array");
316+
write_str!(file, " \"\"\"");
317+
318+
if !gen.is_frozen {
319+
write_str!(file, " def unpack_with(self, data: bytes):");
320+
write_str!(file, " \"\"\"");
321+
write_str!(file, " Deserializes the data into this instance\n");
322+
write_str!(
323+
file,
324+
" :raises InvalidFlatbuffer: If the `data` is invalid for this type"
325+
);
326+
write_str!(file, " \"\"\"");
327+
}
328+
314329
write_str!(file, " @staticmethod");
315330
write_fmt!(file, " def unpack(data: bytes) -> {type_name}:");
316331
write_str!(file, " \"\"\"");
332+
write_str!(file, " Deserializes the data into a new instance\n");
317333
write_str!(
318334
file,
319335
" :raises InvalidFlatbuffer: If the `data` is invalid for this type"

0 commit comments

Comments
 (0)