Java 使用Protostuff保存未知字段
我有以下Java代码: 假设我的XML代码包含不在模式中的未知字段,即提供的XML是由较新版本的软件生成的 当我再次序列化这些字段时,是否有一种好的、干净的方法来保存它们?我知道 一种解决方案是将原始XML复制到缓冲区,然后将新序列化的XML与原始XML合并,但这似乎过于复杂。根据,似乎不支持保留未知字段: 我假设Protobuf序列化是Protostuff的一部分,它能够处理Google提供的库所做的任何事情。如果我选择使用Protostuff,扩展和未知字段是否可用 否和否。忽略未知字段Java 使用Protostuff保存未知字段,java,xml,protocol-buffers,protostuff,Java,Xml,Protocol Buffers,Protostuff,我有以下Java代码: 假设我的XML代码包含不在模式中的未知字段,即提供的XML是由较新版本的软件生成的 当我再次序列化这些字段时,是否有一种好的、干净的方法来保存它们?我知道 一种解决方案是将原始XML复制到缓冲区,然后将新序列化的XML与原始XML合并,但这似乎过于复杂。根据,似乎不支持保留未知字段: 我假设Protobuf序列化是Protostuff的一部分,它能够处理Google提供的库所做的任何事情。如果我选择使用Protostuff,扩展和未知字段是否可用 否和否。忽略未知字段 以
以下是protoc编译器的示例输出片段:
void hello_message::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:trustportal.crypt.rpc.hello_message)
// required string welcome_message = 1;
if (has_welcome_message()) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->welcome_message().data(), this->welcome_message().length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
"welcome_message");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
1, this->welcome_message(), output);
}
if (!unknown_fields().empty()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
unknown_fields(), output);
}
// @@protoc_insertion_point(serialize_end:trustportal.crypt.rpc.hello_message)
}
对我来说,这似乎意味着未知字段将被正确序列化。是的,协议缓冲区编译器保留未知字段,正如我在问题中指出的那样。然而,就我所知,原型似乎不是。
void hello_message::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:trustportal.crypt.rpc.hello_message)
// required string welcome_message = 1;
if (has_welcome_message()) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->welcome_message().data(), this->welcome_message().length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
"welcome_message");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
1, this->welcome_message(), output);
}
if (!unknown_fields().empty()) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
unknown_fields(), output);
}
// @@protoc_insertion_point(serialize_end:trustportal.crypt.rpc.hello_message)
}