-
Notifications
You must be signed in to change notification settings - Fork 0
/
messagecomposer.h
89 lines (78 loc) · 1.8 KB
/
messagecomposer.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
89
/*
* messagecomposer.h
*
* @brief Compose google::protobuf::Message
*
*/
#ifndef MESSAGECOMPOSER_H_
#define MESSAGECOMPOSER_H_
#include <google/protobuf/message.h>
#include <google/protobuf/reflection.h>
#include "pkt2optionscache.h"
/**
* Compose Protobuf message
* @brief "Parse" message using callback
*/
class MessageComposer {
typedef bool (*oncompose_field)(
void* env,
const google::protobuf::Descriptor *message_descriptor,
const google::protobuf::FieldDescriptor::CppType field_type,
const int field_number,
bool repeated,
int index,
std::string &retval
);
typedef bool (*on_message_begin)(
void* env,
const google::protobuf::FieldDescriptor *field,
google::protobuf::Message* message,
bool repeated,
int index
);
typedef bool (*on_message_end)(
void* env,
google::protobuf::Message* message,
bool repeated,
int index
);
private:
void* env;
oncompose_field onComposeField;
on_message_begin onMessageBegin;
on_message_end onMessageEnd;
const Pkt2OptionsCache *optionCache;
int composeField
(
google::protobuf::Message *message,
const google::protobuf::FieldDescriptor *field
);
protected:
/// compose
bool compose
(
const google::protobuf::FieldDescriptor *field,
google::protobuf::Message *message,
bool repeated,
int index
);
public:
MessageComposer();
MessageComposer
(
void *env,
const Pkt2OptionsCache *options,
google::protobuf::Message *message,
oncompose_field callback_field,
on_message_begin callback_message_begin,
on_message_end callback_message_end
);
virtual ~MessageComposer();
void setCallbacks
(
oncompose_field oncomposefield,
on_message_begin onmessagebegin,
on_message_end onmessageend
);
};
#endif /* MESSAGECOMPOSER_H_ */