Example usage for io.netty.buffer ByteBuf writeLong

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

Introduction

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

Prototype

public abstract ByteBuf writeLong(long value);

Source Link

Document

Sets the specified 64-bit long integer at the current writerIndex and increases the writerIndex by 8 in this buffer.

Usage

From source file:org.apache.spark.network.protocol.UploadStream.java

License:Apache License

@Override
public void encode(ByteBuf buf) {
    buf.writeLong(requestId);
    try {/*  w ww .j  ava  2  s  .  c om*/
        ByteBuffer metaBuf = meta.nioByteBuffer();
        buf.writeInt(metaBuf.remaining());
        buf.writeBytes(metaBuf);
    } catch (IOException io) {
        throw new RuntimeException(io);
    }
    buf.writeLong(bodyByteCount);
}

From source file:org.apache.spark.network.shuffle.protocol.mesos.RegisterDriver.java

License:Apache License

@Override
public void encode(ByteBuf buf) {
    Encoders.Strings.encode(buf, appId);
    buf.writeLong(heartbeatTimeoutMs);
}

From source file:org.apache.spark.network.shuffle.protocol.StreamHandle.java

License:Apache License

@Override
public void encode(ByteBuf buf) {
    buf.writeLong(streamId);
    buf.writeInt(numChunks);
}

From source file:org.apache.spark.network.util.TransportFrameDecoderSuite.java

License:Apache License

@Test
public void testSplitLengthField() throws Exception {
    byte[] frame = new byte[1024 * (RND.nextInt(31) + 1)];
    ByteBuf buf = Unpooled.buffer(frame.length + 8);
    buf.writeLong(frame.length + 8);
    buf.writeBytes(frame);//from  w  w w  .  j a v  a2 s.c om

    TransportFrameDecoder decoder = new TransportFrameDecoder();
    ChannelHandlerContext ctx = mockChannelHandlerContext();
    try {
        decoder.channelRead(ctx, buf.readSlice(RND.nextInt(7)).retain());
        verify(ctx, never()).fireChannelRead(any(ByteBuf.class));
        decoder.channelRead(ctx, buf);
        verify(ctx).fireChannelRead(any(ByteBuf.class));
        assertEquals(0, buf.refCnt());
    } finally {
        decoder.channelInactive(ctx);
        release(buf);
    }
}

From source file:org.apache.spark.network.util.TransportFrameDecoderSuite.java

License:Apache License

/**
 * Creates a number of randomly sized frames and feed them to the given decoder, verifying
 * that the frames were read.//from w  w  w .  j  a v  a 2 s.  c o  m
 */
private ByteBuf createAndFeedFrames(int frameCount, TransportFrameDecoder decoder, ChannelHandlerContext ctx)
        throws Exception {
    ByteBuf data = Unpooled.buffer();
    for (int i = 0; i < frameCount; i++) {
        byte[] frame = new byte[1024 * (RND.nextInt(31) + 1)];
        data.writeLong(frame.length + 8);
        data.writeBytes(frame);
    }

    try {
        while (data.isReadable()) {
            int size = RND.nextInt(4 * 1024) + 256;
            decoder.channelRead(ctx, data.readSlice(Math.min(data.readableBytes(), size)).retain());
        }

        verify(ctx, times(frameCount)).fireChannelRead(any(ByteBuf.class));
    } catch (Exception e) {
        release(data);
        throw e;
    }
    return data;
}

From source file:org.asynchttpclient.ntlm.NtlmTest.java

License:Open Source License

@Test(expectedExceptions = NtlmEngineException.class)
public void testGenerateType3MsgThrowsExceptionWhenUnicodeSupportNotIndicated() {
    ByteBuf buf = Unpooled.directBuffer();
    buf.writeBytes("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
    buf.writeByte(0);// w w  w  .  j  a  v  a 2 s  . c  om
    // type 2 indicator
    buf.writeByte(2).writeByte(0).writeByte(0).writeByte(0);
    buf.writeLong(1);
    // flags
    buf.writeByte(0);// unicode support indicator
    buf.writeByte(0).writeByte(0).writeByte(0);
    buf.writeLong(1);// challenge
    NtlmEngine engine = new NtlmEngine();
    engine.generateType3Msg("username", "password", "localhost", "workstation",
            Base64.encode(ByteBufUtils.byteBuf2Bytes(buf)));
    fail("An NtlmEngineException must have occurred as unicode support is not indicated");
}

From source file:org.asynchttpclient.ntlm.NtlmTest.java

License:Open Source License

@Test
public void testGenerateType3Msg() {
    ByteBuf buf = Unpooled.directBuffer();
    buf.writeBytes("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
    buf.writeByte(0);//from www.  j  a  v  a 2  s.  co m
    // type 2 indicator
    buf.writeByte(2).writeByte(0).writeByte(0).writeByte(0);
    buf.writeLong(0);
    // flags
    buf.writeByte(1);// unicode support indicator
    buf.writeByte(0).writeByte(0).writeByte(0);
    buf.writeLong(1);// challenge
    NtlmEngine engine = new NtlmEngine();
    String type3Msg = engine.generateType3Msg("username", "password", "localhost", "workstation",
            Base64.encode(ByteBufUtils.byteBuf2Bytes(buf)));
    assertEquals(type3Msg,
            "TlRMTVNTUAADAAAAGAAYAEgAAAAYABgAYAAAABIAEgB4AAAAEAAQAIoAAAAWABYAmgAAAAAAAACwAAAAAQAAAgUBKAoAAAAP1g6lqqN1HZ0wSSxeQ5riQkyh7/UexwVlCPQm0SHU2vsDQm2wM6NbT2zPonPzLJL0TABPAEMAQQBMAEgATwBTAFQAdQBzAGUAcgBuAGEAbQBlAFcATwBSAEsAUwBUAEEAVABJAE8ATgA=",
            "Incorrect type3 message generated");
}

From source file:org.blockartistry.mod.DynSurround.network.PacketAurora.java

License:MIT License

public void toBytes(final ByteBuf buf) {
    buf.writeInt(this.dimension);
    buf.writeLong(this.seed);
    buf.writeInt(this.posX);
    buf.writeInt(this.posZ);
    buf.writeByte(this.colorSet);
    buf.writeByte(this.preset);
}

From source file:org.blockartistry.mod.DynSurround.network.PacketHealthChange.java

License:MIT License

@Override
public void toBytes(final ByteBuf buf) {
    buf.writeLong(this.entityId.getMostSignificantBits());
    buf.writeLong(this.entityId.getLeastSignificantBits());
    buf.writeFloat(this.posX);
    buf.writeFloat(this.posY);
    buf.writeFloat(this.posZ);
    buf.writeBoolean(this.isCritical);
    buf.writeInt(this.amount);
}

From source file:org.blockartistry.mod.DynSurround.network.PacketSpeechBubble.java

License:MIT License

@Override
public void toBytes(final ByteBuf buf) {
    buf.writeLong(this.entityId.getMostSignificantBits());
    buf.writeLong(this.entityId.getLeastSignificantBits());
    ByteBufUtils.writeUTF8String(buf, this.message);
}