1 //
2 // Copyright (C) 2021 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #pragma once
17 
18 #include <cstdint>
19 #include <sstream>
20 #include <string>
21 #include <tuple>
22 #include <vector>
23 
24 namespace cuttlefish {
25 namespace confui {
26 namespace packet {
27 struct PayloadHeader {
28   std::uint32_t payload_length_;
29 };
30 
31 using BufferType = std::vector<std::uint8_t>;
32 
33 // PayloadHeader + the byte size sent over the channel
34 using Payload = std::tuple<PayloadHeader, BufferType>;
35 
36 // this is for short messages
37 constexpr const ssize_t kMaxPayloadLength = 10000;
38 
39 using ConfUiPacketInfo = std::vector<std::vector<std::uint8_t>>;
40 struct ParsedPacket {
41   std::string session_id_;
42   std::string type_;
43   ConfUiPacketInfo additional_info_;
44 };
45 
46 std::string ToString(const ParsedPacket& packet);
47 }  // end of namespace packet
48 }  // end of namespace confui
49 }  // end of namespace cuttlefish
50