0
votes

Originally, the program saves the data to file by its own defined behavior. First, the data is defined as following:

struct Data{
    DWORD       m_Location;
    BYTE        m_StableCount;
    BYTE        extra[3]; /* nice 4 byte divisible value */

    // the following data is not stored in the file
    DWORD       m_Uid;
    WORD        m_Address;
};

Those fields before m_Uid will be stored into file, however, the others does NOT.

Now, I want to convert the Data into protocol buffer message. As far as I know, all fields defined in the message can be serialized. So I have to split the Data into two parts: one including all saved fields, the other including the rest fields.

Here is my question: What if I declare all fields of Data in one message, and only serialize some partial fields in protocol buffer? Any API support it or NOT?

Thanks in advance.

1

1 Answers

0
votes

This largely depends on what library you are using. A lot of protocol buffers implementations work as code-gen from the schema, and you have to use the generated DTO - so you would already need to push the data into a different object model. That is an implementation detail, though - it isn't a protocol requirement. For example, protobuf-net allows your existing model to be used, and makes it possible to ignore/include values both generally, and specifically (i.e. it allows per-instance conditional serialization, using the standard conventions of the .NET world for such things). However, I'm assuming that your question relates specifically to non-.NET code, in which case the challenge would be to find a C/C++ library that allows for this approach.