0

I am developing a unified protocol serializer for communication between different type of devices using protobuf3.
Different type of devices/environment

  1. Micro-Controller (Cortex M-4 and M-33 (planned) with Ethernet connectivity (Uses Embedded C/C++)
  2. Flutter (Android + iOS + Web)
  3. Python based web-server (using DRF)
  4. Data Gateway (Linux + C/C++)
  5. Android + Kotlin (Legacy Apps)

Most data I send will be of the following types : uint32, uint64, string and bytes.

I have some confusion for Scalar Value Types. If I use uint64 for serial number then in C++ I get uint64 but for Kotlin I get long (signed) and for Python I get int/long.

For C++ I believe I will get range 0 to 18,446,744,073,709,551,615.
For Kotlin and Python I believe the range is 0 to 9,223,372,036,854,775,807.
What will be the range for Flutter?
Looks like I will have a range capped to 9,223,372,036,854,775,807 for my entire system. Am I right regarding this?
I know that serial number will not reach such high value but I will need handle such condition in code.
For checksum CRC32 value I am using uint32 data type which can be anything in range 0 to 4,294,967,295 and the system should be able to handle this. How do I handle this? Kotlin uses int for uint32 while python uses int/long.

[2] In Java, unsigned 32-bit and 64-bit integers are represented using their signed counterparts, with the top bit simply being stored in the sign bit.

[4] 64-bit or unsigned 32-bit integers are always represented as long when decoded, but can be an int if an int is given when setting the field. In all cases, the value must fit in the type represented when set. See [2].

syntax = "proto3";

message Request{
    uint64 serial_number;
    ...
    uint32 checksum;
}
Dark Sorrow
  • 1,681
  • 14
  • 37
  • 1
    Are you implementing protobuf or just asking about the types? The reason I ask is because you're probably better off only using signed ints since that's what Java and Python support. Trying to save space with uints ends up being a compatibility footgun. – David Ehrmann Oct 12 '21 at 05:42
  • @DavidEhrmann I am implementing protobuf. I am starting with C++ implementation. While I was referring to https://developers.google.com/protocol-buffers/docs/proto3#scalar I found out limitation regarding Kotlin and Python. I will now use int64 for serial_number. What about dart (Flutter) how will int64 be mapped? As for CRC32 checksum how to handle it? Should I also use int64 for it? – Dark Sorrow Oct 12 '21 at 05:49
  • 1
    [Dart does not have a native unsigned 64-bit integer](https://stackoverflow.com/questions/53589309/how-do-i-declare-64bit-unsigned-int-in-dart-flutter), so I would expect dart/flutter to map unsigned integers to signed – Marc Gravell Oct 12 '21 at 06:28

0 Answers0