liuli-neko / nekoprototools Goto Github PK
View Code? Open in Web Editor NEWA C++ library that makes it easier to define protocols
License: GNU General Public License v2.0
A C++ library that makes it easier to define protocols
License: GNU General Public License v2.0
现在,该仓库分别在main_v_1_0_0分支和main_v_2_0_0分支提供了两种不同的静态反射支持。两者的思路都是将类注册并赋予唯一的id来实现,同时也都提供了设置默认序列化器并通过基类的序列化反序列化接口。版本1示例如下:
struct ProtoMessage ProtoBase<ProtoMessage, JsonSerializer> {
int a;
std::string b;
CS_SERIALIZE(a, b)
}
int main() {
ProtoFactory factory(1, 0, 0);
IProto* msg = factory.create("ProtoMessage");
auto proto = dynamic_cast<ProtoMessage*>(msg);
proto->a = 1;
proto->b = "hello";
std::vector<char> data;
data = msg->toData();
// do something
delete msg;
return 0;
}
版本2示例如下:
class SerializerAble {
int a;
std::string b;
CS_SERIALIZER(a, b);
}
CS_DECLARE_PROTOCOL(SerializerAble, JsonSerializer)
int main() {
// make protocol by type
// auto sa = makeProtocol(SerializerAble{});
// (*sa)->a = 1;
// (*sa)->b = "hello";
// make protocol by ProtoFactory
ProtoFactory factory(1, 0, 0);
IProto* msg = factory.create("SerializerAble");
auto proto = msg->cast<SerializerAble>();
sa->a = 1;
sa->b = "hello";
auto data = sa->toData(); // for proto message, you can serialize it by toData() and deserialize it by fromData(data)
ProtoFactory factory(1, 0, 0); // you can generate the factory. and proto message while auto regist to this factory.
auto proto = factory.create("SerializerAble"); // you can create the proto message by the name or type value.
proto->fromData(data);
return 0;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.