CCF
Loading...
Searching...
No Matches
msg_types.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
6
7#include <sys/socket.h>
8
9namespace udp
10{
11 using ConnID = int64_t;
12
14 {
16 DEFINE_RINGBUFFER_MSG_TYPE(udp_inbound),
17 DEFINE_RINGBUFFER_MSG_TYPE(udp_outbound),
18 };
19
20 static std::tuple<short, std::vector<uint8_t>> sockaddr_encode(sockaddr& addr)
21 {
22 short family = addr.sa_family;
23 std::vector<uint8_t> data(14, '\0');
24 memcpy(&data[0], &addr.sa_data, 14);
25 return std::make_pair(family, data);
26 }
27
28 static sockaddr sockaddr_decode(
29 short family, const std::vector<uint8_t>& data)
30 {
31 sockaddr addr;
32 addr.sa_family = family;
33 memcpy(&addr.sa_data, &data[0], 14);
34 return addr;
35 }
36}
37
38DECLARE_RINGBUFFER_MESSAGE_PAYLOAD(udp::udp_start, udp::ConnID, std::string);
40 udp::udp_inbound,
41 int64_t,
42 short,
43 std::vector<uint8_t>,
46 udp::udp_outbound,
47 int64_t,
48 short,
49 std::vector<uint8_t>,
uint32_t Message
Definition ring_buffer_types.h:19
Definition msg_types.h:10
@ DEFINE_RINGBUFFER_MSG_TYPE
Definition msg_types.h:15
int64_t ConnID
Definition msg_types.h:11
#define DECLARE_RINGBUFFER_MESSAGE_PAYLOAD(MTYPE,...)
Definition ring_buffer_types.h:179
Definition serializer.h:27