Skip to content

Add forward compatibility to TaggedFieldSerializer in issue #352. #365

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

Merged
merged 1 commit into from
Apr 10, 2016
Merged

Add forward compatibility to TaggedFieldSerializer in issue #352. #365

merged 1 commit into from
Apr 10, 2016

Conversation

levyfan
Copy link

@levyfan levyfan commented Nov 10, 2015

Add forward compatibility to TaggedFieldSerializer in issue #352.

Add ignoreUnknownTags flag in Kryo configuration. If it is set, TaggedFieldSerializer will ignore unknown field tags in input stream. Otherwise a KryoException will be thrown.

@magro
Copy link
Collaborator

magro commented Feb 2, 2016

LGTM. @NathanSweet @romix What do you think?

@psmarcos
Copy link

psmarcos commented Feb 3, 2016

+1

@magro
Copy link
Collaborator

magro commented Feb 20, 2016

@levyfan Can you adjust javadoc and the README to mention this improvement? I think then it's ok to merge. Thanks!

@levyfan
Copy link
Author

levyfan commented Mar 14, 2016

Thanks @magro , please have a review.

@fgaule
Copy link

fgaule commented Mar 16, 2016

Great to have this feature soon :)

@magro
Copy link
Collaborator

magro commented Mar 17, 2016

I've thought about the way of configuration and think we should choose a different approach: https://groups.google.com/forum/#!topic/kryo-users/G16daCijbWo

So if we merge this now the api might be changed before the release, or we wait until this is clarified / changed.

Apart from this, there are things currently holding back a release: https://groups.google.com/forum/#!topic/kryo-users/Fg0yCqZts6E

@psmarcos
Copy link

@magro @levyfan
The serializer fails when you add a field that is not sorted alphabetically. Example:

class NewRoot {
  @TaggedFieldSerializer.Tag(0)
  field b;
  @TaggedFieldSerializer.Tag(1)
  field a;
}

class Root {
 @TaggedFieldSerializer.Tag(0)
 field b;
}

If the serializer writes a byte stream with type NewRoot then it can't be read correctly into an object of type Root.

However if alphabetical order is maintained:

class NewRoot {
  @TaggedFieldSerializer.Tag(0)
  field b;
  @TaggedFieldSerializer.Tag(1)
  field c;
}

class Root {
 @TaggedFieldSerializer.Tag(0)
 field b;
}

The stream can be read correctly into an object of type Root .

Here's a file with tests
TaggedFieldSerializerTest.java.zip

@magro
Copy link
Collaborator

magro commented Mar 25, 2016

@levyfan @psmarcos Is anybody of you going to fix this? Good catch btw!

@levyfan
Copy link
Author

levyfan commented Mar 28, 2016

@magro @psmarcos fixed.
Now TaggedFieldSerializer will write from lowest tag to highest tag, for example, tag 0,1,2,...,N. If the reader do not have any information about tag i, then the stream from tag i will be ignored, i.e, tag i,i+1,...,N won't be read. (Because the reader do not know how many bytes tag i takes and what is the start point of tag i+1).

magro added a commit to magro/kryo that referenced this pull request Mar 28, 2016
The `Kryo` class is more and more used for "global" configuration of
serializers like `FieldSerializer` etc (here's another PR: EsotericSoftware#365).
The semantics of such settings and especially for which serializer
it's applied can often only be clarified via documentation.

This change introduces a `FieldSerializerConfig` class that encapsulates
configuration for `FieldSerializer`. It allows to configure settings
for all `FieldSerializer` instances created via `Kryo.getFieldSerializerConfig`.

`Kryo.asmEnabled` might be used by different serializers, but because until
now it was only used by `FieldSerializer` this setting is also kept in
`FieldSerializerConfig`. `Kryo.set/getAsmEnabled` is marked as deprecated
with a hint to use `getFieldSerializerConfig` instead - this is done to
stay binary compatible.

`Kryo.setCopyTransient` is removed because it was introduced after the
latest release 3.0.3 and therefore not yet a published/released. Now
`Kryo.getFieldSerializerConfig.setCopyTransient` has to be used.

If this is considered to be merged then EsotericSoftware#365 should also follow this
approach.
magro added a commit to magro/kryo that referenced this pull request Mar 28, 2016
The `Kryo` class is more and more used for "global" configuration of
serializers like `FieldSerializer` etc (here's another PR: EsotericSoftware#365).
The semantics of such settings and especially for which serializer
it's applied can often only be clarified via documentation.

This change introduces a `FieldSerializerConfig` class that encapsulates
configuration for `FieldSerializer`. It allows to configure settings
for all `FieldSerializer` instances created via `Kryo.getFieldSerializerConfig`.
On each `FieldSerializer` the config can be changed/overridden, this is
done directly on the serializer (instead e.g. requiring to invoke
`fieldSerializer.getConfig.setSomeThing`) to stay binary compatible and
because forcing to use the config here does not seem to be of much value.
The `FieldSerializer` internally uses the config object so that any further
settings are directly added to `FieldSerializerConfig` and there's only
a single place to keep config settings.

`Kryo.asmEnabled` might be used by different serializers, but because until
now it was only used by `FieldSerializer` this setting is also kept in
`FieldSerializerConfig`. `Kryo.set/getAsmEnabled` is marked as deprecated
with a hint to use `getFieldSerializerConfig` instead - this is done to
stay binary compatible.

`Kryo.setCopyTransient` is removed because it was introduced after the
latest release 3.0.3 and therefore not yet a published/released. Now
`Kryo.getFieldSerializerConfig.setCopyTransient` has to be used.

If this is considered to be merged then EsotericSoftware#365 should also follow this
approach.
magro added a commit to magro/kryo that referenced this pull request Mar 29, 2016
The `Kryo` class is more and more used for "global" configuration of
serializers like `FieldSerializer` etc (here's another PR: EsotericSoftware#365).
The semantics of such settings and especially for which serializer
it's applied can often only be clarified via documentation.

This change introduces a `FieldSerializerConfig` class that encapsulates
configuration for `FieldSerializer`. It allows to configure settings
for all `FieldSerializer` instances created via `Kryo.getFieldSerializerConfig`.
On each `FieldSerializer` the config can be changed/overridden, this is
done directly on the serializer (instead e.g. requiring to invoke
`fieldSerializer.getConfig.setSomeThing`) to stay binary compatible and
because forcing to use the config here does not seem to be of much value.
The `FieldSerializer` internally uses the config object so that any further
settings are directly added to `FieldSerializerConfig` and there's only
a single place to keep config settings.

`Kryo.asmEnabled` might be used by different serializers, but because until
now it was only used by `FieldSerializer` this setting is also kept in
`FieldSerializerConfig`. `Kryo.set/getAsmEnabled` is marked as deprecated
with a hint to use `getFieldSerializerConfig` instead - this is done to
stay binary compatible.

`Kryo.setCopyTransient` is removed because it was introduced after the
latest release 3.0.3 and therefore not yet a published/released. Now
`Kryo.getFieldSerializerConfig.setCopyTransient` has to be used.

If this is considered to be merged then EsotericSoftware#365 should also follow this
approach.
@levyfan
Copy link
Author

levyfan commented Apr 6, 2016

@magro please have a review

@levyfan levyfan closed this Apr 6, 2016
@levyfan levyfan reopened this Apr 6, 2016
@magro
Copy link
Collaborator

magro commented Apr 6, 2016

Because the ignoreUnknownTags setting doesn't make sense for FieldSerializer I'd prefer to have a TaggedFieldSerializerConfig (extending FieldSerializerConfig).

* </p>
*
* @param ignoreUnknownTags if true, unknown field tags will be ignored. Otherwise KryoException will be thrown */
public void setIgnoreUnknownTags (boolean ignoreUnknownTags) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go into TaggedFieldSerializer.

@levyfan
Copy link
Author

levyfan commented Apr 10, 2016

Thanks @magro , please have a review

@@ -70,7 +70,7 @@
/** type variables declared for this type */
final TypeVariable[] typeParameters;
final Class componentType;
private final FieldSerializerConfig config;
final FieldSerializerConfig config;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantically this should be protected probably, sorry that I haven't seen this last time.

@magro
Copy link
Collaborator

magro commented Apr 10, 2016

LGTM, only the one protected seems to be left. Can you squash commits to a single one? Then I'll merge. Thanks!

@levyfan
Copy link
Author

levyfan commented Apr 10, 2016

Hi @magro , please have a review

@magro magro merged commit 6483e86 into EsotericSoftware:master Apr 10, 2016
@magro
Copy link
Collaborator

magro commented Apr 10, 2016

Great, thanks a lot!

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

Successfully merging this pull request may close these issues.

4 participants