nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
framing.h
Go to the documentation of this file.
1#ifndef NANOMMO_PROTOCOL_FRAMING_H_
2#define NANOMMO_PROTOCOL_FRAMING_H_
3
4#include <cstddef>
5#include <optional>
6#include <string>
7#include <string_view>
8
9#include "absl/status/status.h"
10#include "google/protobuf/message_lite.h"
11
12namespace nanommo {
13
14constexpr std::size_t kHeaderSize = 4;
15
16/// Anything bigger is garbage. Without a cap, we might buffer up to 4 GB.
17constexpr std::size_t kMaxMessageSize = 64 * 1024;
18
19std::string Header(std::size_t size);
20
21/// The size goes in front, as four bytes in network byte order.
22std::string Frame(const google::protobuf::MessageLite& message);
23
25 public:
26 void Append(std::string_view bytes);
27
28 /// After a message that's too large, returns nothing more, and status()
29 /// says why.
30 std::optional<std::string> Next();
31
32 const absl::Status& status() const { return status_; }
33
34 private:
35 std::string buffer_;
36 absl::Status status_;
37};
38
39} // namespace nanommo
40
41#endif // NANOMMO_PROTOCOL_FRAMING_H_
void Append(std::string_view bytes)
Definition framing.cc:19
std::optional< std::string > Next()
Definition framing.cc:21
const absl::Status & status() const
Definition framing.h:32
Definition chat.cc:9
constexpr std::size_t kHeaderSize
Definition framing.h:14
std::string Header(std::size_t size)
Definition framing.cc:8
constexpr std::size_t kMaxMessageSize
Anything bigger is garbage. Without a cap, we might buffer up to 4 GB.
Definition framing.h:17
std::string Frame(const google::protobuf::MessageLite &message)
The size goes in front, as four bytes in network byte order.
Definition framing.cc:14