List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:com.jadarstudios.rankcapes.forge.network.packet.S4PacketUpdateCape.java
License:MIT License
@Override public void write(ByteBuf data) throws IndexOutOfBoundsException { data.writeByte(this.updateType.ordinal()); this.writeString(this.cape, data); }
From source file:com.juaby.labs.rpc.client.Rpc2ClientEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, RpcMessage msg, ByteBuf out) throws Exception { // GIOP header out.writeBytes(msg.getGIOPHeader()); // Major version out.writeByte(msg.getMajor()); // Minor version out.writeByte(msg.getMinor());/*from w w w .ja va 2 s . c o m*/ // Flags out.writeByte(msg.getFlags()); // Value out.writeByte(msg.getValue()); // ID out.writeInt(msg.getId()); // Total length out.writeInt(msg.getTotalLength()); // Body length out.writeInt(msg.getBodyLength()); // Body out.writeBytes(msg.getBody()); }
From source file:com.kaijin.AdvPowerMan.tileentities.TEAdjustableTransformer.java
License:Open Source License
@Override protected void addUniqueDescriptionData(ByteBuf data) throws IOException { for (int i = 0; i < 6; i++) { data.writeByte(sideSettings[i]); }//from w ww. j ava 2 s. c om }
From source file:com.kradac.karview.netty.MyEncoder.java
@Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf buf) throws Exception { String msj = String.valueOf(msg); String[] data = msj.split("%%"); msj = data[0];//from www.j a v a2s.c o m System.out.println(">>> " + Integer.parseInt(data[1])); if (Integer.parseInt(data[1]) == 1) { System.out.println("pas1"); buf.writeByte(0x00); buf.writeByte(msj.length() + 4 + 2 + 1); //Aumenta un 1 por el 0 que se aumenta buf.writeByte(0x00); buf.writeByte(0x01); buf.writeByte(0x04); buf.writeByte(0x00); buf.writeByte(0x00); buf.writeBytes(msj.getBytes()); } else { System.out.println("pas2"); buf.writeByte(0x00); buf.writeByte(msj.length() + 4 + 2); buf.writeByte(0x00); buf.writeByte(0x01); buf.writeByte(0x04); buf.writeByte(0x00); buf.writeBytes(msj.getBytes()); } }
From source file:com.lambdaworks.redis.ProtectedModeTests.java
License:Apache License
@BeforeClass public static void beforeClass() throws Exception { server = new MockTcpServer(); server.addHandler(() -> {// ww w . ja v a 2s .c om return new ChannelInboundHandlerAdapter() { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { String message = getMessage(); ByteBuf buffer = ctx.alloc().buffer(message.length() + 3); buffer.writeBytes("-".getBytes()); buffer.writeBytes(message.getBytes()); buffer.writeByte('\r').writeByte('\n'); ctx.writeAndFlush(buffer).addListener(future -> { ctx.close(); }); } }; }); server.initialize(TestSettings.nonexistentPort()); client = RedisClient.create(TestClientResources.get(), RedisURI.create(TestSettings.host(), TestSettings.nonexistentPort())); }
From source file:com.ldp.nettydemo.netty.codec.NettyMessageEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, NettyMessage msg, ByteBuf sendBuf) throws Exception { if (msg == null || msg.getHeader() == null) throw new Exception("The encode message is null"); sendBuf.writeInt((msg.getHeader().getCrcCode())); sendBuf.writeInt((msg.getHeader().getLength())); sendBuf.writeLong((msg.getHeader().getSessionID())); sendBuf.writeByte((msg.getHeader().getType())); sendBuf.writeByte((msg.getHeader().getPriority())); sendBuf.writeInt((msg.getHeader().getAttachment().size())); String key = null;//w w w. j a v a2s . co m byte[] keyArray = null; Object value = null; for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) { key = param.getKey(); keyArray = key.getBytes("UTF-8"); sendBuf.writeInt(keyArray.length); sendBuf.writeBytes(keyArray); value = param.getValue(); sendBuf.writeBytes(ByteObjConverter.ObjectToByte(value)); // marshallingEncoder.encode(value, sendBuf); } key = null; keyArray = null; value = null; if (msg.getBody() != null) { sendBuf.writeBytes(ByteObjConverter.ObjectToByte(msg.getBody())); // marshallingEncoder.encode(msg.getBody(), sendBuf); } else sendBuf.writeInt(0); sendBuf.setInt(4, sendBuf.readableBytes() - 8); }
From source file:com.linecorp.armeria.client.endpoint.dns.DnsTextEndpointGroupTest.java
License:Apache License
private static DnsRecord newTxtRecord(String hostname, String text) { final ByteBuf content = Unpooled.buffer(); content.writeByte(text.length()); content.writeBytes(text.getBytes(StandardCharsets.US_ASCII)); return new DefaultDnsRawRecord(hostname, TXT, 60, content); }
From source file:com.linecorp.armeria.internal.grpc.ArmeriaMessageFramer.java
License:Apache License
private ByteBuf write(ByteBuf message, boolean compressed) { try {/* w w w . j a v a 2s.c o m*/ final int messageLength = message.readableBytes(); if (maxOutboundMessageSize >= 0 && messageLength > maxOutboundMessageSize) { throw Status.RESOURCE_EXHAUSTED .withDescription( String.format("message too large %d > %d", messageLength, maxOutboundMessageSize)) .asRuntimeException(); } final ByteBuf buf = alloc.buffer(HEADER_LENGTH + messageLength); buf.writeByte(compressed ? COMPRESSED : UNCOMPRESSED); buf.writeInt(messageLength); buf.writeBytes(message); return buf; } finally { message.release(); } }
From source file:com.linecorp.armeria.internal.grpc.GrpcTestUtil.java
License:Apache License
public static byte[] uncompressedFrame(ByteBuf proto) { ByteBuf buf = Unpooled.buffer(); buf.writeByte(0); buf.writeInt(proto.readableBytes()); buf.writeBytes(proto);//from w w w.j av a 2 s . co m proto.release(); byte[] result = ByteBufUtil.getBytes(buf); buf.release(); return result; }
From source file:com.linecorp.armeria.internal.grpc.GrpcTestUtil.java
License:Apache License
public static byte[] compressedFrame(ByteBuf uncompressed) { ByteBuf compressed = Unpooled.buffer(); try (ByteBufInputStream is = new ByteBufInputStream(uncompressed, true); GZIPOutputStream os = new GZIPOutputStream(new ByteBufOutputStream(compressed))) { ByteStreams.copy(is, os);// w w w . j a v a 2 s . c o m } catch (IOException e) { throw new UncheckedIOException(e); } ByteBuf buf = Unpooled.buffer(); buf.writeByte(1); buf.writeInt(compressed.readableBytes()); buf.writeBytes(compressed); compressed.release(); byte[] result = ByteBufUtil.getBytes(buf); buf.release(); return result; }