Skip to content

Commit

Permalink
Add test for packed default.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcorre authored and stepancheg committed Jun 16, 2024
1 parent 305b1e4 commit 5d8bdb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use protobuf::reflect::Syntax;
use protobuf::MessageFull;
use protobuf_test_common::*;

use super::test_repeated_packed_pb::*;
Expand Down Expand Up @@ -83,3 +85,16 @@ fn test_issue_281() {
test.values = (0..100).collect();
test_serialize_deserialize_no_hex(&test);
}

#[test]
fn test_write_packed_default() {
let mut test = TestPackedDefault::new();
test.varints = vec![0, 1, 2, 3, 4, 5];

// Proto3 packs primitives by default, proto2 does not.
let expected_hex = match TestPackedDefault::descriptor().file_descriptor().syntax() {
Syntax::Proto2 => "08 00 08 01 08 02 08 03 08 04 08 05",
Syntax::Proto3 => "0a 06 00 01 02 03 04 05",
};
test_serialize_deserialize(expected_hex, &test);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ message TestUnpacked {
message TestIssue281 {
repeated fixed32 values = 1 [packed=true];
}

message TestPackedDefault {
repeated uint32 varints = 1;
}

0 comments on commit 5d8bdb4

Please sign in to comment.