Add V0 support for fixed ints (32 and 64)

PiperOrigin-RevId: 548716260
pull/13237/head
Hong Shin 1 year ago committed by Copybara-Service
parent a6083e672f
commit 7e9d0c1630
  1. 33
      rust/test/shared/accessors_test.rs
  2. 2
      src/google/protobuf/compiler/rust/accessors/accessors.cc
  3. 6
      src/google/protobuf/compiler/rust/naming.cc

@ -34,6 +34,8 @@ use unittest_proto::proto2_unittest::TestAllTypes;
#[test] #[test]
fn test_default_accessors() { fn test_default_accessors() {
let msg = TestAllTypes::new(); let msg = TestAllTypes::new();
assert_eq!(msg.default_fixed32(), 47);
assert_eq!(msg.default_fixed64(), 48);
assert_eq!(msg.default_int32(), 41); assert_eq!(msg.default_int32(), 41);
assert_eq!(msg.default_int64(), 42); assert_eq!(msg.default_int64(), 42);
assert_eq!(msg.default_sint32(), -45); assert_eq!(msg.default_sint32(), -45);
@ -45,6 +47,37 @@ fn test_default_accessors() {
assert_eq!(msg.default_bool(), true); assert_eq!(msg.default_bool(), true);
} }
#[test]
fn test_optional_fixed32_accessors() {
let mut msg = TestAllTypes::new();
assert_eq!(msg.optional_fixed32_opt(), None);
assert_eq!(msg.optional_fixed32(), 0);
msg.optional_fixed32_set(Some(99));
assert_eq!(msg.optional_fixed32_opt(), Some(99));
assert_eq!(msg.optional_fixed32(), 99);
msg.optional_fixed32_set(None);
assert_eq!(msg.optional_fixed32_opt(), None);
assert_eq!(msg.optional_fixed32(), 0);
}
#[test]
fn test_optional_fixed64_accessors() {
let mut msg = TestAllTypes::new();
assert_eq!(msg.optional_fixed64_opt(), None);
assert_eq!(msg.optional_fixed64(), 0);
msg.optional_fixed64_set(Some(2000));
assert_eq!(msg.optional_fixed64_opt(), Some(2000));
assert_eq!(msg.optional_fixed64(), 2000);
msg.optional_fixed64_set(None);
assert_eq!(msg.optional_fixed64_opt(), None);
assert_eq!(msg.optional_fixed64(), 0);
}
#[test] #[test]
fn test_optional_int32_accessors() { fn test_optional_int32_accessors() {
let mut msg = TestAllTypes::new(); let mut msg = TestAllTypes::new();

@ -51,6 +51,8 @@ std::unique_ptr<AccessorGenerator> AccessorGenerator::For(
switch (field.desc().type()) { switch (field.desc().type()) {
case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_INT32:
case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_INT64:
case FieldDescriptor::TYPE_FIXED32:
case FieldDescriptor::TYPE_FIXED64:
case FieldDescriptor::TYPE_SINT32: case FieldDescriptor::TYPE_SINT32:
case FieldDescriptor::TYPE_SINT64: case FieldDescriptor::TYPE_SINT64:
case FieldDescriptor::TYPE_UINT32: case FieldDescriptor::TYPE_UINT32:

@ -110,6 +110,10 @@ absl::string_view PrimitiveRsTypeName(Context<FieldDescriptor> field) {
switch (field.desc().type()) { switch (field.desc().type()) {
case FieldDescriptor::TYPE_BOOL: case FieldDescriptor::TYPE_BOOL:
return "bool"; return "bool";
case FieldDescriptor::TYPE_FIXED32:
return "i32";
case FieldDescriptor::TYPE_FIXED64:
return "i64";
case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_INT32:
return "i32"; return "i32";
case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_INT64:
@ -141,6 +145,8 @@ bool IsSupportedFieldType(Context<FieldDescriptor> field) {
// cord or string_piece) in V0 API. // cord or string_piece) in V0 API.
!field.desc().options().has_ctype() && !field.desc().options().has_ctype() &&
(field.desc().type() == FieldDescriptor::TYPE_BOOL || (field.desc().type() == FieldDescriptor::TYPE_BOOL ||
field.desc().type() == FieldDescriptor::TYPE_FIXED32 ||
field.desc().type() == FieldDescriptor::TYPE_FIXED64 ||
field.desc().type() == FieldDescriptor::TYPE_INT32 || field.desc().type() == FieldDescriptor::TYPE_INT32 ||
field.desc().type() == FieldDescriptor::TYPE_INT64 || field.desc().type() == FieldDescriptor::TYPE_INT64 ||
field.desc().type() == FieldDescriptor::TYPE_SINT32 || field.desc().type() == FieldDescriptor::TYPE_SINT32 ||

Loading…
Cancel
Save