SOLA
Loading...
Searching...
No Matches
framing_manager.h
1// Copyright 2023 The SOLA authors
2//
3// This file is part of DAISI.
4//
5// DAISI is free software: you can redistribute it and/or modify it under the terms of the GNU
6// General Public License as published by the Free Software Foundation; version 2.
7//
8// DAISI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10// Public License for more details.
11//
12// You should have received a copy of the GNU General Public License along with DAISI. If not, see
13// <https://www.gnu.org/licenses/>.
14//
15// SPDX-License-Identifier: GPL-2.0-only
16
17#ifndef DAISI_NETWORK_TCP_FRAMING_MANAGER_H_
18#define DAISI_NETWORK_TCP_FRAMING_MANAGER_H_
19
20#include <cstdint>
21#include <deque>
22#include <optional>
23#include <string>
24
25namespace daisi::network_tcp {
26
28public:
29 void processNewData(const std::string &msg);
30
31 bool hasPackets() const;
32
33 std::string nextPacket();
34
35 static std::string frameMsg(const std::string &msg);
36
37private:
39 static uint32_t readPacketSize(const std::string &msg, uint32_t next_offset);
40
42 uint32_t handleNewPacket(const std::string &msg, uint32_t next_offset);
43
46 uint32_t readPacket(const std::string &msg, uint32_t next_offset);
47
48 std::deque<std::string> outstanding_packets_;
49
50 struct InflightPacket {
51 std::string packet;
52 size_t remaining_size;
53 };
54
55 std::optional<InflightPacket> inflight_;
56};
57} // namespace daisi::network_tcp
58
59#endif // DAISI_NETWORK_TCP_FRAMING_MANAGER_H_
Definition framing_manager.h:27