Add serialize(&self) on MsgView and MsgMut (in addition to the preexisting owned Message)

PiperOrigin-RevId: 607593581
pull/15856/head
Protobuf Team Bot 11 months ago committed by Copybara-Service
parent 976a6eb6a4
commit 42c215718e
  1. 9
      rust/test/shared/serialization_test.rs
  2. 10
      src/google/protobuf/compiler/rust/message.cc

@ -10,9 +10,16 @@ use unittest_proto::TestAllTypes;
#[test]
fn serialize_zero_length() {
let msg = TestAllTypes::new();
let mut msg = TestAllTypes::new();
let serialized = msg.serialize();
assert_that!(serialized.len(), eq(0));
let serialized = msg.as_view().serialize();
assert_that!(serialized.len(), eq(0));
let serialized = msg.as_mut().serialize();
assert_that!(serialized.len(), eq(0));
}
#[test]

@ -904,6 +904,10 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
self.msg
}
pub fn serialize(&self) -> $pbr$::SerializedData {
$Msg::serialize$
}
$accessor_fns_for_views$
}
@ -1034,6 +1038,10 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
self.inner
}
pub fn serialize(&self) -> $pbr$::SerializedData {
$pb$::ViewProxy::as_view(self).serialize()
}
$raw_arena_getter_for_msgmut$
$accessor_fns_for_muts$
@ -1079,7 +1087,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
$raw_arena_getter_for_message$
pub fn serialize(&self) -> $pbr$::SerializedData {
$Msg::serialize$
self.as_view().serialize()
}
pub fn deserialize(&mut self, data: &[u8]) -> Result<(), $pb$::ParseError> {
$Msg::deserialize$

Loading…
Cancel
Save