Skip to content

Commit 63fa0cc

Browse files
committed
Made retrievers accessible in python
1 parent d3a91a4 commit 63fa0cc

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

docs/pages/reference/types/base_struct.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ver",
55
"__new__",
66
"__reconstruct__",
7+
"retrievers",
78
"from_stream",
89
"to_bytes",
910
"from_base",

src/retrievers/retriever.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,30 @@ pub enum RetState {
2828
#[pyclass(module = "bfp_rs")]
2929
#[derive(Debug, Clone)]
3030
pub struct Retriever {
31+
#[pyo3(get)]
3132
pub idx: usize,
32-
33+
34+
#[pyo3(get)]
3335
pub data_type: BfpType,
3436

37+
#[pyo3(get)]
3538
min_ver: Version,
39+
40+
#[pyo3(get)]
3641
max_ver: Version,
3742

43+
#[pyo3(get)]
3844
pub repeat: isize,
45+
46+
#[pyo3(get)]
3947
pub remaining_compressed: bool,
4048

49+
#[pyo3(get)]
4150
pub name: String,
4251

4352
on_read: Option<Arc<Vec<CombinatorType>>>,
4453
on_write: Option<Arc<Vec<CombinatorType>>>,
45-
54+
4655
default: Option<Arc<PyObject>>,
4756
default_factory: Option<Arc<PyObject>>,
4857

src/types/base_struct.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
88
use pyo3::exceptions::{PyAttributeError, PyTypeError};
99
use pyo3::intern;
1010
use pyo3::prelude::*;
11-
use pyo3::types::{PyBytes, PyDict, PyTuple, PyType};
11+
use pyo3::types::{PyBytes, PyDict, PyList, PyTuple, PyType};
1212
use serde::de::DeserializeSeed;
1313
use serde_json::Deserializer;
1414

@@ -220,6 +220,15 @@ impl BaseStruct {
220220
slf.raw.read().expect("GIL bound read").ver.clone()
221221
}
222222

223+
#[classmethod]
224+
fn retrievers<'py>(cls: &Bound<'py, PyType>) -> PyResult<Bound<'py, PyList>> {
225+
let struct_ = StructBuilder::get_struct(&cls)?;
226+
Ok(PyList::new_bound(
227+
cls.py(),
228+
struct_.retrievers().iter().map(|x| x.clone().into_py(cls.py()))
229+
))
230+
}
231+
223232
#[new]
224233
#[classmethod]
225234
#[pyo3(signature = (*_args, ver = Version::new(vec![-1]), ctx = ContextPtr::new(), init_defaults = true, **retriever_inits))]

stubs/bfp_rs/retrievers/retriever.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ class Retriever:
1313
allowing setting constraints and hooks
1414
"""
1515

16+
idx: int
17+
data_type: Any
18+
min_ver: Version
19+
max_ver: Version
20+
repeat: int
21+
remaining_compressed: bool
22+
name: str
23+
1624
def __new__(
1725
cls,
1826
data_type: Any,

stubs/bfp_rs/types/base_struct.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any, Self
22

3+
from bfp_rs.retrievers import Retriever
34
from bfp_rs.types.byte_stream import ByteStream
45
from bfp_rs.types.context import Context
56
from bfp_rs.types.version import Version
@@ -13,6 +14,10 @@ class BaseStruct:
1314
ver: Version
1415
"The version of the struct"
1516

17+
@classmethod
18+
def retrievers(cls) -> list[Retriever]:
19+
...
20+
1621
def __new__(cls, *args, ver: Version = Version(-1), ctx: Context = Context(), init_defaults: bool = True, **retriever_inits: Any) -> Self:
1722
"""
1823
Default initialise and create a new instance of this struct

0 commit comments

Comments
 (0)