Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backward-compatible thrown exception #1

Open
sduwall opened this issue Oct 9, 2021 · 6 comments
Open

backward-compatible thrown exception #1

sduwall opened this issue Oct 9, 2021 · 6 comments

Comments

@sduwall
Copy link

sduwall commented Oct 9, 2021

first version zs content:

package tutorial;

struct Employee
{
    uint8           age : age <= 65; // max age is 65
    string          name;
    uint16          salary;
    Role            role;
    // if employee is a developer, list programming skill
    Experience      skills[] if role == Role.DEVELOPER;
};

struct Experience
{
    bit:6       yearsOfExperience;
    Language    programmingLanguage;
};

enum bit:2 Language
{
    CPP     = 0,
    JAVA    = 1,
    PYTHON  = 2,
    JS      = 3
};

enum uint8 Role
{
    DEVELOPER = 0,
    TEAM_LEAD = 1,
    CTO       = 2
};

struct ArrayEmployee
{
    int16   numItems;
    Employee list[numItems];
};

second version zs content:


struct Employee
{
    uint8           age : age <= 65; // max age is 65
    string          name;
    uint16          salary;
    Role            role;
    // if employee is a developer, list programming skill
    Experience      skills[] if role == Role.DEVELOPER;

    optional uint16 bonus;
};

struct Experience
{
    bit:6       yearsOfExperience;
    Language    programmingLanguage;
};

enum bit:2 Language
{
    CPP     = 0,
    JAVA    = 1,
    PYTHON  = 2,
    JS      = 3
};

enum uint8 Role
{
    DEVELOPER = 0,
    TEAM_LEAD = 1,
    CTO       = 2
};

struct ArrayEmployee
{
    int16   numItems;
    Employee list[numItems];
};

problem description:

  1. serialize array employee used second version zs
  2. deserialize array employee used first version zs
  3. raise zserio.PythonRuntimeException
  4. How to solve the problem?
  5. How to keep backward-compatible?
@mikir
Copy link
Contributor

mikir commented Oct 11, 2021

I think the problem is that optional put hidden boolean to the serialized bytes. This hidden bit should be reflected in the first version as well:

struct Employee
{
    uint8           age : age <= 65; // max age is 65
    string          name;
    uint16          salary;
    Role            role;
    // if employee is a developer, list programming skill
    Experience      skills[] if role == Role.DEVELOPER;
    bool            hasBonus; // should be always false in the first version
};

More info about hidden data in zserio can be found here.

I hope, it helps.

@sduwall
Copy link
Author

sduwall commented Oct 15, 2021

thank you for your answer. but this has a problem, because the first version dose not know the hasBonus.

@mikir
Copy link
Contributor

mikir commented Oct 15, 2021

This should not be a problem because hasBonus should be always set to false. It can be renamed to dummy as well:

struct Employee
{
    uint8           age : age <= 65; // max age is 65
    string          name;
    uint16          salary;
    Role            role;
    // if employee is a developer, list programming skill
    Experience      skills[] if role == Role.DEVELOPER;
    bool            dummy; // should be always false in the first version
};

@sduwall
Copy link
Author

sduwall commented Oct 18, 2021

Thank you for your answer.

This maybe cannot solve the problem, because i cannot know the hasBonus field. After several months, this field needs to be added according to business needs. But now the first version has been sent out and cannot be modified. So reading the latest data with the first version engine will crash.

@mikir
Copy link
Contributor

mikir commented Oct 18, 2021

OK, I see. Unfortunately, there is currently no solution for that.

However, we have an issue in backlog because of that: ndsev/zserio#43. You might put there some requirements.

@sduwall
Copy link
Author

sduwall commented Oct 18, 2021

OK, thank you for your timely answer too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants