-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (27 loc) · 1.01 KB
/
main.cpp
File metadata and controls
34 lines (27 loc) · 1.01 KB
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
#include "MsgpackWrapper.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
typedef enum { uAdmin = 42, uViewer } TUserRole;
class UserDto : public MsgpackObject {
public:
MsgpackValue<char *> Name;
MsgpackValue<uint32_t> Role;
UserDto(const char *name = {}, const TUserRole role = {})
: Name(this, 0, name), //
Role(this, 1, role) {};
};
int main(void) {
char buffer[2048];
UserDto outUserDto("DemoWrapper", uAdmin);
auto writed = outUserDto.Write(buffer, sizeof(buffer));
fprintf(stdout, "out UserDto(%s, %u) serialized to %u bytes\n", outUserDto.Name.Get(), outUserDto.Role.Get(), (unsigned)writed);
UserDto inUserDto;
auto res = inUserDto.TryParse(buffer, writed);
if (res) {
fprintf(stdout, "in UserDto(%s, %u) deserialized successfully\n", outUserDto.Name.Get(), outUserDto.Role.Get());
} else {
fprintf(stderr, "in UserDto(%s, %u) deserialized with error\n", outUserDto.Name.Get(), outUserDto.Role.Get());
}
return 0;
}