https://github.com/yinqiwen/shm_proto
https://github.com/yinqiwen/shm_proto
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/yinqiwen/shm_proto
- Owner: yinqiwen
- Created: 2018-04-09T01:58:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-13T09:55:58.000Z (over 7 years ago)
- Last Synced: 2025-01-05T10:43:11.159Z (9 months ago)
- Language: C++
- Size: 21.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# shm_proto
## Features
- Create data strucures in shared memory from proto3 description file.
- Simple reflection support on created data strucures
- Convert from/to standard C++ protobuf instances## Dependency
- [mmdata](https://github.com/yinqiwen/mmdata)
- golang (used as proto3 compiler plugin to generate source files)## Example
```cpp
//build a PB3 instance
HelloTestData data;
.....
//Create
char* buf = (char*)malloc(1024*1024);
MMData mdata;
mdata.OpenWrite(buf, 1024*1024);
//convert from PB to shm instance
const ShmProtoFunctors* funcs = ShmProtoFactory::GetInstance().GetShmFunctors(data.GetTypeName());
void* shm = funcs->Create(mdata);
funcs->Read(shm, &data);
ShmHelloTestData* shmdata = (ShmHelloTestData*)shm;
std::cout << "####"<< *shmdata << std::endl;//get field by name
const mmdata::SHMString* sv = (const mmdata::SHMString*)funcs->GetField(shm, "sv");
std::cout << "#### sv = "<< *sv << std::endl;//convert from shm to pb instance
HelloTestData another;
funcs->Write(shm, &another);
std::string json;
google::protobuf::util::JsonPrintOptions opt;
opt.add_whitespace = true;
opt.always_print_primitive_fields = true;
opt.preserve_proto_field_names = true;
google::protobuf::util::MessageToJsonString(another, &json, opt);
std::cout << "####"<< json << std::endl;funcs->Destroy(mdata, shm);
free(buf);
return 0;
```