List of usage examples for io.netty.buffer ByteBuf writeBytes
public abstract ByteBuf writeBytes(ByteBuffer src);
From source file:com.vethrfolnir.login.network.mu.ClientChannelHandler.java
License:Open Source License
@Override public void channelRegistered(ChannelHandlerContext ctx) throws Exception { if (nameService.liveServerSize() > 0) { ByteBuf buff = ctx.alloc().buffer(4); ctx.writeAndFlush(buff.writeBytes(new byte[] { (byte) 0xC1, 0x04, 0x00, 0x01 })); }/*from w w w . j a va 2s. com*/ }
From source file:com.weibo.api.motan.transport.netty.NettyEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { long requestId = getRequestId(msg); byte[] data = null; if (msg instanceof Response) { try {/*from w w w. jav a 2 s . com*/ data = codec.encode(client, msg); } catch (Exception e) { LoggerUtil.error("NettyEncoder encode error, identity=" + client.getUrl().getIdentity(), e); Response response = buildExceptionResponse(requestId, e); data = codec.encode(client, response); } } else { data = codec.encode(client, msg); } byte[] transportHeader = new byte[MotanConstants.NETTY_HEADER]; ByteUtil.short2bytes(MotanConstants.NETTY_MAGIC_TYPE, transportHeader, 0); transportHeader[3] = getType(msg); ByteUtil.long2bytes(getRequestId(msg), transportHeader, 4); ByteUtil.int2bytes(data.length, transportHeader, 12); out.writeBytes(transportHeader).writeBytes(data); }
From source file:com.weibo.api.motan.transport.netty4.yar.YarMessageHandlerWarpperTest.java
License:Apache License
private FullHttpRequest buildHttpRequest(YarRequest yarRequest, String requestPath) throws Exception { PooledByteBufAllocator allocator = new PooledByteBufAllocator(); ByteBuf buf = allocator.buffer(2048, 1024 * 1024); if (yarRequest != null) { buf.writeBytes(YarProtocol.toProtocolBytes(yarRequest)); }/*w w w . ja va 2 s .co m*/ FullHttpRequest httpReqeust = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, requestPath, buf); return httpReqeust; }