chia_protocol/
classgroup.rs1use crate::Bytes100;
2use chia_streamable_macro::streamable;
3
4#[cfg(feature = "py-bindings")]
5use pyo3::prelude::*;
6
7#[streamable]
8#[derive(Copy)]
9pub struct ClassgroupElement {
10 data: Bytes100,
11}
12
13impl Default for ClassgroupElement {
14 fn default() -> Self {
15 let mut data = [0_u8; 100];
16 data[0] = 0x08;
17 Self { data: data.into() }
18 }
19}
20
21impl ClassgroupElement {
22 pub const SIZE: usize = 100;
23}
24
25#[cfg(feature = "py-bindings")]
26#[pymethods]
27impl ClassgroupElement {
28 #[staticmethod]
29 pub fn create(bytes: &[u8]) -> ClassgroupElement {
30 if bytes.len() == 100 {
31 ClassgroupElement {
32 data: bytes.try_into().unwrap(),
33 }
34 } else {
35 assert!(bytes.len() < 100);
36 let mut data = [0_u8; 100];
37 data[..bytes.len()].copy_from_slice(bytes);
38 ClassgroupElement { data: data.into() }
39 }
40 }
41
42 #[staticmethod]
43 #[pyo3(name = "get_default_element")]
44 pub fn py_get_default_element() -> ClassgroupElement {
45 Self::default()
46 }
47
48 #[staticmethod]
49 #[pyo3(name = "get_size")]
50 pub fn py_get_size() -> i32 {
51 Self::SIZE as i32
52 }
53}