You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2021/10/21 01:21:10 UTC

[datasketches-cpp] branch tuple_serial_ver3 created (now 788d17e)

This is an automated email from the ASF dual-hosted git repository.

alsay pushed a change to branch tuple_serial_ver3
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git.


      at 788d17e  tuple serial version 3 for compatibility with Java

This branch includes the following new commits:

     new 788d17e  tuple serial version 3 for compatibility with Java

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org


[datasketches-cpp] 01/01: tuple serial version 3 for compatibility with Java

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch tuple_serial_ver3
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git

commit 788d17e56b22bcc1bc5de803346f982fd1b07572
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Wed Oct 20 18:20:55 2021 -0700

    tuple serial version 3 for compatibility with Java
---
 tuple/include/tuple_sketch.hpp      |  6 ++++--
 tuple/include/tuple_sketch_impl.hpp | 20 ++++++++++++++++----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/tuple/include/tuple_sketch.hpp b/tuple/include/tuple_sketch.hpp
index db3f359..14d3871 100644
--- a/tuple/include/tuple_sketch.hpp
+++ b/tuple/include/tuple_sketch.hpp
@@ -365,9 +365,11 @@ public:
   using vector_bytes = std::vector<uint8_t, AllocBytes>;
   using comparator = compare_by_key<ExtractKey>;
 
-  static const uint8_t SERIAL_VERSION = 1;
+  static const uint8_t SERIAL_VERSION_LEGACY = 1;
+  static const uint8_t SERIAL_VERSION = 3;
   static const uint8_t SKETCH_FAMILY = 9;
-  static const uint8_t SKETCH_TYPE = 5;
+  static const uint8_t SKETCH_TYPE = 1;
+  static const uint8_t SKETCH_TYPE_LEGACY = 5;
   enum flags { IS_BIG_ENDIAN, IS_READ_ONLY, IS_EMPTY, IS_COMPACT, IS_ORDERED };
 
   // Instances of this type can be obtained:
diff --git a/tuple/include/tuple_sketch_impl.hpp b/tuple/include/tuple_sketch_impl.hpp
index bd14ca7..fdd91f8 100644
--- a/tuple/include/tuple_sketch_impl.hpp
+++ b/tuple/include/tuple_sketch_impl.hpp
@@ -439,9 +439,15 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(std::istream&
   read<uint8_t>(is); // unused
   const auto flags_byte = read<uint8_t>(is);
   const auto seed_hash = read<uint16_t>(is);
-  checker<true>::check_serial_version(serial_version, SERIAL_VERSION);
+  if (serial_version != SERIAL_VERSION && serial_version != SERIAL_VERSION_LEGACY) {
+    throw std::invalid_argument("serial version mismatch: expected " + std::to_string(SERIAL_VERSION) + " or "
+        + std::to_string(SERIAL_VERSION_LEGACY) + ", actual " + std::to_string(serial_version));
+  }
   checker<true>::check_sketch_family(family, SKETCH_FAMILY);
-  checker<true>::check_sketch_type(type, SKETCH_TYPE);
+  if (type != SKETCH_TYPE && type != SKETCH_TYPE_LEGACY) {
+    throw std::invalid_argument("sketch type mismatch: expected " + std::to_string(SKETCH_TYPE) + " or "
+        + std::to_string(SKETCH_TYPE_LEGACY) + ", actual " + std::to_string(type));
+  }
   const bool is_empty = flags_byte & (1 << flags::IS_EMPTY);
   if (!is_empty) checker<true>::check_seed_hash(seed_hash, compute_seed_hash(seed));
 
@@ -494,9 +500,15 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(const void* b
   ptr += copy_from_mem(ptr, flags_byte);
   uint16_t seed_hash;
   ptr += copy_from_mem(ptr, seed_hash);
-  checker<true>::check_serial_version(serial_version, SERIAL_VERSION);
+  if (serial_version != SERIAL_VERSION && serial_version != SERIAL_VERSION_LEGACY) {
+    throw std::invalid_argument("serial version mismatch: expected " + std::to_string(SERIAL_VERSION) + " or "
+        + std::to_string(SERIAL_VERSION_LEGACY) + ", actual " + std::to_string(serial_version));
+  }
   checker<true>::check_sketch_family(family, SKETCH_FAMILY);
-  checker<true>::check_sketch_type(type, SKETCH_TYPE);
+  if (type != SKETCH_TYPE && type != SKETCH_TYPE_LEGACY) {
+    throw std::invalid_argument("sketch type mismatch: expected " + std::to_string(SKETCH_TYPE) + " or "
+        + std::to_string(SKETCH_TYPE_LEGACY) + ", actual " + std::to_string(type));
+  }
   const bool is_empty = flags_byte & (1 << flags::IS_EMPTY);
   if (!is_empty) checker<true>::check_seed_hash(seed_hash, compute_seed_hash(seed));
 

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org