-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSegment.h
51 lines (40 loc) · 942 Bytes
/
Segment.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// Created by frank on 17-8-13.
//
#ifndef FDP_SEGMENT_H
#define FDP_SEGMENT_H
#include "noncopyable.h"
#include <cstdint>
#include <memory>
#include <vector>
struct Segment: noncopyable
{
uint32_t ident;
uint32_t cmd;
uint32_t frg;
uint32_t wnd;
uint32_t ts;
uint32_t seq;
uint32_t una;
uint32_t len;
uint32_t resendts;
uint32_t rto;
uint32_t fastack;
uint32_t xmit;
char data[];
};
class SegmentDeleter
{
public:
SegmentDeleter() = default;
void operator()(Segment* seg) const
{ free(seg); }
};
#define ENCODE_OVERHEAD 24
#define MAX_FRAGMENTS 255
typedef std::unique_ptr<Segment, SegmentDeleter> SegmentPtr;
SegmentPtr createSegment(const char *data, uint32_t size);
uint32_t encodeSegment(const Segment& seg, char*& buffer, uint32_t& size);
uint32_t encodeSegment(const Segment& seg, std::vector<char>& buffer);
SegmentPtr decodeSegment(const char *&data, uint32_t &size);
#endif //FDP_SEGMENT_H