-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpb.h
88 lines (79 loc) · 1.9 KB
/
pb.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <string>
#include <vector>
namespace aliyun_log_sdk_v6
{
namespace pb
{
struct LogContent
{
std::string key; // required
std::string value; // required
LogContent() {}
LogContent(const std::string& key, const std::string& value) : key(key), value(value) {}
};
struct LogTag
{
std::string key; // required
std::string value; // required
LogTag() {}
LogTag(const std::string& key, const std::string& value) : key(key), value(value) {}
};
struct Log
{
uint32_t time; // required
std::vector<LogContent> contents; // required
bool hasTimeNs;
uint32_t timeNs;
Log() : time(0), hasTimeNs(false), timeNs(0) {}
Log(uint32_t time, const std::vector<LogContent>& contents)
: time(time),
contents(contents),
hasTimeNs(false),
timeNs(0)
{
}
Log(uint32_t time, const std::vector<LogContent>& contents, uint32_t timeNs)
: time(time),
contents(contents),
hasTimeNs(true),
timeNs(timeNs)
{
}
};
struct LogGroup
{
std::vector<Log> logs;
std::vector<LogTag> logTags;
std::string topic;
std::string source;
LogGroup() {}
LogGroup(const std::vector<Log>& logs,
const std::vector<LogTag>& logTags,
const std::string& topic,
const std::string& source)
: logs(logs),
logTags(logTags),
topic(topic),
source(source)
{
}
bool SerializeToString(std::string& out) const;
};
struct LogGroupList
{
std::vector<LogGroup> logGroupList;
bool ParseFromString(const std::string& str);
void Clear()
{
logGroupList.clear();
}
};
class PbEncoder
{
public:
static bool SerializeToString(const LogGroup& logGroup, std::string& out);
static bool ParseFromString(const std::string& str, LogGroupList& out);
};
} // namespace pb
} // namespace aliyun_log_sdk_v6