A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
host_binary_channel.h
Go to the documentation of this file.
1// Copyright 2026 The A11 Authors
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 A11_WASM_HOST_BINARY_CHANNEL_H_
16#define A11_WASM_HOST_BINARY_CHANNEL_H_
17
18#include <memory>
19#include <optional>
20#include <string>
21#include <string_view>
22
23#include <absl/status/status.h>
24#include <absl/status/statusor.h>
25#include <nlohmann/json.hpp>
26
27#include "a11/net/internal/binary_channel.h"
30
31namespace a11::wasm {
32
33class HostBinaryChannel final : public net::internal::BinaryChannel {
34 public:
35 explicit HostBinaryChannel(std::string id) : id_(std::move(id)) {}
36
37 absl::Status SetCallbacks(net::internal::BinaryChannelCallbacks callbacks)
38 override;
39 absl::Status ResetCallbacks() override;
40 absl::Status Open() override;
41 absl::Status Send(std::string bytes) override;
42 absl::StatusOr<size_t> BufferedAmount() const override;
43 absl::StatusOr<bool> IsOpen() const override;
44 absl::Status Close() override;
45 absl::Status Abort(absl::Status status) override;
46 void* absl_nullable GetImpl() const override { return nullptr; }
47
48 absl::Status Emit(std::string_view kind, const nlohmann::json& payload);
49
50 private:
51 absl::StatusOr<nlohmann::json> Call(std::string_view kind,
52 const nlohmann::json& payload) const;
53
54 std::string id_;
55 mutable thread::Mutex mu_;
56 net::internal::BinaryChannelCallbacks callbacks_ ABSL_GUARDED_BY(mu_);
57 std::optional<absl::Status> pending_error_ ABSL_GUARDED_BY(mu_);
58};
59
61 public:
62 static absl::StatusOr<std::shared_ptr<HostChannelWireStream>> Create(
63 const std::shared_ptr<HostBinaryChannel>& channel, std::string id,
66
67 private:
68 explicit HostChannelWireStream(std::shared_ptr<State> state)
69 : net::ChannelWireStream(std::move(state)) {}
70};
71
72} // namespace a11::wasm
73
74#endif // A11_WASM_HOST_BINARY_CHANNEL_H_
Shared WireStream lifecycle and framing for binary channels.
Definition channel_wire_stream.h:69
Definition host_binary_channel.h:33
absl::StatusOr< bool > IsOpen() const override
Definition host_binary_channel.cc:118
absl::StatusOr< size_t > BufferedAmount() const override
Definition host_binary_channel.cc:109
absl::Status Emit(std::string_view kind, const nlohmann::json &payload)
Definition host_binary_channel.cc:134
absl::Status Open() override
Definition host_binary_channel.cc:101
absl::Status Abort(absl::Status status) override
Definition host_binary_channel.cc:130
absl::Status SetCallbacks(net::internal::BinaryChannelCallbacks callbacks) override
Definition host_binary_channel.cc:78
absl::Status Close() override
Definition host_binary_channel.cc:126
void *absl_nullable GetImpl() const override
Definition host_binary_channel.h:46
absl::Status ResetCallbacks() override
Definition host_binary_channel.cc:93
absl::Status Send(std::string bytes) override
Definition host_binary_channel.cc:105
HostBinaryChannel(std::string id)
Definition host_binary_channel.h:35
Definition host_binary_channel.h:60
static absl::StatusOr< std::shared_ptr< HostChannelWireStream > > Create(const std::shared_ptr< HostBinaryChannel > &channel, std::string id, net::ChannelEndpointRole role, net::WireStreamOptions options, net::ChannelFramingOptions framing)
Definition host_binary_channel.cc:173
Definition boost_primitives.h:21
TokenKind kind
Definition format.cc:1372
ChannelEndpointRole
Handshake role a binary channel endpoint is permitted to assume.
Definition channel_wire_stream.h:43
Definition async_task.cc:27
stores::ChunkStoreReaderOptions options
Definition runtime_streams.cc:31
Packetisation and incomplete-message bounds for a binary WireStream.
Definition channel_wire_stream.h:46
Buffering, sizing, and deadline limits for a WireStream endpoint.
Definition wire_stream.h:58