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.mrcrayfish.furniture.network.message.MessageMineBayBrowse.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(itemNum);
    buf.writeInt(x);
    buf.writeInt(y);
    buf.writeInt(z);
}

From source file:com.mrcrayfish.furniture.network.message.MessageMineBayBuy.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(itemNum);
    buf.writeInt(x);//from   w ww .ja  v  a  2s  .  c o m
    buf.writeInt(y);
    buf.writeInt(z);
    buf.writeBoolean(shouldClear);
}

From source file:com.mrcrayfish.furniture.network.message.MessagePresent.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    ByteBufUtils.writeItemStack(buf, present);
    buf.writeInt(x);
    buf.writeInt(y);
    buf.writeInt(z);
}

From source file:com.mrcrayfish.furniture.network.message.MessageTVClient.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(channel);
    buf.writeInt(x);
    buf.writeInt(y);
    buf.writeInt(z);
}

From source file:com.mrgreaper.twisted.handlers.TwistedPacket.java

License:MIT License

public void writeBytes(ByteBuf bytes) {
    bytes.writeInt(i);
}

From source file:com.nanxiaoqiang.test.netty.protocol.demo1.codec.NettyMessageEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, NettyMessage msg, ByteBuf sendBuf) throws Exception {
    if (msg == null || msg.getHeader() == null)
        throw new Exception("The encode message is null");
    // Header Start
    sendBuf.writeInt((msg.getHeader().getCrcCode()));// crc
    sendBuf.writeInt((msg.getHeader().getLength()));// ?
    sendBuf.writeLong((msg.getHeader().getSessionID()));
    sendBuf.writeByte((msg.getHeader().getType()));
    sendBuf.writeByte((msg.getHeader().getPriority()));
    sendBuf.writeInt((msg.getHeader().getAttachment().size()));
    String key = null;/*ww  w.j a v a  2 s .  c o  m*/
    byte[] keyArray = null;
    Object value = null;
    for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) {
        key = param.getKey();
        keyArray = key.getBytes("UTF-8");
        sendBuf.writeInt(keyArray.length);
        sendBuf.writeBytes(keyArray);
        value = param.getValue();
        marshallingEncoder.encode(value, sendBuf);
    }
    key = null;
    keyArray = null;
    value = null;
    // Head End

    // Body Start
    if (msg.getBody() != null) {// ?
        marshallingEncoder.encode(msg.getBody(), sendBuf);
    } else
        // ?
        sendBuf.writeInt(0);// 0int
    sendBuf.setInt(4, sendBuf.readableBytes() - 8);// 0~3CRC4~7??8?
}

From source file:com.necla.simba.server.gateway.server.frontend.FrontendFrameEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
    LOG.debug("told to send out msg numBytes=" + msg.readableBytes() + " to " + ctx.channel());
    int length = msg.readableBytes();
    if (DOCOMPRESS) {
        compress(ctx, msg, out);/*w w  w  .  j  a v a  2 s.co m*/

    } else {
        length &= ~(1 << 30);
        out.writeInt(length);
        out.writeBytes(msg, msg.readerIndex(), msg.readableBytes());

        Stats.sent(length);
    }

}

From source file:com.neoba.FacebookUserCreateMessage.java

ByteBuf result() throws JSONException {
    ByteBuf reply = isnametaken ? buffer(6) : buffer(6 + suggestionssize);
    reply.writeByte(Constants.VERSION);/*from   w w w.  j  av a2  s.  c om*/
    reply.writeByte(Constants.USER_CREATE);
    if (!isnametaken) {
        reply.writeInt(Constants.W_SUCCESS);
        reply.writeInt(fuser.getFriends().length());
        for (int i = 0; i < fuser.getFriends().length(); i++) {
            reply.writeLong(Long.parseLong(fuser.getFriends().getJSONObject(i).getString("id")));
            reply.writeInt(fuser.getFriends().getJSONObject(i).getString("username").length());
            reply.writeBytes(fuser.getFriends().getJSONObject(i).getString("username").getBytes());
        }

    } else
        reply.writeInt(Constants.W_ERR_DUP_USERNAME);
    return reply;
}

From source file:com.neoba.FacebookUserLogin.java

ByteBuf result() throws JSONException {
    ByteBuf reply;
    String username;//from w  ww .  jav  a 2 s  .c  o  m
    if (response == Constants.W_SUCCESS) {
        username = user.getString("username");
        reply = buffer(6 + 16 + 4 + username.length());
    } 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());
        reply.writeInt(user.getString("username").length());
        for (byte b : ((String) user.get("username")).getBytes()) {
            reply.writeByte(b);
        }
    }
    return reply;
}

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

@Override
public ByteBuf result() {

    ByteBuf reply = buffer(2 + 4 + 16);
    reply.writeByte(Constants.VERSION);/* w  w w .  j a  v  a 2  s .  com*/
    reply.writeByte(Constants.DOCUMENT_CREATE);
    reply.writeInt(Constants.W_SUCCESS);
    reply.writeLong(id.getLeastSignificantBits());
    reply.writeLong(id.getMostSignificantBits());
    return reply;
}