/workspaces/astro/sol3-sdk/cpp/sol3/net/framer.h Source File

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/net/framer.h Source File
Space-ng SDK
framer.h
Go to the documentation of this file.
1 // Copyright (c) Space-ng, inc. All rights reserved.
2 
3 #pragma once
4 
5 #include <cstdint>
6 #include <memory>
7 #include <optional>
8 #include <vector>
9 
10 namespace sol3::net {
11 
12 // Frames a payload in a stream of bytes
13 class IFramer {
14  public:
15  virtual ~IFramer() = default;
16 
17  // A view of a Frame
18  struct FrameSpan {
19  uint8_t const* data;
20  std::size_t size;
21  };
22 
23  // The number of bytes to read next.
24  // The next call to `consume()` must match exactly this number of bytes.
25  virtual std::size_t nextReadLength() const = 0;
26 
27  // Feeds `n` bytes, where `n` matches the last value of `nextReadLength()`.
28  // Returns a frame view if a frame has been found.
29  virtual std::optional<FrameSpan> consume(
30  uint8_t const* data, std::size_t n) = 0;
31 
32  // Frame a payload into caller-owned storage
33  virtual void frameInto(
34  std::vector<uint8_t>& out, uint8_t const* data, std::size_t n) const = 0;
35 
36  // Clone with no internal state
37  virtual std::unique_ptr<IFramer> clone() const = 0;
38 };
39 
40 } // namespace sol3::net
Definition: framer.h:13
virtual void frameInto(std::vector< uint8_t > &out, uint8_t const *data, std::size_t n) const =0
virtual std::unique_ptr< IFramer > clone() const =0
virtual std::optional< FrameSpan > consume(uint8_t const *data, std::size_t n)=0
virtual std::size_t nextReadLength() const =0
virtual ~IFramer()=default
Definition: buffer_pool.h:12
Definition: framer.h:18
uint8_t const * data
Definition: framer.h:19
std::size_t size
Definition: framer.h:20