yihua commented on code in PR #10241:
URL: https://github.com/apache/hudi/pull/10241#discussion_r1420974614


##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/ByteUtils.java:
##########
@@ -0,0 +1,244 @@
+/*
+ * 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.hudi.io.hfile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+public class ByteUtils {
+  /**
+   * Reads four bytes starting from the offset in the input and returns {@code 
int} value.
+   *
+   * @param bytes  Input byte array.
+   * @param offset Offset to start reading.
+   * @return The {@code int} value.
+   */
+  public static int readInt(byte[] bytes, int offset) {
+    return (((bytes[offset] & 0xff) << 24)
+        | ((bytes[offset + 1] & 0xff) << 16)
+        | ((bytes[offset + 2] & 0xff) << 8)
+        | (bytes[offset + 3] & 0xff));
+  }
+
+  /**
+   * Reads eight bytes starting from the offset in the input and returns 
{@code long} value.
+   *
+   * @param bytes  Input byte array.
+   * @param offset Offset to start reading.
+   * @return The {@code long} value.
+   */
+  public static long readLong(byte[] bytes, int offset) {
+    return (((long) (bytes[offset] & 0xff) << 56)
+        | ((long) (bytes[offset + 1] & 0xff) << 48)
+        | ((long) (bytes[offset + 2] & 0xff) << 40)
+        | ((long) (bytes[offset + 3] & 0xff) << 32)
+        | ((long) (bytes[offset + 4] & 0xff) << 24)
+        | ((long) (bytes[offset + 5] & 0xff) << 16)
+        | ((long) (bytes[offset + 6] & 0xff) << 8)
+        | (long) (bytes[offset + 7] & 0xff));
+  }
+
+  /**
+   * Reads two bytes starting from the offset in the input and returns {@code 
short} value.
+   *
+   * @param bytes  Input byte array.
+   * @param offset Offset to start reading.
+   * @return The {@code short} value.
+   */
+  public static short readShort(byte[] bytes, int offset) {
+    short n = 0;
+    n = (short) ((n ^ bytes[offset]) & 0xFF);
+    n = (short) (n << 8);
+    n ^= (short) (bytes[offset + 1] & 0xFF);
+    return n;
+  }
+
+  /**
+   * Parses the first byte of a vint/vlong to determine the number of bytes on 
disk.
+   *
+   * @param bytes  Input byte array.
+   * @param offset Offset to start reading.
+   * @return The total number of bytes (1 to 9) on disk.
+   */
+  public static int decodeVLongSizeOnDisk(byte[] bytes, int offset) {

Review Comment:
   It refers to variable-length integer.  Renamed to VarInt now.



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