diff options
author | Yang Song <songy23@users.noreply.github.com> | 2017-12-13 09:30:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-13 09:30:35 -0800 |
commit | 14152dfdb8be40808e437b46f107907c6538ca81 (patch) | |
tree | ea2e3ab160883f7ce178473c593ae8fd24367cf1 /impl_core | |
parent | 3ba71b610dc172db098299d4a5210cb81e4e0095 (diff) | |
download | opencensus-java-14152dfdb8be40808e437b46f107907c6538ca81.tar.gz |
Support previous encoding versions. (#901)
Diffstat (limited to 'impl_core')
2 files changed, 10 insertions, 3 deletions
diff --git a/impl_core/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java b/impl_core/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java index 756aeb5d..2daad95e 100644 --- a/impl_core/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java +++ b/impl_core/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java @@ -103,9 +103,9 @@ final class SerializationUtils { ByteBuffer buffer = ByteBuffer.wrap(bytes).asReadOnlyBuffer(); int versionId = buffer.get(); - if (versionId != VERSION_ID) { + if (versionId > VERSION_ID || versionId < 0) { throw new TagContextDeserializationException( - "Wrong Version ID: " + versionId + ". Currently supported version is: " + VERSION_ID); + "Wrong Version ID: " + versionId + ". Currently supports version up to: " + VERSION_ID); } return new TagContextImpl(parseTags(buffer)); } catch (BufferUnderflowException exn) { diff --git a/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java b/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java index c465ee94..8db0e389 100644 --- a/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java +++ b/impl_core/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java @@ -296,10 +296,17 @@ public class TagContextDeserializationTest { @Test public void testDeserializeWrongVersionId() throws TagContextDeserializationException { thrown.expect(TagContextDeserializationException.class); - thrown.expectMessage("Wrong Version ID: 1. Currently supported version is: 0"); + thrown.expectMessage("Wrong Version ID: 1. Currently supports version up to: 0"); serializer.fromByteArray(new byte[] {(byte) (SerializationUtils.VERSION_ID + 1)}); } + @Test + public void testDeserializeNegativeVersionId() throws TagContextDeserializationException { + thrown.expect(TagContextDeserializationException.class); + thrown.expectMessage("Wrong Version ID: -1. Currently supports version up to: 0"); + serializer.fromByteArray(new byte[] {(byte) -1}); + } + // <tag_encoding> == // <tag_key_len><tag_key><tag_val_len><tag_val> // <tag_key_len> == varint encoded integer |