zserio icon indicating copy to clipboard operation
zserio copied to clipboard

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

Open reinco opened this issue 2 years ago • 2 comments

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();
};

reinco avatar Oct 03 '22 10:10 reinco

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

mikir avatar Oct 07 '22 10:10 mikir

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

mikir avatar Dec 15 '23 10:12 mikir