Action Engine
Loading...
Searching...
No Matches
chunk_store_pybind11.h
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ACTIONENGINE_PYBIND11_ACTIONENGINE_CHUNK_STORE_H_
16#define ACTIONENGINE_PYBIND11_ACTIONENGINE_CHUNK_STORE_H_
17
18#include <cstddef>
19#include <cstdint>
20#include <functional>
21#include <memory>
22#include <optional>
23#include <string_view>
24
25#include <absl/status/status.h>
26#include <absl/status/statusor.h>
27#include <absl/time/time.h>
28#include <pybind11/cast.h>
29#include <pybind11/detail/type_caster_base.h>
30#include <pybind11/pybind11.h>
31#include <pybind11/pytypes.h>
32#include <pybind11_abseil/absl_casters.h>
33#include <pybind11_abseil/status_caster.h>
34#include <pybind11_abseil/statusor_caster.h>
35
38
39namespace act::pybindings {
40
41namespace py = ::pybind11;
42
43class PyChunkStore final : public ChunkStore, py::trampoline_self_life_support {
44 // For detailed documentation, see the base class, ChunkStore.
45 public:
46 using ChunkStore::ChunkStore;
47
48 PyChunkStore() : ChunkStore() {}
49
50 absl::StatusOr<Chunk> Get(int64_t seq, absl::Duration timeout) override;
51
52 absl::StatusOr<Chunk> GetByArrivalOrder(int64_t seq,
53 absl::Duration timeout) override;
54
55 absl::StatusOr<std::reference_wrapper<const Chunk>> GetRef(
56 int64_t seq, absl::Duration timeout) override;
57
58 absl::StatusOr<std::reference_wrapper<const Chunk>> GetRefByArrivalOrder(
59 int64_t seq, absl::Duration timeout) override;
60
61 absl::StatusOr<std::optional<Chunk>> Pop(int64_t seq) override;
62
63 absl::Status Put(int64_t seq, Chunk chunk, bool final) override;
64
65 absl::Status CloseWritesWithStatus(absl::Status status) override;
66
67 absl::StatusOr<size_t> Size() override;
68
69 absl::StatusOr<bool> Contains(int64_t seq) override;
70
71 absl::Status SetId(std::string_view id) override;
72
73 [[nodiscard]] std::string_view GetId() const override;
74
75 absl::StatusOr<int64_t> GetSeqForArrivalOffset(
76 int64_t arrival_offset) override;
77
78 absl::StatusOr<int64_t> GetFinalSeq() override;
79};
80
81void BindChunkStoreReaderOptions(
82 py::handle scope, std::string_view name = "ChunkStoreReaderOptions");
83
84void BindChunkStore(py::handle scope, std::string_view name = "ChunkStore");
85
86void BindLocalChunkStore(py::handle scope,
87 std::string_view name = "LocalChunkStore");
88
89py::module_ MakeChunkStoreModule(py::module_ scope,
90 std::string_view module_name = "chunk_store");
91} // namespace act::pybindings
92
93namespace pybind11::detail {
94template <>
95class type_caster<std::unique_ptr<act::ChunkStore>>
96 : public type_caster_base<std::unique_ptr<act::ChunkStore>> {};
97} // namespace pybind11::detail
98
99#endif // ACTIONENGINE_PYBIND11_ACTIONENGINE_CHUNK_STORE_H_
An abstract interface for raw data storage and retrieval for ActionEngine nodes.
ActionEngine data structures used to implement actions and nodes (data streams).