Example usage for io.netty.buffer ByteBuf writeInt

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

Introduction

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

Prototype

public abstract ByteBuf writeInt(int value);

Source Link

Document

Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

From source file:com.friz.update.network.codec.UpdateEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, FileResponseEvent msg, ByteBuf buffer) throws Exception {
    ByteBuf container = msg.getContainer();
    int type = msg.getType();
    int file = msg.getFile();

    if (!msg.isPriority())
        file |= 0x80000000;/*from  w  ww  . j a  va  2s  . c  o m*/

    buffer.writeByte(type);
    buffer.writeInt(file);

    int bytes = container.readableBytes();
    if (bytes > BYTES_AFTER_HEADER)
        bytes = BYTES_AFTER_HEADER;

    buffer.writeBytes(container.readBytes(bytes));

    for (;;) {
        bytes = container.readableBytes();
        if (bytes == 0)
            break;
        else if (bytes > BYTES_AFTER_HEADER)
            bytes = BYTES_AFTER_HEADER;

        buffer.writeByte(type);
        buffer.writeInt(file);
        buffer.writeBytes(container.readBytes(bytes));
    }
}

From source file:com.friz.update.network.codec.UpdateInitEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, UpdateResponseEvent msg, ByteBuf out) throws Exception {
    out.writeByte(msg.getStatus());// ww  w  . ja v  a  2 s  .  co m
    if (msg.getStatus() == UpdateResponseEvent.STATUS_OK) {
        for (int i = 0; i < PERCENT_DELTA.length; i++) {
            out.writeInt(PERCENT_DELTA[i]);
        }
    }
}

From source file:com.github.milenkovicm.kafka.protocol.Convert.java

License:Apache License

public static void encodeInteger(int integer, ByteBuf buf) {
    buf.writeInt(integer);
}

From source file:com.github.mrstampy.pprspray.core.streamer.footer.MediaFooter.java

License:Open Source License

private byte[] buildFooter() {
    ByteBuf buf = Unpooled.buffer(MediaStreamerUtils.FOOTER_LENGTH);

    buf.writeBytes(getType().eomBytes());
    buf.writeInt(getMessageHash());
    buf.writeInt(getMediaHash());/*from   ww  w .  jav  a  2 s .com*/

    return buf.array();
}

From source file:com.github.mrstampy.pprspray.core.streamer.MediaStreamType.java

License:Open Source License

private void setEomBytes() {
    int eomOrdinal = Integer.MAX_VALUE - ordinal();

    ByteBuf buf = Unpooled.buffer(4);
    buf.writeInt(eomOrdinal);
    eomBytes = buf.array();/*www .ja  v  a  2 s. c o m*/
}

From source file:com.github.mrstampy.pprspray.core.streamer.MediaStreamType.java

License:Open Source License

private void setOrdinalBytes() {
    ByteBuf buf = Unpooled.buffer(4);
    buf.writeInt(ordinal());
    ordinalBytes = buf.array();
}

From source file:com.github.mrstampy.pprspray.core.streamer.text.AbstractMetaTextChunkProcessor.java

License:Open Source License

protected void appendToHeader(Streamer<?> streamer, ByteBuf buf, int headerLength) {
    buf.writeBytes(headerKey);/*from www. j  a  v  a2 s  .  co  m*/
    buf.writeInt(getMarshallingClassHash());
}

From source file:com.github.mrstampy.pprspray.core.streamer.util.MediaStreamerUtils.java

License:Open Source License

/**
 * Write header./*  w w w . ja  va2 s  .c  o m*/
 *
 * @param buf
 *          the buf
 * @param type
 *          the type
 * @param headerLength
 *          the header length
 * @param messageHash
 *          the message hash
 * @param mediaHash
 *          the media hash
 * @param sequence
 *          the sequence
 * @param ackRequired
 *          the ack required
 */
public static void writeHeader(ByteBuf buf, MediaStreamType type, int headerLength, int messageHash,
        int mediaHash, long sequence, boolean ackRequired) {
    buf.writeBytes(type.ordinalBytes());
    buf.writeShort(headerLength);
    buf.writeInt(messageHash);
    buf.writeInt(mediaHash);
    buf.writeLong(sequence);
    buf.writeBoolean(ackRequired);
}

From source file:com.github.spapageo.jannel.channel.ChannelBufferUtils.java

License:Open Source License

/**
 * Writes a string to output buffer using the specified encoding
 * @param input the input string// w w w.  ja v a2  s  .  c  om
 * @param output the output buffer
 * @param charset the charset to use in order to encode the string
 */
public static void writeStringToOctetString(@Nullable String input, ByteBuf output, Charset charset) {
    if (input == null) {
        output.writeInt(-1);
        return;
    }

    byte[] bytes = input.getBytes(charset);
    output.writeInt(bytes.length);
    output.writeBytes(bytes);
}

From source file:com.github.spapageo.jannel.channel.ChannelBufferUtils.java

License:Open Source License

/**
 * Writes a byte array to output buffer//from w w w .j av  a  2s.  c  om
 * @param input the input byte array
 * @param output the output buffer
 */
public static void writeBytesToOctetString(@Nullable ByteBuf input, ByteBuf output) {
    if (input == null) {
        output.writeInt(-1);
        return;
    }

    output.writeInt(input.readableBytes());
    output.writeBytes(input);
}