在c++中显式序列化Slice对象为string或ostream



是否有一种方法可以显式地将Slice对象序列化为使用ice的字符串?问题是有一个对象必须通过json/xml/ice发送,因为ice已经在ice (Slice)的规范语言中有一个平台独立的对象,所以没有必要包括另一个像protobuf这样的库。但是据我所知,显式序列化对象是不可能的。我错了吗?

您可以使用OutputStream API以Ice二进制格式序列化对象

Ice::ByteSeq inParams, outParams;
Ice::OutputStream out(communicator);
out.startEncapsulation();
Demo::CPtr c = new Demo::C;
c->s.name = "blue";
c->s.value = Demo::blue;
out.write(c);
out.writePendingValues();
out.endEncapsulation();
out.finished(inParams);

ice-demos存储库https://github.com/zeroc-ice/ice-demos/tree/3.7/cpp98/Ice/invoke

中有其他示例OutputStream的文档可以在https://doc.zeroc.com/ice/3.7/client-server-features/dynamic-ice/streaming-interfaces/c++-streaming-interfaces/the-outputstream-interface-in-c++

找到

最新更新