ctubbsii commented on a change in pull request #2224:
URL: https://github.com/apache/accumulo/pull/2224#discussion_r683943792



##########
File path: 
server/base/src/main/java/org/apache/accumulo/server/conf/codec/EncodingOptions.java
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.server.conf.codec;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.StringJoiner;
+
+/**
+ * Serialization metadata to allow for evolution of the encoding used for 
property storage. This
+ * info is expected to be stored first in the serialization and uncompressed 
so that the handling of
+ * subsequent fields and data can be processed correctly.
+ * <p>
+ * Instances of this class are immutable.
+ */
+public class EncodingOptions {
+
+  public static final EncodingOptions COMPRESSED_V1 =
+      new EncodingOptions(EncodingOptions.EncodingVersion.V1_0, true);
+
+  public static final EncodingOptions UNCOMPRESSED_V1 =
+      new EncodingOptions(EncodingOptions.EncodingVersion.V1_0, false);
+
+  private final EncodingVersion encodingVersion;
+  private final boolean compress;
+
+  public EncodingOptions(EncodingVersion encodingVersion, final boolean 
compress) {
+    this.encodingVersion = encodingVersion;
+    this.compress = compress;
+  }
+
+  public EncodingOptions(final DataInputStream dis) throws IOException {
+    encodingVersion = EncodingVersion.byId(dis.readInt());
+    compress = dis.readBoolean();
+  }
+
+  public void encode(final DataOutputStream dos) throws IOException {
+    dos.writeInt(encodingVersion.id);
+    dos.writeBoolean(compress);
+  }
+
+  public EncodingVersion getEncodingVersion() {
+    return encodingVersion;
+  }
+
+  public boolean isCompressed() {
+    return compress;
+  }
+
+  @Override
+  public String toString() {
+    return new StringJoiner(", ", EncodingOptions.class.getSimpleName() + "[", 
"]")
+        .add("encodingVersion=" + encodingVersion).toString();
+  }
+
+  /**
+   * Provides a strong typing of the known encoding versions and allows the 
version id to be encoded
+   * as an integer. Adding an encoding type must be done as an addition and 
not change or delete
+   * previous versions or numbering to preserve compatibility.
+   */
+  public enum EncodingVersion {

Review comment:
       What about just using constants for convenience names? Also, an integer 
might work better in future if you have an implementation that is compatible 
with a range of previous versions. Checking ranges for integers might be easier 
in that case than enumerating a set of versions by name.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to