當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuf.writeBytes方法代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBuf.writeBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.writeBytes方法的具體用法?Java ByteBuf.writeBytes怎麽用?Java ByteBuf.writeBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.writeBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toBytes

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(entityID);
	buf.writeByte(type);
	if (type == 0)
		buf.writeInt(intValue);
	else if (type == 1)
		buf.writeFloat(floatValue);
	else if (type == 2)
		buf.writeByte(byteValue);
	else if (type == 3) {
		byte[] stringValueArray = stringValue.getBytes(StandardCharsets.UTF_8);
		buf.writeByte(stringValueArray.length);
		buf.writeBytes(stringValueArray);
	}
	byte[] stringNameArray = name.getBytes(StandardCharsets.UTF_8);
	buf.writeBytes(stringNameArray);
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:19,代碼來源:TF2Message.java

示例2: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void encode(ByteBuf out, Object message) throws IOException {
    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        closer.register(byteArrayOutputStream);
        KryoSerialize kryoSerialization = new KryoSerialize(pool);
        kryoSerialization.serialize(byteArrayOutputStream, message);
        byte[] body = byteArrayOutputStream.toByteArray();
        int dataLength = body.length;
        out.writeInt(dataLength);
        out.writeBytes(body);
    } finally {
        closer.close();
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:16,代碼來源:KryoCodecServiceImpl.java

示例3: mirrorUnknown

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private ByteBuf mirrorUnknown ( final ByteBuf data, final byte typeId, final InformationStructure informationStructure, final byte size, final ASDUHeader header, final Cause newCause )
{
    logger.debug ( "Mirror unknown message -> {}", newCause );
    final ByteBuf reply = Unpooled.buffer ();

    EncodeHelper.encodeHeader ( typeId, informationStructure, this.options, (int)size, header.clone ( newCause ), reply );

    reply.writeBytes ( data ); // copy data

    return reply;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:12,代碼來源:MessageManager.java

示例4: channelActive

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 *@description 客戶端成功連接到服務器之後向服務器發送數據
 *@time 創建時間:2017年7月26日下午7:51:31
 *@param ctx
 *@throws Exception
 *@author dzn
 */
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    ByteBuf message = null;
    for(int i = 0; i < 100; i ++){
        message = Unpooled.buffer(req.length);
        message.writeBytes(req);
        ctx.channel().writeAndFlush(message);
    }
}
 
開發者ID:SnailFastGo,項目名稱:netty_op,代碼行數:17,代碼來源:RightTimeClientHandler.java

示例5: write

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void write(byte[] bytes) {
	if(bytes!=null && bytes.length>0 && isActive())
	{
		ByteBuf buf=PooledByteBufAllocator.DEFAULT.buffer();
		buf.writeBytes(bytes);
		write(buf);
	}
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:10,代碼來源:NettyConnection.java

示例6: writeInet

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static void writeInet(InetSocketAddress inet, ByteBuf cb)
{
    byte[] address = inet.getAddress().getAddress();

    cb.writeByte(address.length);
    cb.writeBytes(address);
    cb.writeInt(inet.getPort());
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:9,代碼來源:CBUtil.java

示例7: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * 編碼
 * 
 * @param out
 */
public void encode(ByteBuf out) {
	byte[] head = encodeHead();
	byte[] body = encodeBody();
	out.writeShort((short) (head.length + body.length + 2)); // 消息的總長度
	out.writeBytes(head); // 協議頭
	out.writeShort((short) body.length); // 消息體長度
	out.writeBytes(body); // 消息體
}
 
開發者ID:inspingcc,項目名稱:LibraSock,代碼行數:14,代碼來源:LibraMessage.java

示例8: writeBytes

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void writeBytes(ByteBuffer bytes, ByteBuf dest) {
  if (bytes == null) {
    writeInt(-1, dest);
  } else {
    writeInt(bytes.remaining(), dest);
    dest.writeBytes(bytes.duplicate());
  }
}
 
開發者ID:datastax,項目名稱:simulacron,代碼行數:10,代碼來源:ByteBufCodec.java

示例9: metadata

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected ByteBuf metadata(ByteBufAllocator alloc) {
    byte[] pathBytes = fileId.pathBytes();

    int metaSize = 2 * FastdfsConstants.FDFS_PROTO_PKG_LEN_SIZE + pathBytes.length;
    ByteBuf buf = alloc.buffer(metaSize);
    buf.writeLong(pathBytes.length);
    buf.writeLong(size());
    buf.writeBytes(pathBytes);
    return buf;
}
 
開發者ID:rodbate,項目名稱:fastdfs-spring-boot,代碼行數:12,代碼來源:FileAppendEncoder.java

示例10: shouldDeserializeTheMapCorrectly

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Test
public void shouldDeserializeTheMapCorrectly() throws Exception {
    ByteBuf buf = new PooledByteBufAllocator(true).buffer();
    buf.writeBytes(new ObjectMapper().writeValueAsBytes(map));
    assertThat(mapCodec.getMapValueDecoder().decode(buf, new State(false)))
            .isInstanceOf(Map.class)
            .isEqualTo(map);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:9,代碼來源:JsonJacksonMapValueCodecTest.java

示例11: serialize

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void serialize(ByteBuf buf) {
  super.serialize(buf);
  if (partResult != null) {
    byte[] data = partResult.getClass().getName().getBytes();
    buf.writeInt(data.length);
    buf.writeBytes(data);

    partResult.serialize(buf);
  }
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:12,代碼來源:GetUDFResponse.java

示例12: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static void encode(ByteBuf buf, String s) {
  byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
  buf.writeInt(bytes.length);
  buf.writeBytes(bytes);
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:6,代碼來源:Encoders.java

示例13: main

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static void main(String[] args) {
   	ByteBuf heapBuf = Unpooled.buffer(10);
   	heapBuf.writeBytes("helloworld".getBytes());
	heapBuffer(heapBuf);
}
 
開發者ID:zy416548283,項目名稱:NettyStudy,代碼行數:6,代碼來源:ByteBufExamples.java

示例14: writeUUID

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static void writeUUID(UUID uuid, ByteBuf cb)
{
    cb.writeBytes(UUIDGen.decompose(uuid));
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:5,代碼來源:CBUtil.java

示例15: writeInetAddr

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void writeInetAddr(InetAddress address, ByteBuf dest) {
  byte[] addr = address.getAddress();
  dest.writeByte(addr.length);
  dest.writeBytes(addr);
}
 
開發者ID:datastax,項目名稱:simulacron,代碼行數:7,代碼來源:ByteBufCodec.java


注:本文中的io.netty.buffer.ByteBuf.writeBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。