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.neoba.messages.DocumentDeleteMessage.java

public ByteBuf result() {
    ByteBuf reply = buffer(2 + 4);
    reply.writeByte(Constants.VERSION);/* w w  w .j a va  2 s  . c o m*/
    reply.writeByte(Constants.DOCUMENT_EDIT);

    if (!candelete) {
        reply.writeInt(Constants.W_ERR_UNPRIVILAGED_USER);
    } else if (!doc_exists) {
        reply.writeInt(Constants.W_ERR_DOCUMENT_NONEXISTANT);
    } else if (!push_success) {
        reply.writeInt(Constants.W_ERR_PUSH_FAILED);
    } else {
        reply.writeInt(Constants.W_SUCCESS);
    }
    return reply;
}

From source file:com.neoba.messages.GrantPermissionMessage.java

@Override
public ByteBuf result() {
    ByteBuf reply = buffer(6);
    reply.writeByte(Constants.VERSION);/*  w w  w .ja  v a  2  s  .  c om*/
    reply.writeByte(Constants.GRANT_PERMISSION);
    if (unfollowed_user) {
        reply.writeInt(Constants.W_ERR_SHARE_WITH_UNFOLLOWED_USER);
    } else if (unprivilaged) {
        reply.writeInt(Constants.W_ERR_UNPRIVILAGED_USER);
    } else if (!push_successn || !push_successw || !push_successr) {
        reply.writeInt(Constants.W_ERR_PUSH_FAILED);
    } else {
        reply.writeInt(Constants.W_SUCCESS);
    }
    return reply;
}

From source file:com.neoba.messages.NotLoggedInMessage.java

@Override
public ByteBuf result() {

    ByteBuf reply = buffer(6);
    reply.writeByte(Constants.VERSION);/*w  w  w  . j a v  a2  s  .c  om*/
    reply.writeByte(Constants.CREDENTIAL_REQ);
    reply.writeInt(Constants.W_ERR_NOT_LOGGED_IN);
    return reply;
}

From source file:com.neoba.messages.PingPongMessage.java

@Override
public ByteBuf result() {

    ByteBuf reply = buffer(6);
    reply.writeByte(Constants.VERSION);/*from   w  ww. j a  v  a2  s  .  co m*/
    reply.writeByte(Constants.PINGPONG);
    reply.writeInt(Constants.W_PING);

    return reply;
}

From source file:com.neoba.messages.ProtocolExpiredMessage.java

@Override
public ByteBuf result() {

    ByteBuf reply = buffer(6);
    reply.writeByte(Constants.VERSION);/*from   ww w .j  a  v  a 2 s  .c  om*/
    reply.writeByte(type);
    reply.writeInt(Constants.W_ERR_PROTOCOL_EXPIRED);
    return reply;
}

From source file:com.neoba.messages.UserCreateMessage.java

@Override
public ByteBuf result() {

    ByteBuf reply = buffer(6);
    reply.writeByte(Constants.VERSION);/*  w w  w .ja v a 2 s.c o m*/
    reply.writeByte(Constants.USER_CREATE);
    if (!isnametaken)
        reply.writeInt(Constants.W_SUCCESS);
    else
        reply.writeInt(Constants.W_ERR_DUP_USERNAME);
    return reply;
}

From source file:com.neoba.messages.UserLoginMessage.java

@Override
public ByteBuf result() {
    ByteBuf reply;
    if (response == Constants.W_SUCCESS) {
        reply = buffer(6 + 16);/*from   w  ww.j av  a2 s  .  co m*/
    } else {
        reply = buffer(6);
    }

    reply.writeByte(Constants.VERSION);
    reply.writeByte(Constants.USER_LOGIN);
    reply.writeInt(response);
    if (response == Constants.W_SUCCESS) {
        reply.writeLong(sessid.getLeastSignificantBits());
        reply.writeLong(sessid.getMostSignificantBits());
    }
    return reply;
}

From source file:com.neoba.messages.UserLogoutMessage.java

public ByteBuf result() {
    ByteBuf reply = buffer(6);
    reply.writeByte(Constants.VERSION);/*ww w  .  j  ava2 s .c o m*/
    reply.writeByte(Constants.LOGOUT);
    if (session_not_found) {
        reply.writeInt(Constants.W_ERR_SESSION_NOT_FOUND);
    } else {
        reply.writeInt(Constants.W_SUCCESS);
    }
    return reply;
}

From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyBackendHandler.java

License:Apache License

@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) {
    ByteBuf buf = (ByteBuf) msg;//from  w w  w .ja v a2  s  .co m
    System.out.println("channelRead:" + ByteBufUtil.hexDump((buf)));
    while (buf.readableBytes() > 0) {

        int payload = buf.readUnsignedMedium();
        int frameType = buf.readByte();
        Http2Flags flags = new Http2Flags(buf.readUnsignedByte());
        int streamId = readUnsignedInt(buf);
        ByteBuf payloadBuf = buf.readBytes(payload);
        ByteBuf copy = ctx.alloc().buffer();
        System.out.println("frame_type:" + frameType + "," + ByteBufUtil.hexDump((payloadBuf)));
        switch (frameType) {
        case Http2FrameTypes.SETTINGS:
            handleSettingFrame(ctx, flags);
            break;
        case Http2FrameTypes.WINDOW_UPDATE:
            handleWindowsUpdateFrame(ctx);
            break;
        case Http2FrameTypes.HEADERS:

            copy.writeMedium(payload);
            copy.writeByte(frameType);
            copy.writeByte(flags.value());
            copy.writeInt(streamId);
            copy.writeBytes(payloadBuf);
            forward(ctx, copy);
            break;
        case Http2FrameTypes.DATA:
            copy.writeMedium(payload);
            copy.writeByte(frameType);
            copy.writeByte(flags.value());
            copy.writeInt(streamId);
            copy.writeBytes(payloadBuf);
            forward(ctx, copy);
            break;
        default:
            break;

        }
    }

}

From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyFrontendHandler.java

License:Apache License

private void readFrame(final ChannelHandlerContext ctx, ByteBuf buf) {
    if (first) {/*w w  w . j a  v a2s .  co  m*/
        try {
            readClientPrefaceString(buf);
        } catch (Http2Exception e) {
            e.printStackTrace();
        }
        first = false;
    }

    while (buf.readableBytes() > 0) {

        int payload = buf.readUnsignedMedium();
        int frameType = buf.readByte();
        Http2Flags flags = new Http2Flags(buf.readUnsignedByte());
        int streamId = readUnsignedInt(buf);
        ByteBuf payloadBuf = buf.readBytes(payload);
        ByteBuf copy = ctx.alloc().buffer();
        switch (frameType) {
        case Http2FrameTypes.SETTINGS:
            handleSettingFrame(ctx, flags);
            break;
        case Http2FrameTypes.WINDOW_UPDATE:
            handleWindowsUpdateFrame(ctx);
            break;
        case Http2FrameTypes.HEADERS:

            copy.writeMedium(payload);
            copy.writeByte(frameType);
            copy.writeByte(flags.value());
            copy.writeInt(streamId);
            copy.writeBytes(payloadBuf);
            handleHeaderFrame(ctx, copy, streamId);
            break;
        case Http2FrameTypes.DATA:
            copy.writeMedium(payload);
            copy.writeByte(frameType);
            copy.writeByte(flags.value());
            copy.writeInt(streamId);
            copy.writeBytes(payloadBuf);
            handleDataFrame(ctx, copy, streamId);
            break;
        default:
            break;

        }
    }
}