Example usage for io.netty.buffer ByteBuf writeZero

List of usage examples for io.netty.buffer ByteBuf writeZero

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeZero.

Prototype

public abstract ByteBuf writeZero(int length);

Source Link

Document

Fills this buffer with NUL (0x00) starting at the current writerIndex and increases the writerIndex by the specified length .

Usage

From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java

License:Open Source License

/**
 * Writes unsigned 64-bit integer <code>value</code> if not null, otherwise
 * writes zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is
 * increased by 8.//w w w  .  jav a  2 s .  c  o m
 *
 * @param value
 *            BigInteger value to be written to the output.
 * @param output
 *            ByteBuf, where value or zeros are written.
 */
public static void writeUnsignedLong(final BigInteger value, final ByteBuf output) {
    if (value != null) {
        output.writeLong(value.longValue());
    } else {
        output.writeZero(LONG_BYTES_LENGTH);
    }
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java

License:Open Source License

/**
 * Writes IPv4 address if not null, otherwise writes zeros to the
 * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
 *
 * @param ipv4Address/*from   w ww  .j a  va  2 s.co  m*/
 *            IPv4 address to be written to the output.
 * @param output
 *            ByteBuf, where ipv4Address or zeros are written.
 */
public static void writeIpv4Address(final Ipv4Address ipv4Address, final ByteBuf output) {
    if (ipv4Address != null) {
        output.writeBytes(Ipv4Util.bytesForAddress(ipv4Address));
    } else {
        output.writeZero(Ipv4Util.IP4_LENGTH);
    }
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java

License:Open Source License

/**
 * Writes IPv4 prefix if not null, otherwise writes zeros to the
 * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 5.
 *
 * @param ipv4Prefix//from w  w w. j  a  v a  2  s.co  m
 *            IPv4 prefix value to be written to the output. Prefix is
 *            written in the last byte.
 * @param output
 *            ByteBuf, where ipv4Prefix or zeros are written.
 */
public static void writeIpv4Prefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
    if (ipv4Prefix != null) {
        output.writeBytes(Ipv4Util.bytesForPrefix(ipv4Prefix));
    } else {
        output.writeZero(IPV4_PREFIX_BYTE_LENGTH);
    }
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java

License:Open Source License

/**
 * Writes IPv6 address if not null, otherwise writes zeros to the
 * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
 *
 * @param ipv6Address/*from w  ww  .j  av a 2s . com*/
 *            IPv6 address to be written to the output.
 * @param output
 *            ByteBuf, where ipv6Address or zeros are written.
 */
public static void writeIpv6Address(final Ipv6Address ipv6Address, final ByteBuf output) {
    if (ipv6Address != null) {
        output.writeBytes(Ipv6Util.bytesForAddress(ipv6Address));
    } else {
        output.writeZero(Ipv6Util.IPV6_LENGTH);
    }
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java

License:Open Source License

/**
 * Writes IPv6 prefix if not null, otherwise writes zeros to the
 * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 17.
 *
 * @param ipv6Prefix// www.  j  a v a2s .  co  m
 *            IPv6 prefix to be written to the output. Prefix is written in
 *            the last byte.
 * @param output
 *            ByteBuf, where ipv6Prefix or zeros are written.
 */
public static void writeIpv6Prefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
    if (ipv6Prefix != null) {
        output.writeBytes(Ipv6Util.bytesForPrefix(ipv6Prefix));
    } else {
        output.writeZero(IPV6_PREFIX_BYTE_LENGTH);
    }
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java

License:Open Source License

/**
 * Writes Float32 <code>value</code> if not null, otherwise writes zeros to
 * the <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
 *
 * @param value/*  w ww. j av  a 2  s.co  m*/
 *            Float32 value to be written to the output.
 * @param output
 *            ByteBuf, where value or zeros are written.
 */
public static void writeFloat32(final Float32 value, final ByteBuf output) {
    if (value != null) {
        output.writeBytes(value.getValue());
    } else {
        output.writeZero(FLOAT32_BYTES_LENGTH);
    }
}

From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java

License:Open Source License

/**
 * Writes BitSet's bits if not null, otherwise writes zeros to the
 * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by
 * specified length.//from   w w w.j  a va 2 s.  c  o m
 *
 * @param bitSet
 *            BitSet values to be written to the output, starting from left most bit.
 * @param outputLength
 *            Number of bytes to be written, must be greater than 0.
 * @param output
 *            ByteBuf, where bitSet or zeros are written.
 */
public static void writeBitSet(final BitSet bitSet, final int outputLength, final ByteBuf output) {
    Preconditions.checkArgument(outputLength > 0);
    if (bitSet != null) {
        output.writeBytes(ByteArray.bitSetToBytes(bitSet, outputLength));
    } else {
        output.writeZero(outputLength);
    }
}

From source file:org.traccar.protocol.CastelProtocolEncoder.java

License:Apache License

private ByteBuf encodeContent(long deviceId, short type, ByteBuf content) {

    ByteBuf buf = Unpooled.buffer(0);
    String uniqueId = Context.getIdentityManager().getById(deviceId).getUniqueId();

    buf.writeByte('@');
    buf.writeByte('@');

    buf.writeShortLE(2 + 2 + 1 + 20 + 2 + content.readableBytes() + 2 + 2); // length

    buf.writeByte(1); // protocol version

    buf.writeBytes(uniqueId.getBytes(StandardCharsets.US_ASCII));
    buf.writeZero(20 - uniqueId.length());

    buf.writeShort(type);//from w w  w  .  ja v  a2  s .c o m
    buf.writeBytes(content);

    buf.writeShortLE(Checksum.crc16(Checksum.CRC16_X25, buf.nioBuffer()));

    buf.writeByte('\r');
    buf.writeByte('\n');

    return buf;
}

From source file:org.traccar.protocol.CellocatorProtocolDecoder.java

License:Apache License

private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) {
    if (channel != null) {
        ByteBuf reply = Unpooled.buffer(28);
        reply.writeByte('M');
        reply.writeByte('C');
        reply.writeByte('G');
        reply.writeByte('P');
        reply.writeByte(MSG_SERVER_ACKNOWLEDGE);
        reply.writeIntLE((int) deviceId);
        reply.writeByte(commandCount++);
        reply.writeIntLE(0); // authentication code
        reply.writeByte(0);/*from ww  w.  j  a  va2 s.  c o  m*/
        reply.writeByte(packetNumber);
        reply.writeZero(11);

        byte checksum = 0;
        for (int i = 4; i < 27; i++) {
            checksum += reply.getByte(i);
        }
        reply.writeByte(checksum);

        channel.writeAndFlush(new NetworkMessage(reply, remoteAddress));
    }
}

From source file:ru.jts_dev.authserver.util.Encoder.java

License:Open Source License

public ByteBuf appendChecksum(ByteBuf buf) {
    if (buf.readableBytes() % 4 != 0) {
        throw new IndexOutOfBoundsException("ByteBuf size must be multiply of 4");
    }//w w  w  .  j a v a2  s  .  co  m
    int checksum = 0;
    for (int i = 0; i < buf.readableBytes(); i += 4) {
        checksum ^= buf.getInt(i);
    }

    buf.writeInt(checksum);

    buf.writeZero(4); // for blowfish block

    return buf;
}