List of usage examples for io.netty.buffer ByteBuf writeLong
public abstract ByteBuf writeLong(long value);
From source file:com.friz.owari.network.codec.PatchInitEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, PatchInitEvent msg, ByteBuf out) throws Exception { if (!out.isWritable()) return;/* ww w. j a va2 s . c om*/ out.writeInt(msg.getCount()); out.writeLong(msg.getSize()); }
From source file:com.github.milenkovicm.kafka.protocol.Convert.java
License:Apache License
public static void encodeLong(int integer, ByteBuf buf) { buf.writeLong(integer); }
From source file:com.github.mrstampy.kitchensync.stream.header.SequenceHeaderPrepender.java
License:Open Source License
@Override protected ByteBuf processImpl(Streamer<?> streamer, byte[] message) { int headerLength = sizeInBytes(streamer); ByteBuf buf = createByteBuf(headerLength + message.length); buf.writeBytes(SequenceHeader.SEQUENCE_HEADER_BYTES); buf.writeLong(streamer.getSequence()); appendToHeader(streamer, buf, headerLength); buf.writeBytes(message);/* ww w .j ava2 s . com*/ return buf; }
From source file:com.github.mrstampy.pprspray.core.streamer.util.MediaStreamerUtils.java
License:Open Source License
/** * Write header./*ww w . jav a 2s .com*/ * * @param buf * the buf * @param type * the type * @param headerLength * the header length * @param messageHash * the message hash * @param mediaHash * the media hash * @param sequence * the sequence * @param ackRequired * the ack required */ public static void writeHeader(ByteBuf buf, MediaStreamType type, int headerLength, int messageHash, int mediaHash, long sequence, boolean ackRequired) { buf.writeBytes(type.ordinalBytes()); buf.writeShort(headerLength); buf.writeInt(messageHash); buf.writeInt(mediaHash); buf.writeLong(sequence); buf.writeBoolean(ackRequired); }
From source file:com.github.sparkfy.network.protocol.MessageEncoder.java
License:Apache License
/*** * Encodes a Message by invoking its encode() method. For non-data messages, we will add one * ByteBuf to 'out' containing the total frame length, the message type, and the message itself. * In the case of a ChunkFetchSuccess, we will also add the ManagedBuffer corresponding to the * data to 'out', in order to enable zero-copy transfer. *//*w ww.j a v a2s. com*/ @Override public void encode(ChannelHandlerContext ctx, Message in, List<Object> out) throws Exception { Object body = null; long bodyLength = 0; boolean isBodyInFrame = false; // If the message has a body, take it out to enable zero-copy transfer for the payload. if (in.body() != null) { try { bodyLength = in.body().size(); body = in.body().convertToNetty(); isBodyInFrame = in.isBodyInFrame(); } catch (Exception e) { in.body().release(); if (in instanceof AbstractResponseMessage) { AbstractResponseMessage resp = (AbstractResponseMessage) in; // Re-encode this message as a failure response. String error = e.getMessage() != null ? e.getMessage() : "null"; logger.error( String.format("Error processing %s for client %s", in, ctx.channel().remoteAddress()), e); encode(ctx, resp.createFailureResponse(error), out); } else { throw e; } return; } } Message.Type msgType = in.type(); // All messages have the frame length, message type, and message itself. The frame length // may optionally include the length of the body data, depending on what message is being // sent. int headerLength = 8 + msgType.encodedLength() + in.encodedLength(); long frameLength = headerLength + (isBodyInFrame ? bodyLength : 0); ByteBuf header = ctx.alloc().heapBuffer(headerLength); header.writeLong(frameLength); msgType.encode(header); in.encode(header); assert header.writableBytes() == 0; if (body != null) { // We transfer ownership of the reference on in.body() to MessageWithHeader. // This reference will be freed when MessageWithHeader.deallocate() is called. out.add(new MessageWithHeader(in.body(), header, body, bodyLength)); } else { out.add(header); } }
From source file:com.github.sparkfy.network.protocol.RpcFailure.java
License:Apache License
@Override public void encode(ByteBuf buf) { buf.writeLong(requestId); Encoders.Strings.encode(buf, errorString); }
From source file:com.github.sparkfy.network.protocol.RpcRequest.java
License:Apache License
@Override public void encode(ByteBuf buf) { buf.writeLong(requestId); // See comment in encodedLength(). buf.writeInt((int) body().size()); }
From source file:com.github.sparkfy.network.protocol.StreamChunkId.java
License:Apache License
public void encode(ByteBuf buffer) { buffer.writeLong(streamId); buffer.writeInt(chunkIndex); }
From source file:com.github.sparkfy.network.protocol.StreamResponse.java
License:Apache License
/** Encoding does NOT include 'buffer' itself. See {@link MessageEncoder}. */ @Override// w w w.jav a 2 s . com public void encode(ByteBuf buf) { Encoders.Strings.encode(buf, streamId); buf.writeLong(byteCount); }
From source file:com.gmail.socraticphoenix.forge.randore.packet.RandoresPacket.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeLong(this.getSeed()); }