mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-09 20:04:20 +00:00
This search/replace updates all copyright notices to drop the "All rights reserved", Use "ChromiumOS" instead of "Chromium OS" and drops the trailing dots. This fulfills the request from legal and unifies our notices. ./tools/health-check has been updated to only accept this style. BUG=b:246579983 TEST=./tools/health-check Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Dennis Kempin <denniskempin@google.com>
35 lines
1.3 KiB
Rust
35 lines
1.3 KiB
Rust
// Copyright 2019 The ChromiumOS Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
use protobuf::Message;
|
|
|
|
/// Asserts that a given protobuf message object can be serialized to bytes and
|
|
/// read back into a value of the same type, preserving equality between the
|
|
/// original object and the one read back.
|
|
///
|
|
/// This is helpful for confirming that proto files have been compiled
|
|
/// successfully and are exposed as intended by the public API of the parent
|
|
/// crate. It also lets us exercise the full set of methods we intend to use for
|
|
/// building particular proto objects so that we notice breakage early in the
|
|
/// event that a proto external to this repository would make a breaking change.
|
|
///
|
|
/// Note: assumes that the given `message` is not just `T::new` so that we can
|
|
/// tell that deserialization has happened successfully.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```ignore
|
|
/// let mut request = SendCommandRequest::new();
|
|
/// request.set_command(b"...".to_vec());
|
|
/// test_round_trip(request);
|
|
/// ```
|
|
pub fn test_round_trip<T: Message + PartialEq>(message: T) {
|
|
let serialized = message.write_to_bytes().unwrap();
|
|
|
|
let mut back = T::new();
|
|
assert_ne!(message, back);
|
|
|
|
back.merge_from_bytes(&serialized).unwrap();
|
|
assert_eq!(message, back);
|
|
}
|