rdblue commented on code in PR #4537:
URL: https://github.com/apache/iceberg/pull/4537#discussion_r847673771


##########
core/src/main/java/org/apache/iceberg/stats/StatsFormat.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.iceberg.stats;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import io.airlift.compress.Compressor;
+import io.airlift.compress.lz4.Lz4Compressor;
+import io.airlift.compress.lz4.Lz4Decompressor;
+import io.airlift.compress.zstd.ZstdCompressor;
+import io.airlift.compress.zstd.ZstdDecompressor;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.math.BigInteger;
+import java.util.Arrays;
+import org.apache.commons.codec.binary.Base16;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+final class StatsFormat {
+  private StatsFormat() {
+  }
+
+  static final int CURRENT_FORMAT_VERSION = 1;
+
+  private static final byte[] MAGIC = new Base16().decode("50464953");
+  static final int MAGIC_AS_NUMBER_LE = new 
BigInteger(swap(MAGIC)).intValueExact();
+
+  static final int SUPPORTED_FLAGS = 0b1;
+  static final int FLAG_COMPRESSED = 0b1;
+
+  // TODO use LZ4 with frames, see 
https://trinodb.slack.com/archives/CP1MUNEUX/p1649676596198729
+  @Deprecated
+  static final int LZ4_UNCOMPRESSED_MAX_SIZE = 1024 * 1024;
+
+  // Not using JsonUtil.mapper() to avoid changing all JSON parsing
+  static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
+      .registerModule(new Jdk8Module());
+
+  static byte[] getMagic() {
+    return MAGIC.clone();
+  }
+
+  static void writeIntegerLittleEndian(OutputStream outputStream, int value) 
throws IOException {
+    outputStream.write(0xFF & value);
+    outputStream.write(0xFF & value >> 8);
+    outputStream.write(0xFF & value >> 16);
+    outputStream.write(0xFF & value >> 24);
+  }
+
+  static int readIntegerLittleEndian(byte[] data, int offset) {
+    return Byte.toUnsignedInt(data[offset]) |
+        (Byte.toUnsignedInt(data[offset + 1]) << 8) |
+        (Byte.toUnsignedInt(data[offset + 2]) << 16) |
+        (Byte.toUnsignedInt(data[offset + 3]) << 24);
+  }
+
+  static byte[] compressFooterPayload(byte[] payload) {

Review Comment:
   We don't generally work with `byte[]`, especially with no offset or length, 
because it requires new allocations all the time. Can these work with 
`ByteBuffer` instead?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to