Skip to content

Commit 2a1fad6

Browse files
committed
Update to new spec
1 parent 9819a5c commit 2a1fad6

6 files changed

Lines changed: 65 additions & 59 deletions

File tree

Cargo.lock

Lines changed: 38 additions & 50 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-py"
3-
version = "0.8.1"
3+
version = "0.9.0"
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/structs.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ impl StructBindGenerator {
327327
String::from("Option<crate::Floats>")
328328
} else if inner_type == "Bool" {
329329
String::from("Option<crate::Bools>")
330+
} else if self.is_frozen {
331+
format!("Option<super::{inner_type}>")
330332
} else {
331333
format!("Option<Py<super::{inner_type}>>")
332334
}),
@@ -690,7 +692,13 @@ impl Generator for StructBindGenerator {
690692
}
691693
RustType::Option(InnerOptionType::BaseType, inner_type)
692694
| RustType::Option(InnerOptionType::String, inner_type) => format!("Option<{inner_type}>"),
693-
RustType::Option(_, inner_type) => format!("Option<Py<super::{inner_type}>>"),
695+
RustType::Option(_, inner_type) => {
696+
if self.is_frozen {
697+
format!("Option<super::{inner_type}>")
698+
} else {
699+
format!("Option<Py<super::{inner_type}>>")
700+
}
701+
}
694702
RustType::Base(inner_type) => inner_type.clone(),
695703
RustType::String => String::from("String"),
696704
RustType::Union(inner_type) | RustType::Custom(inner_type) => {
@@ -810,9 +818,15 @@ impl Generator for StructBindGenerator {
810818
}
811819
}
812820
RustType::Option(InnerOptionType::Box, _) => {
821+
let inner = if self.is_frozen {
822+
"(*x).into()"
823+
} else {
824+
"crate::into_py_from(py, *x)"
825+
};
826+
813827
write_fmt!(
814828
self,
815-
" {variable_name}: flat_t.{variable_name}.map(|x| crate::into_py_from(py, *x)),"
829+
" {variable_name}: flat_t.{variable_name}.map(|x| {inner}),"
816830
);
817831
}
818832
RustType::Option(InnerOptionType::String, _) => {
@@ -930,7 +944,13 @@ impl Generator for StructBindGenerator {
930944
}
931945
}
932946
RustType::Option(InnerOptionType::Box, _) => {
933-
write_fmt!(self, " {variable_name}: py_type.{variable_name}.as_ref().map(|x| Box::new(crate::from_py_into(py, x))),");
947+
let inner = if self.is_frozen {
948+
"x.into()"
949+
} else {
950+
"crate::from_py_into(py, x)"
951+
};
952+
953+
write_fmt!(self, " {variable_name}: py_type.{variable_name}.as_ref().map(|x| Box::new({inner})),");
934954
}
935955
RustType::Option(InnerOptionType::String, _) => {
936956
write_fmt!(self, " {variable_name}: py_type.{variable_name}.clone(),");

flatbuffers-schema

pybench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_gtp():
99
gtp = flat.GameTickPacket(
1010
balls=[flat.BallInfo(shape=flat.SphereShape()) for _ in range(32)],
1111
players=[flat.PlayerInfo() for _ in range(128)],
12-
boost_pad_states=[flat.BoostPadState() for _ in range(128)],
12+
boost_pads=[flat.BoostPadState() for _ in range(128)],
1313
teams=[flat.TeamInfo() for _ in range(2)],
1414
)
1515

pytest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ def random_script_config():
150150

151151
print()
152152

153-
ballPred = BallPrediction([
154-
PredictionSlice(1) for _ in range(5 * 120)
155-
])
153+
ballPred = BallPrediction([PredictionSlice(1) for _ in range(5 * 120)])
156154
data = ballPred.pack()
157155
print(f"BallPrediction size: {len(data)} bytes")
158156

0 commit comments

Comments
 (0)