ndsev / zserio

zero sugar, zero fat, zero serialization overhead
https://zserio.org/
BSD 3-Clause "New" or "Revised" License
109 stars 27 forks source link

Define types for the mapping of zserio types to c++ types #425

Open reinco opened 2 years ago

reinco commented 2 years ago

There are rules that define what zserio fundamental type is mapped to what c++/java/python type. For code maintainability, it is better that the mapped types are not used directly. Instead there should be a typedef for every mapped type in the proper namespace in the emitted code.

See https://github.com/ndsev/zserio/blob/master/doc/ZserioTypesMapping.md#base-types The idea would be to create a type definition in the emitted code for every mentioned Zserio type (first column of the table). And use these type definitions in the generated code (for example in the getXXX() and setXXX() methods for a field called XXX in a zserio struct).

For example:

Zserio should emit a typedef for 'varint':

namespace zserio
{
   typedef int64_t varint;
}

And given the following struct definition:

struct Data
{
   varint x;
};

We should get something like the following:

class Data
{
   zserio::varsize getX();
};

instead of:

class Data
{
   int64_t getX();
};
mikir commented 2 years ago

As a workaround, schema authors could probably use subtype command.

mikir commented 10 months ago

Consider to use strong typedefs. Please also see #555.