-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathping_request.rs
More file actions
77 lines (65 loc) · 1.92 KB
/
ping_request.rs
File metadata and controls
77 lines (65 loc) · 1.92 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::{FromGil, IntoGil, PyDefault, flat, flat_err_to_py};
use planus::{Builder, ReadAsRoot};
use pyo3::{prelude::*, types::*};
#[pyclass(module = "rlbot_flatbuffers", subclass, get_all)]
pub struct PingRequest {
#[pyo3(set)]
pub cookie: u64,
}
impl crate::PyDefault for PingRequest {
fn py_default(py: Python) -> Py<Self> {
Py::new(
py,
Self {
cookie: Default::default(),
},
)
.unwrap()
}
}
impl FromGil<&flat::PingRequest> for PingRequest {
#[allow(unused_variables)]
fn from_gil(py: Python, flat_t: &flat::PingRequest) -> Self {
PingRequest {
cookie: flat_t.cookie,
}
}
}
impl FromGil<&PingRequest> for flat::PingRequest {
#[allow(unused_variables)]
fn from_gil(py: Python, py_type: &PingRequest) -> Self {
Self {
cookie: py_type.cookie,
}
}
}
#[pymethods]
impl PingRequest {
#[new]
#[pyo3(signature = (cookie=0))]
pub fn new(cookie: u64) -> Self {
Self { cookie }
}
pub fn __str__(&self, py: Python) -> String {
self.__repr__(py)
}
#[allow(unused_variables)]
pub fn __repr__(&self, py: Python) -> String {
format!("PingRequest(cookie={})", self.cookie,)
}
#[classattr]
fn __match_args__() -> (&'static str,) {
("cookie",)
}
fn pack<'py>(&self, py: Python<'py>) -> Bound<'py, PyBytes> {
let mut builder = Builder::with_capacity(u16::MAX as usize);
let flat_t = flat::PingRequest::from_gil(py, self);
PyBytes::new(py, builder.finish(flat_t, None))
}
#[staticmethod]
fn unpack(py: Python, data: &[u8]) -> PyResult<Py<Self>> {
let flat_t_ref = flat::PingRequestRef::read_as_root(data).map_err(flat_err_to_py)?;
let flat_t = flat::PingRequest::try_from(flat_t_ref).map_err(flat_err_to_py)?;
Ok(crate::into_py_from(py, &flat_t))
}
}