zserio
zserio copied to clipboard
Allow using raw bytes as request/response in services
Currently, there is no possibility how to send/receive raw bytes in Zserio Services. Zserio services accept only Zserio structures. Consider the following structure:
struct Request
{
uint8 image[];
}
If the structure Request
is serialized and used in Zserio service, it will contain the number of elements before array image
. This could be makes a problem, e.g. for the REST API.
Therefore, it would be good to allow pure raw bytes in services. Possible solution could be to enable parameterized types and introduce new keyword @size
(meaning would be the size of all received/sent data):
struct Image(varsize length)
{
uint8 data[length];
}
service ImageConverterService
{
Image(@size) convertImage(Image(@size));
};
Why not adding a new keyword - e.g. stream
- which could be used instead of struct with size parameter?
Yes, this is another possible solution.
We thought that we will support more generic solution which allows description of service data (e.g. image) in more detail:
struct Image(varsize length)
{
PngHeader header;
uint8 data[length - 8]; // 8 is PNG header size in bytes, we don't have something like sizeof operator
}
However, this more generic solution will be more complicated for implementation and from schema point of view. stream
solution is easier and it will have better performance (no serialization and deserialization). In short, if we are not able to find out any use case for more generic solution, then stream
or even better bytes
solution will be better.
We will implement this by new zserio type bytes
introduced by issue #448. Example:
service ImageConverterService
{
bytes convertImage(bytes);
};