ibessonov commented on a change in pull request #566:
URL: https://github.com/apache/ignite-3/pull/566#discussion_r789645885



##########
File path: 
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/util/PageUtils.java
##########
@@ -0,0 +1,255 @@
+/*
+ * 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.ignite.internal.pagememory.util;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+
+/**
+ * Page utils.
+ */
+public class PageUtils {
+    /**
+     * Reads a byte from the memory.
+     *
+     * @param addr Start address.
+     * @param off  Offset.
+     * @return Byte value from given address.
+     */
+    public static byte getByte(long addr, int off) {
+        assert addr > 0 : addr;
+        assert off >= 0;
+
+        return GridUnsafe.getByte(addr + off);
+    }
+
+    /**
+     * Reads an unsigned byte from the memory.
+     *
+     * @param addr Start address.
+     * @param off  Offset.
+     * @return Byte value from given address.
+     */
+    public static int getUnsignedByte(long addr, int off) {
+        assert addr > 0 : addr;
+        assert off >= 0;
+
+        return GridUnsafe.getByte(addr + off) & 0xFF;
+    }
+
+    /**
+     * Reads a byte array from the memory.
+     *
+     * @param addr Start address.
+     * @param off  Offset.
+     * @param len  Bytes length.
+     * @return Bytes from given address.
+     */
+    public static byte[] getBytes(long addr, int off, int len) {
+        assert addr > 0 : addr;
+        assert off >= 0;
+        assert len >= 0;
+
+        byte[] bytes = new byte[len];
+
+        GridUnsafe.copyMemory(null, addr + off, bytes, 
GridUnsafe.BYTE_ARR_OFF, len);
+
+        return bytes;
+    }
+
+    /**
+     * Reads a byte array from the memory.
+     *
+     * @param srcAddr Source address.
+     * @param srcOff  Source offset.
+     * @param dst     Destination array.
+     * @param dstOff  Destination offset.
+     * @param len     Length.
+     */
+    public static void getBytes(long srcAddr, int srcOff, byte[] dst, int 
dstOff, int len) {
+        assert srcAddr > 0;
+        assert srcOff > 0;
+        assert dst != null;
+        assert dstOff >= 0;
+        assert len >= 0;
+
+        GridUnsafe.copyMemory(null, srcAddr + srcOff, dst, 
GridUnsafe.BYTE_ARR_OFF + dstOff, len);
+    }
+
+    /**
+     * Reads a short value from the memory.
+     *
+     * @param addr Address.
+     * @param off  Offset.
+     * @return Value.
+     */
+    public static short getShort(long addr, int off) {
+        assert addr > 0 : addr;
+        assert off >= 0;
+
+        return GridUnsafe.getShort(addr + off);
+    }
+
+    /**
+     * Reads an int value from the memory.
+     *
+     * @param addr Address.
+     * @param off  Offset.
+     * @return Value.
+     */
+    public static int getInt(long addr, int off) {
+        assert addr > 0 : addr;
+        assert off >= 0;
+
+        return GridUnsafe.getInt(addr + off);
+    }
+
+    /**
+     * Reads a long value from the memory.
+     *
+     * @param addr Address.
+     * @param off  Offset.
+     * @return Value.
+     */
+    public static long getLong(long addr, int off) {
+        assert addr > 0 : addr;
+        assert off >= 0;
+
+        return GridUnsafe.getLong(addr + off);
+    }
+
+    /**
+     * Writes a byte array into the memory.
+     *
+     * @param addr  Address.
+     * @param off   Offset.
+     * @param bytes Bytes.
+     */
+    public static void putBytes(long addr, int off, byte[] bytes) {
+        assert addr > 0 : addr;
+        assert off >= 0;
+        assert bytes != null;
+
+        GridUnsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF, null, addr + 
off, bytes.length);
+    }
+
+    /**
+     * Writes a byte array into the memory.
+     *
+     * @param addr     Address.
+     * @param off      Offset.
+     * @param bytes    Bytes array.
+     * @param bytesOff Bytes array offset.
+     */
+    public static void putBytes(long addr, int off, byte[] bytes, int 
bytesOff) {
+        assert addr > 0 : addr;
+        assert off >= 0;
+        assert bytes != null;
+        assert bytesOff >= 0 && (bytesOff < bytes.length || bytes.length == 0) 
: bytesOff;
+
+        GridUnsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF + bytesOff, null, 
addr + off, bytes.length - bytesOff);

Review comment:
       What exactly do you mean?




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