MCPcopy Create free account
hub / github.com/OpenImageDebugger/OpenImageDebugger / FakeTransport

Class FakeTransport

tests/host/ipc/ipc_client_test.cpp:95–118  ·  view source on GitHub ↗

Fake transport: `inbound` is a queue of bytes handed out (possibly short) via receive(); sent frames are recorded verbatim in `sends`.

Source from the content-addressed store, hash-verified

93// Fake transport: `inbound` is a queue of bytes handed out (possibly short)
94// via receive(); sent frames are recorded verbatim in `sends`.
95struct FakeTransport final : ITransport {
96 std::vector<std::byte> inbound;
97 std::size_t pos = 0;
98 std::vector<std::vector<std::byte>> sends;
99
100 void send(std::span<const std::byte> d) override {
101 sends.emplace_back(d.begin(), d.end());
102 }
103
104 std::size_t receive(std::span<std::byte> dst) override {
105 const std::size_t n = (std::min)(dst.size(), inbound.size() - pos);
106 std::memcpy(dst.data(), inbound.data() + pos, n);
107 pos += n;
108 return n; // may short-read
109 }
110
111 bool has_data() const override {
112 return pos < inbound.size();
113 }
114
115 void feed(const std::vector<std::byte>& f) {
116 inbound.insert(inbound.end(), f.begin(), f.end());
117 }
118};
119
120// Captures the bytes a MessageComposer would send, without a real socket.
121static std::vector<std::byte> frame(const MessageComposer& c) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected