Skip to content

Commit

Permalink
Check for overlapping tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Keese authored and Darren Keese committed Jul 8, 2016
1 parent b6847be commit bfd71b9
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
* <code>@Tag</code> annotation must remain in the class. Deprecated fields can optionally be made private and/or renamed so they
* don't clutter the class (eg, <code>ignored</code>, <code>ignored2</code>). For these reasons, TaggedFieldSerializer generally
* provides more flexibility for classes to evolve. The downside is that it has a small amount of additional overhead compared to
* VersionFieldSerializer (an additional varint per field). Forward compatibility is not supported.
* VersionFieldSerializer (an additional varint per field). Forward compatibility is supported only if
* {@link #setIgnoreUnknownTags(boolean)} is set to true.
* <p>Tag values must be entirely unique, even among a class and its superclass(es).
* @see VersionFieldSerializer
* @author Nathan Sweet <misc@n4te.com> */
public class TaggedFieldSerializer<T> extends FieldSerializer<T> {
Expand All @@ -56,10 +58,7 @@ public TaggedFieldSerializer (Kryo kryo, Class type) {

/** Tells Kryo, if should ignore unknown field tags when using TaggedFieldSerializer. Already existing serializer instances
* are not affected by this setting.
*
* <p>
* By default, Kryo will throw KryoException if encounters unknown field tags.
* </p>
* <p> By default, Kryo will throw KryoException if it encounters unknown field tags.
*
* @param ignoreUnknownTags if true, unknown field tags will be ignored. Otherwise KryoException will be thrown */
public void setIgnoreUnknownTags (boolean ignoreUnknownTags) {
Expand Down Expand Up @@ -96,6 +95,8 @@ public int compare(CachedField o1, CachedField o2) {
for (int i = 0, n = fields.length; i < n; i++) {
Field field = fields[i].getField();
tags[i] = field.getAnnotation(Tag.class).value();
if (i > 0 && tags[i] == tags[i-1]) //check relies on fields being sorted
throw new KryoException(String.format("The fields [%s] and [%s] both have a tag value of %d.", field, fields[i-1].getField(), tags[i]));
if (field.getAnnotation(Deprecated.class) != null) {
deprecated[i] = true;
writeFieldCount--;
Expand Down

0 comments on commit bfd71b9

Please sign in to comment.