Example usage for io.netty.util.internal PlatformDependent putByte

List of usage examples for io.netty.util.internal PlatformDependent putByte

Introduction

In this page you can find the example usage for io.netty.util.internal PlatformDependent putByte.

Prototype

public static void putByte(long address, byte value) 

Source Link

Usage

From source file:org.apache.activemq.artemis.core.io.mapped.BytesUtils.java

License:Apache License

public static void zerosDirect(final ByteBuffer buffer) {
    //DANGEROUS!! erases bound-checking using directly addresses -> safe only if it use counted loops
    int remaining = buffer.capacity();
    long address = PlatformDependent.directBufferAddress(buffer);
    while (remaining >= 8) {
        PlatformDependent.putLong(address, 0L);
        address += 8;//  w w w .ja  va 2s . c  o m
        remaining -= 8;
    }
    while (remaining > 0) {
        PlatformDependent.putByte(address, (byte) 0);
        address++;
        remaining--;
    }
}

From source file:org.apache.activemq.artemis.utils.UTF8Util.java

License:Apache License

private static int unsafeOffHeapWriteUTF(final CharSequence str, final long addressBytes, final int index,
        final int length) {
    int charCount = index;
    for (int i = 0; i < length; i++) {
        char charAtPos = str.charAt(i);
        if (charAtPos <= 0x7f) {
            PlatformDependent.putByte(addressBytes + charCount++, (byte) charAtPos);
        } else if (charAtPos >= 0x800) {
            PlatformDependent.putByte(addressBytes + charCount++, (byte) (0xE0 | charAtPos >> 12 & 0x0F));
            PlatformDependent.putByte(addressBytes + charCount++, (byte) (0x80 | charAtPos >> 6 & 0x3F));
            PlatformDependent.putByte(addressBytes + charCount++, (byte) (0x80 | charAtPos >> 0 & 0x3F));
        } else {// w  w w.j av  a 2s .  com
            PlatformDependent.putByte(addressBytes + charCount++, (byte) (0xC0 | charAtPos >> 6 & 0x1F));
            PlatformDependent.putByte(addressBytes + charCount++, (byte) (0x80 | charAtPos >> 0 & 0x3F));
        }
    }

    final int writtenBytes = (charCount - index);
    return writtenBytes;
}

From source file:org.apache.arrow.vector.DecimalVector.java

License:Apache License

/**
 * Set the decimal element at given index to the provided array of bytes.
 * Decimal is now implemented as Little Endian. This API allows the user
 * to pass a decimal value in the form of byte array in BE byte order.
 *
 * <p>Consumers of Arrow code can use this API instead of first swapping
 * the source bytes (doing a write and read) and then finally writing to
 * ArrowBuf of decimal vector.// w  w  w  .j  av a2s. co  m
 *
 * <p>This method takes care of adding the necessary padding if the length
 * of byte array is less then 16 (length of decimal type).
 *
 * @param index position of element
 * @param value array of bytes containing decimal in big endian byte order.
 */
public void setBigEndian(int index, byte[] value) {
    BitVectorHelper.setValidityBitToOne(validityBuffer, index);
    final int length = value.length;

    // do the bound check.
    valueBuffer.checkBytes(index * TYPE_WIDTH, (index + 1) * TYPE_WIDTH);

    long outAddress = valueBuffer.memoryAddress() + index * TYPE_WIDTH;
    // swap bytes to convert BE to LE
    for (int byteIdx = 0; byteIdx < length; ++byteIdx) {
        PlatformDependent.putByte(outAddress + byteIdx, value[length - 1 - byteIdx]);
    }

    if (length == TYPE_WIDTH) {
        return;
    }

    if (length == 0) {
        PlatformDependent.setMemory(outAddress, DecimalVector.TYPE_WIDTH, (byte) 0);
    } else if (length < TYPE_WIDTH) {
        // sign extend
        final byte pad = (byte) (value[0] < 0 ? 0xFF : 0x00);
        PlatformDependent.setMemory(outAddress + length, DecimalVector.TYPE_WIDTH - length, pad);
    } else {
        throw new IllegalArgumentException(
                "Invalid decimal value length. Valid length in [1 - 16], got " + length);
    }
}

From source file:org.apache.arrow.vector.DecimalVector.java

License:Apache License

/**
 * Sets the element at given index using the buffer whose size maybe <= 16 bytes.
 * @param index index to write the decimal to
 * @param start start of value in the buffer
 * @param buffer contains the decimal in big endian bytes
 * @param length length of the value in the buffer
 *//*  w ww.j  a va 2s  .  c om*/
public void setBigEndianSafe(int index, int start, ArrowBuf buffer, int length) {
    handleSafe(index);
    BitVectorHelper.setValidityBitToOne(validityBuffer, index);

    // do the bound checks.
    buffer.checkBytes(start, start + length);
    valueBuffer.checkBytes(index * TYPE_WIDTH, (index + 1) * TYPE_WIDTH);

    // not using buffer.getByte() to avoid boundary checks for every byte.
    long inAddress = buffer.memoryAddress() + start;
    long outAddress = valueBuffer.memoryAddress() + index * TYPE_WIDTH;
    // swap bytes to convert BE to LE
    for (int byteIdx = 0; byteIdx < length; ++byteIdx) {
        byte val = PlatformDependent.getByte((inAddress + length - 1) - byteIdx);
        PlatformDependent.putByte(outAddress + byteIdx, val);
    }
    // sign extend
    if (length < 16) {
        byte msb = PlatformDependent.getByte(inAddress);
        final byte pad = (byte) (msb < 0 ? 0xFF : 0x00);
        PlatformDependent.setMemory(outAddress + length, DecimalVector.TYPE_WIDTH - length, pad);
    }
}

From source file:org.apache.drill.exec.store.easy.text.compliant.RepeatedVarCharOutput.java

License:Apache License

@Override
public void append(byte data) {
    if (!collect) {
        return;/*  w w w . j a va 2s  . co  m*/
    }

    if (characterData >= characterDataMax) {
        expandVarCharData();
    }

    PlatformDependent.putByte(characterData, data);
    characterData++;

}

From source file:org.apache.tajo.tuple.memory.CompactRowBlockWriter.java

License:Apache License

/**
 * Encode and write a varint.  {@code value} is treated as
 * unsigned, so it won't be sign-extended if negative.
 *///  ww  w.  j  a  v a 2  s  . com
public static short writeRawVarint32(long address, int value) {
    short length = 0;
    while (true) {
        if ((value & ~0x7F) == 0) {
            PlatformDependent.putByte(address + length, (byte) value);
            length++;
            return length;
        } else {
            PlatformDependent.putByte(address + length, (byte) ((value & 0x7F) | 0x80));
            value >>>= 7;
            length++;
        }
    }
}

From source file:org.apache.tajo.tuple.memory.CompactRowBlockWriter.java

License:Apache License

/**
 * Encode and write a varint64./* w  w  w  . j  a  va  2  s .co m*/
 */
public static short writeRawVarint64(long address, long value) {
    short length = 0;
    while (true) {
        if ((value & ~0x7FL) == 0) {
            PlatformDependent.putByte(address + length, (byte) value);
            length++;
            return length;
        } else {
            PlatformDependent.putByte(address + length, (byte) ((value & 0x7F) | 0x80));
            value >>>= 7;
            length++;
        }
    }
}

From source file:org.apache.tajo.tuple.memory.CompactRowBlockWriter.java

License:Apache License

@Override
public void putByte(byte val) {
    ensureSize(SizeOf.SIZE_OF_BYTE);/* ww  w . j  a  va2s  .c  o m*/
    long addr = currentAddr();

    PlatformDependent.putByte(addr, val);
    curFieldIdx++;
    forwardField(SizeOf.SIZE_OF_BYTE);
}

From source file:org.apache.tajo.tuple.memory.OffHeapRowWriter.java

License:Apache License

@Override
public void putByte(byte val) {
    ensureSize(SizeOf.SIZE_OF_BYTE);/*from ww w . ja v  a2 s.com*/
    long addr = currentAddr();

    PlatformDependent.putByte(addr, val);
    putFieldHeader(addr, curOffset);
    forwardField(SizeOf.SIZE_OF_BYTE);
}

From source file:org.apache.tajo.tuple.memory.OffHeapRowWriter.java

License:Apache License

@Override
public void putBool(boolean val) {
    ensureSize(SizeOf.SIZE_OF_BOOL);//from   w w w.j  av a  2 s. c  o m
    long addr = currentAddr();

    PlatformDependent.putByte(addr, (byte) (val ? 0x01 : 0x00));
    putFieldHeader(addr, curOffset);
    forwardField(SizeOf.SIZE_OF_BOOL);
}