Java Code Examples for io.netty.buffer.ByteBuf.writeLong()

The following are Jave code examples for showing how to use writeLong() of the io.netty.buffer.ByteBuf class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: fastdfs-spring-boot   File: FileOperationEncoder.java   Source Code and License Vote up 6 votes
@Override
public List<Object> encode(ByteBufAllocator alloc) {
    ByteBuf meta = metadata(alloc);

    ByteBuf head = alloc.buffer(FastdfsConstants.FDFS_HEAD_LEN);
    head.writeLong(meta.readableBytes() + size);
    head.writeByte(cmd());
    head.writeByte(FastdfsConstants.ERRNO_OK);

    CompositeByteBuf cbb = alloc.compositeBuffer();
    cbb.addComponents(head, meta);
    cbb.writerIndex(head.readableBytes() + meta.readableBytes());

    List<Object> requests = new LinkedList<>();
    requests.add(cbb);
    requests.add(content);
    return requests;
}
 
Example 2
Project: reactive-pg-client   File: Parse.java   Source Code and License Vote up 6 votes
private static void encode(long statement, String query, int[] paramDataTypes, ByteBuf out) {
  int pos = out.writerIndex();
  out.writeByte(PARSE);
  out.writeInt(0);
  if(statement == 0) {
    out.writeByte(0);
  } else {
    out.writeLong(statement);
  }
  Util.writeCStringUTF8(out, query);
  // no parameter data types (OIDs)
  if(paramDataTypes == null) {
    out.writeShort(0);
  } else {
    // Parameter data types (OIDs)
    out.writeShort(paramDataTypes.length);
    for (int paramDataType : paramDataTypes) {
      out.writeInt(paramDataType);
    }
  }
  out.setInt(pos + 1, out.writerIndex() - pos - 1);
}
 
Example 3
Project: PAYDAY   File: PacketSyncTileEntityClient.java   Source Code and License Vote up 6 votes
@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(x);
	buf.writeInt(y);
	buf.writeInt(z);

	buf.writeInt(players.size());

	buf.writeBoolean(isGameLive);

	for (UUID player : players) {
		buf.writeLong(player.getMostSignificantBits());
		buf.writeLong(player.getLeastSignificantBits());
	}

	buf.writeBoolean(lobbyHost != null);

	if (lobbyHost != null) {
		buf.writeLong(lobbyHost.getMostSignificantBits());
		buf.writeLong(lobbyHost.getLeastSignificantBits());
	}
}
 
Example 4
Project: rpc   File: NettyEncoder.java   Source Code and License Vote up 6 votes
@Override
protected void encode(ChannelHandlerContext channelHandlerContext, RpcMessage message, ByteBuf byteBuf) throws Exception {
    Header header = message.getHeader();
    byteBuf.writeShort(header.getMagic());
    byteBuf.writeByte(header.getVersion());
    byteBuf.writeByte(header.getExtend());
    byteBuf.writeLong(header.getMessageID());
    Object content = message.getContent();
    // 心跳消息,没有body
    if (content == null && EventType.typeofHeartBeat(header.getExtend())) {
        byteBuf.writeInt(0);
        return;
    }
    Serialization serialization = SerializeType.getSerializationByExtend(header.getExtend());
    Compress compress = CompressType.getCompressTypeByValueByExtend(header.getExtend());
    byte[] payload = compress.compress(serialization.serialize(content));
    byteBuf.writeInt(payload.length);
    byteBuf.writeBytes(payload);
}
 
Example 5
Project: Machines-and-Stuff   File: MessageAccumulator.java   Source Code and License Vote up 6 votes
@Override
public void toBytes(ByteBuf buf) {
    
    buf.writeInt(this.x);
    buf.writeInt(this.y);
    buf.writeInt(this.z);
    
    buf.writeLong(energy);

    NBTTagList list = new NBTTagList();
    for(AccumulatorInfo info : this.infos) {
        list.appendTag(info.writeToNBT());
    }
    NBTTagCompound tag = new NBTTagCompound();
    tag.setTag("infos", list);
    ByteBufUtils.writeTag(buf, tag);
}
 
Example 6
Project: message-broker   File: HeaderFrame.java   Source Code and License Vote up 6 votes
@Override
public void writePayload(ByteBuf buf) {
    buf.writeShort(classId);
    buf.writeShort(0); // Write 0 for weight
    buf.writeLong(bodySize);

    int propertyFlags = getPropertyFlagsValue(properties.getValue(PROPERTY_FLAGS));

    buf.writeShort(propertyFlags);
    writeProperty(buf, properties.getValue(Metadata.CONTENT_TYPE));
    writeProperty(buf, properties.getValue(Metadata.CONTENT_ENCODING));
    writeFieldTable(buf, headers);
    writeProperty(buf, properties.getValue(Metadata.DELIVERY_MODE));
    writeProperty(buf, properties.getValue(Metadata.PRIORITY));
    writeProperty(buf, properties.getValue(Metadata.CORRELATION_ID));
    writeProperty(buf, properties.getValue(REPLY_TO));
    writeProperty(buf, properties.getValue(Metadata.EXPIRATION));
    writeProperty(buf, properties.getValue(Metadata.MESSAGE_ID));
    writeProperty(buf, properties.getValue(TIMESTAMP));
    writeProperty(buf, properties.getValue(TYPE));
    writeProperty(buf, properties.getValue(USER_ID));
    writeProperty(buf, properties.getValue(APPLICATION_ID));
}
 
Example 7
Project: angel   File: ServerSparseDoubleRowTest.java   Source Code and License Vote up 6 votes
@Test
public void testDeserialize() throws Exception {
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeInt(0);
  buf.writeInt(1);
  buf.writeLong(2);
  buf.writeLong(3);
  buf.writeInt(4);
  buf.writeInt(3);
  buf.writeInt(0);
  buf.writeDouble(-1.0);
  buf.writeInt(1);
  buf.writeDouble(-2.0);
  buf.writeInt(2);
  buf.writeDouble(-3.0);
  serverSparseDoubleRow.deserialize(buf);
  assertEquals(serverSparseDoubleRow.getRowId(), 0);
  assertEquals(serverSparseDoubleRow.getClock(), 1);
  assertEquals(serverSparseDoubleRow.getStartCol(), 2);
  assertEquals(serverSparseDoubleRow.getEndCol(), 3);
  assertEquals(serverSparseDoubleRow.getRowVersion(), 4);
  assertEquals(serverSparseDoubleRow.getData().size(), 3);
  assertEquals(serverSparseDoubleRow.getData().get(0), -1, 0.0);
  assertEquals(serverSparseDoubleRow.getData().get(1), -2, 0.0);
  assertEquals(serverSparseDoubleRow.getData().get(2), -3, 0.0);
}
 
Example 8
Project: FlexMC   File: MessageS04SpawnPainting.java   Source Code and License Vote up 5 votes
@Override
public void write( ByteBuf buf ) throws IOException {
    writeVarInt( entityId, buf );
    writeUUID( entityUUID, buf );
    writeString( title, buf );
    buf.writeLong( position.asLong() );
    buf.writeByte( direction );
}
 
Example 9
Project: angel   File: LongIndexPartGetParam.java   Source Code and License Vote up 5 votes
@Override
public void serialize(ByteBuf buf) {
  super.serialize(buf);
  buf.writeInt(rowId);
  buf.writeInt(index.length);

  if (index.length > 0) {
    for(int i = 0; i < index.length; i++) {
      buf.writeLong(index[i]);
    }
  }
}
 
Example 10
Project: angel   File: ServerRow.java   Source Code and License Vote up 5 votes
@Override
public void serialize(ByteBuf buf) {
  buf.writeInt(rowId);
  buf.writeInt(clock);
  buf.writeLong(startCol);
  buf.writeLong(endCol);
  buf.writeInt(rowVersion);
}
 
Example 11
Project: fastdfs-spring-boot   File: FileModifyEncoder.java   Source Code and License Vote up 5 votes
@Override
protected ByteBuf metadata(ByteBufAllocator alloc) {
    byte[] pathBytes = fileId.pathBytes();
    int metaLen = 3 * FastdfsConstants.FDFS_PROTO_PKG_LEN_SIZE + pathBytes.length;
    ByteBuf buf = alloc.buffer(metaLen);
    buf.writeLong(pathBytes.length);
    buf.writeLong(offset);
    buf.writeLong(size());
    buf.writeBytes(pathBytes);
    return buf;
}
 
Example 12
Project: Randores2   File: RandoresUpdatePluginSeedRequest.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
    byte[] encodedKey = this.plugin.getBytes(StandardCharsets.UTF_8);
    buf.writeInt(encodedKey.length);
    buf.writeBytes(encodedKey);
    buf.writeLong(this.seed);
}
 
Example 13
Project: PAYDAY   File: PacketSyncPlayerPropertiesClient.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
	buf.writeBoolean(inLobby);
	buf.writeBoolean(ready);

	buf.writeLong(playerProfileUUID.getMostSignificantBits());
	buf.writeLong(playerProfileUUID.getLeastSignificantBits());
}
 
Example 14
Project: minebox   File: TransmissionPhase.java   Source Code and License Vote up 5 votes
private void sendTransmissionSimpleReply(ChannelHandlerContext ctx, int error, long handle, ByteBuf data) {
    synchronized (this) {
        ByteBuf bbr = ctx.alloc().buffer(16);
        bbr.writeInt(Protocol.REPLY_MAGIC);
        bbr.writeInt(error); // zero for okay
        bbr.writeLong(handle);
        ctx.write(bbr);
        if (data != null) {
            ctx.write(data);
        }
    }
    ctx.flush();
    logPendingOperations();
}
 
Example 15
Project: message-broker   File: LongLongInt.java   Source Code and License Vote up 4 votes
@Override
public void write(ByteBuf buf) {
    buf.writeLong(value);
}
 
Example 16
Project: FlexMC   File: MessageS46SpawnPosition.java   Source Code and License Vote up 4 votes
@Override
public void write( ByteBuf buf ) throws IOException {
    buf.writeLong( position.asLong() );
}
 
Example 17
Project: Randores2   File: RandoresEndDataTransferRequest.java   Source Code and License Vote up 4 votes
@Override
public void toBytes(ByteBuf buf) {
    buf.writeLong(this.id.getMostSignificantBits());
    buf.writeLong(this.id.getLeastSignificantBits());
}
 
Example 18
Project: FlexMC   File: MessageS09UpdateBlockEntity.java   Source Code and License Vote up 4 votes
@Override
public void write( ByteBuf buf ) throws IOException {
    buf.writeLong( position.asLong() );
    buf.writeByte( action );
    writeNbtTag( tag, buf );
}
 
Example 19
Project: athena   File: MessageEncoder.java   Source Code and License Vote up 4 votes
@Override
protected void encode(
        ChannelHandlerContext context,
        InternalMessage message,
        ByteBuf out) throws Exception {

    out.writeInt(this.preamble);

    // write message id
    out.writeLong(message.id());

    Endpoint sender = message.sender();

    IpAddress senderIp = sender.host();
    if (senderIp.version() == Version.INET) {
        out.writeByte(0);
    } else {
        out.writeByte(1);
    }
    out.writeBytes(senderIp.toOctets());

    // write sender port
    out.writeInt(sender.port());

    byte[] messageTypeBytes = message.type().getBytes(Charsets.UTF_8);

    // write length of message type
    out.writeInt(messageTypeBytes.length);

    // write message type bytes
    out.writeBytes(messageTypeBytes);

    // write message status value
    out.writeInt(message.status().ordinal());

    byte[] payload = message.payload();

    // write payload length
    out.writeInt(payload.length);

    // write payload.
    out.writeBytes(payload);
}
 
Example 20
Project: Randores2   File: RandoresDefineBySeedRequest.java   Source Code and License Vote up 4 votes
@Override
public void toBytes(ByteBuf buf) {
    buf.writeLong(this.seed);
}