Protocol Buffers - Google's data interchange format (grpc依赖) https://developers.google.com/protocol-buffers/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
use unittest_proto::proto2_unittest::TestAllTypes;
#[test]
fn serialize_deserialize_message() {
let mut msg = TestAllTypes::new();
msg.optional_int64_set(Some(42));
msg.optional_bool_set(Some(true));
msg.optional_bytes_mut().set(b"serialize deserialize test");
let serialized = msg.serialize();
let mut msg2 = TestAllTypes::new();
assert!(msg2.deserialize(&serialized).is_ok());
assert_eq!(msg.optional_int64(), msg2.optional_int64());
assert_eq!(msg.optional_bool(), msg2.optional_bool());
assert_eq!(msg.optional_bytes(), msg2.optional_bytes());
}
#[test]
fn deserialize_empty() {
let mut msg = TestAllTypes::new();
assert!(msg.deserialize(&[]).is_ok());
}
#[test]
fn deserialize_error() {
let mut msg = TestAllTypes::new();
let data = b"not a serialized proto";
assert!(msg.deserialize(&*data).is_err());
}