8000 Extension preserving compatibility · Issue #52 · atomix/catalyst · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 15, 2018. It is now read-only.
This repository was archived by the owner on Apr 15, 2018. It is now read-only.
Extension preserving compatibility #52
Open
@mnicky

Description

@mnicky

Is there any support for extension of serializable data structures that preserves compatibility?

Let's say I have a class that looks like this:

class Data implements CatalystSerializable {

  private String data;

  public void writeObject(BufferOutput<?> buffer, Serializer serializer) {
    buffer.writeString(data);
  }

  public void readObject(BufferInput<?> buffer, Serializer serializer) {
    data = buffer.readString();
  }

...and I work with lists of them (e.g. ArrayList<Data>). Now I want to add another field, let's say boolean anotherField.

The problem I ran into is, how to migrate the data to the newer type. First, I wanted to do something like this:

  public void readObject(BufferInput<?> buffer, Serializer serializer) {
    data = buffer.readString();
    anotherField = buffer.hasRemaining() ? buffer.readBoolean() : false;
  }

...to preserve compatibility, but then I found out that Catalyst doesn't guarantee that hasRemaining() works as expected. And indeed, it didn't work when deserializing ArrayList<Data>. hasRemaining() was returning true also for the Data without anotherField, because there were probably another elements from the same array in the buffer. What's worse, it caused ArrayListSerializer to be misaligned (not on the borders of the elements in the list) and when it tried to deserialize another element, it blew up :)

Is there any way for me to find out whether I have the old Data structure (without anotherField) or not, and act accordingly?

I'd expect that the Catalyst could do the work for me and wrap the elements so that I receive just the one I'm trying to deserialize or at least provide me a way to determine whether there are any data left from the current element in the buffer.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0