Example usage for io.netty.buffer ByteBuf writeByte

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

Introduction

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

Prototype

public abstract ByteBuf writeByte(int value);

Source Link

Document

Sets the specified byte at the current writerIndex and increases the writerIndex by 1 in this buffer.

Usage

From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

License:Open Source License

public static void writeFieldLength(ByteBuf buf, long length) {
    if (length < 251) {
        buf.writeByte((byte) length);
    } else if (length < 0x10000L) {
        buf.writeByte((byte) 252);
        writeUB2(buf, (int) length);
    } else if (length < 0x1000000L) {
        buf.writeByte((byte) 253);
        writeUB3(buf, (int) length);
    } else {// w ww. ja  v a 2 s . c  om
        buf.writeByte((byte) 254);
        writeLong(buf, length);
    }
}

From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

License:Open Source License

public static void writeLongLong(ByteBuf buf, long i) {
    buf.writeByte((byte) (i & 0xff));
    buf.writeByte((byte) (i >>> 8));
    buf.writeByte((byte) (i >>> 16));
    buf.writeByte((byte) (i >>> 24));
    buf.writeByte((byte) (i >>> 32));
    buf.writeByte((byte) (i >>> 40));
    buf.writeByte((byte) (i >>> 48));
    buf.writeByte((byte) (i >>> 56));
}

From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

License:Open Source License

public static final void writeWithLength(ByteBuf buffer, byte[] src, byte nullValue) {
    if (src == null) {
        buffer.writeByte(nullValue);
    } else {//w w  w .j  av a 2  s.c  o  m
        writeWithLength(buffer, src);
    }
}

From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

License:Open Source License

public static final void writeWithLength(ByteBuf buffer, byte[] src) {
    if (src == null || src.length == 0) {
        buffer.writeByte((byte) 0);
    } else {/* w  ww. j  a  v  a2 s .  c  o  m*/
        int length = src == null ? 0 : src.length;
        if (length < 251) {
            buffer.writeByte((byte) length);
        } else if (length < 0x10000L) {
            buffer.writeByte((byte) 252);
            writeUB2(buffer, length);
        } else if (length < 0x1000000L) {
            buffer.writeByte((byte) 253);
            writeUB3(buffer, length);
        } else {
            buffer.writeByte((byte) 254);
            writeLong(buffer, length);
        }
        buffer.writeBytes(src);
    }
}

From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

License:Open Source License

public static final void writeWithNull(ByteBuf buffer, byte[] src) {
    if (src != null) {
        buffer.writeBytes(src);//from  ww w. j  a v a  2  s  . c o m
    }
    buffer.writeByte((byte) 0);
}

From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

License:Open Source License

public static void writeString(ByteBuf buf, String s) {
    writeStringNoNull(buf, s);
    buf.writeByte(0);
}

From source file:com.basho.riak.client.core.netty.RiakHttpMessageHandlerTest.java

License:Apache License

@Test
public void notifiesListenerOnComplete() throws Exception {
    HttpResponse response = mock(HttpResponse.class);
    HttpResponseStatus status = mock(HttpResponseStatus.class);
    doReturn(status).when(response).getStatus();
    doReturn(200).when(status).code();/*from  w w  w .  j a  v a  2 s .  c  o m*/
    LastHttpContent lastContent = mock(LastHttpContent.class);
    ByteBuf bb = Unpooled.buffer();
    bb.writeByte((byte) 1);
    doReturn(bb).when(lastContent).data();
    handler.messageReceived(mockContext, response);
    handler.messageReceived(mockContext, lastContent);

    verify(mockListener).onSuccess(Matchers.any(Channel.class), Matchers.any(RiakHttpMessage.class));
}

From source file:com.basho.riak.client.core.netty.RiakHttpMessageHandlerTest.java

License:Apache License

@Test
public void removesSelfFromPipelineOnCompletion() throws Exception {
    HttpResponse response = mock(HttpResponse.class);
    HttpResponseStatus status = mock(HttpResponseStatus.class);
    doReturn(status).when(response).getStatus();
    doReturn(200).when(status).code();//from   w w  w .j a v  a  2 s  .  c  om
    LastHttpContent lastContent = mock(LastHttpContent.class);
    ByteBuf bb = Unpooled.buffer();
    bb.writeByte((byte) 1);
    doReturn(bb).when(lastContent).data();
    handler.messageReceived(mockContext, response);
    handler.messageReceived(mockContext, lastContent);

    verify(mockPipeline).remove(handler);
}

From source file:com.basho.riak.client.core.netty.RiakHttpMessageHandlerTest.java

License:Apache License

@Test
public void producesCorrectResponse() throws Exception {
    HttpResponse response = mock(HttpResponse.class);
    HttpResponseStatus status = mock(HttpResponseStatus.class);
    doReturn(status).when(response).getStatus();
    doReturn(200).when(status).code();//from w w  w. j av  a 2  s  .  co m
    HttpContent content = mock(HttpContent.class);
    LastHttpContent lastContent = mock(LastHttpContent.class);

    ByteBuf bb = Unpooled.buffer();
    bb.writeByte((byte) 1);
    doReturn(bb).when(content).data();
    doReturn(bb.copy()).when(lastContent).data();

    handler.messageReceived(mockContext, response);
    handler.messageReceived(mockContext, content);
    handler.messageReceived(mockContext, lastContent);

    RiakHttpMessage message = Whitebox.getInternalState(handler, "message");

    verify(mockListener).onSuccess(mockChannel, message);
    assertEquals(message.getResponse(), response);
    byte[] bytes = new byte[] { 1, 1 };
    assertArrayEquals(message.getContent(), bytes);
}

From source file:com.basho.riak.client.core.netty.RiakMessageCodec.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, RiakMessage msg, ByteBuf out) throws Exception {
    int length = msg.getData().length + 1;
    out.writeInt(length);/*from   ww w  .j  a va2  s  . c  om*/
    out.writeByte(msg.getCode());
    out.writeBytes(msg.getData());
}