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.smithsmodding.smithscore.util.common.positioning.Coordinate2D.java

public void toBytes(ByteBuf pDataOut) {
    pDataOut.writeInt(getXComponent());
    pDataOut.writeInt(getYComponent());
}

From source file:com.smithsmodding.smithscore.util.common.positioning.Coordinate3D.java

public void toBytes(ByteBuf pDataOut) {
    pDataOut.writeInt(getXComponent());
    pDataOut.writeInt(getYComponent());
    pDataOut.writeInt(getZComponent());
}

From source file:com.smithsmodding.tinystorage.network.message.MessageSyncPlayerData.java

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(playerList.size());
    for (UUID ID : playerList.keySet()) {
        ByteBufUtils.writeUTF8String(buf, ID.toString());
        ByteBufUtils.writeUTF8String(buf, playerList.get(ID));
    }/*  ww w  .j av  a  2s . com*/
    buf.writeInt(playerGlobalFriends.size());
    for (UUID ID : playerGlobalFriends.keySet()) {
        ByteBufUtils.writeUTF8String(buf, ID.toString());
        ByteBufUtils.writeUTF8String(buf, playerGlobalFriends.get(ID));
    }
    buf.writeInt(playerUUIDs.size());
    for (String string : playerUUIDs) {
        ByteBufUtils.writeUTF8String(buf, string);
    }
}

From source file:com.specialeffect.messages.PickBlockMessage.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(entityId);
}

From source file:com.spotify.ffwd.riemann.RiemannResponder.java

License:Apache License

private ByteBuf ack(boolean ok) throws IOException {
    final Proto.Msg m = Proto.Msg.newBuilder().setOk(ok).build();

    final ByteBuf b = Unpooled.buffer();

    try (final ByteBufOutputStream output = new ByteBufOutputStream(b)) {
        m.writeTo(output);/*  w ww .  j  ava  2 s .com*/

        final ByteBuf frame = output.buffer();
        final ByteBuf buffer = Unpooled.buffer(4 + frame.readableBytes());

        buffer.writeInt(frame.readableBytes());
        buffer.writeBytes(frame);

        return buffer;
    } finally {
        b.release();
    }
}

From source file:com.spotify.ffwd.riemann.RiemannSerialization.java

License:Apache License

public ByteBuf encodeAll0(Collection<Object> messages) throws IOException {
    final Proto.Msg.Builder builder = Proto.Msg.newBuilder();

    for (final Object d : messages) {
        if (d instanceof Metric) {
            builder.addEvents(encodeMetric0((Metric) d));
        } else if (d instanceof Event) {
            builder.addEvents(encodeEvent0((Event) d));
        }//from  ww w. ja  va  2 s.c  o m
    }

    final Proto.Msg m = builder.build();

    final ByteBuf work = Unpooled.buffer();

    try (final ByteBufOutputStream output = new ByteBufOutputStream(work)) {
        m.writeTo(output);

        final ByteBuf result = Unpooled.buffer();

        result.writeInt(work.writerIndex());
        result.writeBytes(work);

        return result;
    } finally {
        work.release();
    }
}

From source file:com.spotify.folsom.client.binary.BinaryMemcacheDecoderTest.java

License:Apache License

@Test
public void test() throws Exception {
    GetRequest request = new GetRequest(KEY, OpCode.GET, 123, OPAQUE);
    BinaryMemcacheDecoder decoder = new BinaryMemcacheDecoder();

    ByteBuf cb = Unpooled.buffer(30);
    cb.writeByte(0x81);//from   w  w w  . jav a 2 s. c o  m
    cb.writeByte(OpCode.GET);
    cb.writeShort(3);
    cb.writeByte(0);
    cb.writeZero(1);
    cb.writeShort(0);
    cb.writeInt(6);
    cb.writeInt(request.getOpaque());
    cb.writeLong(258);
    cb.writeBytes(KEY.getBytes());
    cb.writeBytes(VALUE.getBytes());

    List<Object> out = Lists.newArrayList();
    decoder.decode(null, cb, out);
    @SuppressWarnings("unchecked")
    List<ResponsePacket> replies = (List<ResponsePacket>) out.get(0);
    request.handle(replies);

    GetResult<byte[]> getResult = request.get();
    assertEquals(258, getResult.getCas());
    assertEquals(VALUE, TRANSCODER.decode(getResult.getValue()));
}

From source file:com.srotya.sidewinder.core.ingress.binary.SeriesDataPointEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext arg0, List<DataPoint> dataPoints, ByteBuf buf) throws Exception {
    int size = dataPoints.size();
    buf.writeInt(size);
    for (DataPoint dataPoint : dataPoints) {
        encodeDPointToBuf(buf, dataPoint);
    }/* w  ww  . j av  a  2  s. c o m*/
}

From source file:com.srotya.sidewinder.core.ingress.binary.SeriesDataPointEncoder.java

License:Apache License

public static void encodeDPointToBuf(ByteBuf buf, DataPoint dataPoint) {
    byte[] dbNameBytes = dataPoint.getDbName().getBytes();
    buf.writeInt(dbNameBytes.length);
    buf.writeBytes(dbNameBytes);/*from  www  .j a v a 2  s.  c  om*/
    byte[] measurementNameBytes = dataPoint.getMeasurementName().getBytes();
    buf.writeInt(measurementNameBytes.length);
    buf.writeBytes(measurementNameBytes);
    byte[] valueNameBytes = dataPoint.getValueFieldName().getBytes();
    buf.writeInt(valueNameBytes.length);
    buf.writeBytes(valueNameBytes);

    buf.writeLong(dataPoint.getTimestamp());
    if (dataPoint.isFp()) {
        buf.writeByte('0');
        buf.writeDouble(dataPoint.getValue());
    } else {
        buf.writeByte('1');
        buf.writeLong(dataPoint.getLongValue());
    }
}

From source file:com.streamsets.pipeline.lib.parser.net.netflow.NetflowTestUtil.java

License:Apache License

public static void writeV5NetflowHeader(EmbeddedChannel channel, int count, long uptime, long seconds,
        long nanos, long flowSequence, int engineType, int engineId, int sampling) {
    final int version = 5;

    final ByteBuf buf = Unpooled.buffer();
    buf.writeShort(version);//from   ww w . ja  va  2  s . c om
    buf.writeShort(count);
    buf.writeInt((int) uptime);
    buf.writeInt((int) seconds);
    buf.writeInt((int) nanos);
    buf.writeInt((int) flowSequence);
    buf.writeByte(engineType);
    buf.writeByte(engineId);
    buf.writeShort(sampling);

    channel.writeInbound(buf);
}