public void Encode(IoSession session, object message, IProtocolEncoderOutput output) { if (message is object[]) { foreach (var m in (object[])message) { Encode(session, m, output); } } else if (message is VMNetMessage) { var nmsg = (VMNetMessage)message; var payload = IoBuffer.Allocate(128); payload.Order = ByteOrder.LittleEndian; payload.AutoExpand = true; payload.PutInt32(0); //packet type payload.PutInt32(nmsg.Data.Length + 1); payload.Put((byte)nmsg.Type); foreach (var b in nmsg.Data) { payload.Put(b); } payload.Flip(); output.Write(payload); } }
public void Encode(IoSession session, ISerialPacket message, IProtocolEncoderOutput output) { var buf = message.GetBuffer(); buf.Flip(); output.Write(buf); }
/// <inheritdoc/> public override void Encode(IoSession session, Object message, IProtocolEncoderOutput output) { if (!message.GetType().IsSerializable) { throw new System.Runtime.Serialization.SerializationException(message.GetType() + " is not serializable."); } IoBuffer buf = IoBuffer.Allocate(64); buf.AutoExpand = true; buf.PutInt32(0); buf.PutObject(message); Int32 objectSize = buf.Position - 4; if (objectSize > _maxObjectSize) { throw new ArgumentException(String.Format("The encoded object is too big: {0} (> {1})", objectSize, _maxObjectSize), "message"); } buf.PutInt32(0, objectSize); buf.Flip(); output.Write(buf); }
public void Encode(IoSession session, object message, IProtocolEncoderOutput output) { Message msg = (Message)message; IoBuffer buffer = IoBuffer.Allocate(1024); buffer.AutoExpand = true; buffer.PutMessage(msg); buffer.Flip(); output.Write(buffer); }
public void Encode(IoSession session, PacketOutStream message, IProtocolEncoderOutput output) { int size = message.GetSize(); IoBuffer buf = IoBuffer.Allocate(size + 4); buf.PutInt32(size); buf.Put(message.getPackets2()); buf.Flip(); output.Write(buf); }
public void Encode(IoSession session, TMessage message, IProtocolEncoderOutput output) { var buffer = IoBuffer.Allocate(48); buffer.AutoExpand = true; if (DoEncode(buffer, message)) { buffer.Flip(); output.Write(buffer); } }
/// <inheritdoc/> public override void Encode(IoSession session, Object message, IProtocolEncoderOutput output) { String value = (String)message; IoBuffer buffer = IoBuffer.Allocate(value.Length); buffer.AutoExpand = true; buffer.PutPrefixedString(value, PrefixLength, Encoding); if (buffer.Position > MaxDataLength) { throw new ArgumentException("Data length: " + buffer.Position); } buffer.Flip(); output.Write(buffer); }
public void Encode(object message, IProtocolEncoderOutput output) { IDataBlock frame = (IDataBlock) message; int frameSize = (int)frame.Size; // TODO: sort out signed/unsigned ByteBuffer buffer = ByteBuffer.Allocate(frameSize); frame.WritePayload(buffer); if (_logger.IsDebugEnabled) { _logger.Debug("Encoded frame byte-buffer is '" + ByteBufferHexDumper.GetHexDump(buffer) + "'"); } buffer.Flip(); output.Write(buffer); }
public void Encode(object message, IProtocolEncoderOutput output) { IDataBlock frame = (IDataBlock)message; int frameSize = (int)frame.Size; // TODO: sort out signed/unsigned ByteBuffer buffer = ByteBuffer.Allocate(frameSize); frame.WritePayload(buffer); if (_logger.IsDebugEnabled) { _logger.Debug("Encoded frame byte-buffer is '" + ByteBufferHexDumper.GetHexDump(buffer) + "'"); } buffer.Flip(); output.Write(buffer); }
public void Encode(IoSession session, T message, IProtocolEncoderOutput output) { IoBuffer buf = IoBuffer.Allocate(16); buf.AutoExpand = true; // Enable auto-expand for easier encoding // Encode a header buf.PutInt16((short)_type); buf.PutInt32(message.Sequence); // Encode a body EncodeBody(session, message, buf); buf.Flip(); output.Write(buf); }
/// <inheritdoc/> public void Encode(IoSession session, Object message, IProtocolEncoderOutput output) { String value = message == null ? String.Empty : message.ToString(); value += _delimiter.Value; Byte[] bytes = _encoding.GetBytes(value); if (bytes.Length > _maxLineLength) { throw new ArgumentException("Line too long: " + bytes.Length); } // TODO BufferAllocator IoBuffer buf = IoBuffer.Wrap(bytes); output.Write(buf); }
public void Encode(IoSession session, byte[] message, IProtocolEncoderOutput output) { try { var data = (byte[])message; IoBuffer buf = IoBuffer.Allocate(data.Length); buf.AutoExpand = true; // Enable auto-expand for easier encoding buf.Put(data); buf.Flip(); output.Write(buf); } catch (System.Exception ex) { _logger.Error(System.String.Format("Exception in {0} {1}", LST.GetCurrentMethod(), ex.Message)); } }
private void EncodeVoltronStylePackets(IoSession session, IProtocolEncoderOutput output, AriesPacketType ariesType, ushort packetType, IoBufferSerializable message) { var payload = IoBuffer.Allocate(512); payload.Order = ByteOrder.BigEndian; payload.AutoExpand = true; message.Serialize(payload, Context); payload.Flip(); int payloadSize = payload.Remaining; IoBuffer headers = IoBuffer.Allocate(18); headers.Order = ByteOrder.LittleEndian; /** * Aries header * uint32 type * uint32 timestamp * uint32 payloadSize */ uint timestamp = (uint)TimeSpan.FromTicks(DateTime.Now.Ticks - session.CreationTime.Ticks).TotalMilliseconds; headers.PutUInt32(ariesType.GetPacketCode()); headers.PutUInt32(timestamp); headers.PutUInt32((uint)payloadSize + 6); /** * Voltron header * uint16 type * uint32 payloadSize */ headers.Order = ByteOrder.BigEndian; headers.PutUInt16(packetType); headers.PutUInt32((uint)payloadSize + 6); if (payloadSize > 0) { headers.AutoExpand = true; headers.Put(payload); } headers.Flip(); output.Write(headers); //output.Flush(); }
public override void Encode(IoSession session, Object message, IProtocolEncoderOutput output) { if (!message.GetType().IsSerializable) throw new System.Runtime.Serialization.SerializationException(message.GetType() + " is not serializable."); IoBuffer buf = IoBuffer.Allocate(64); buf.AutoExpand = true; buf.PutInt32(0); buf.PutObject(message); Int32 objectSize = buf.Position - 4; if (objectSize > _maxObjectSize) throw new ArgumentException(String.Format("The encoded object is too big: {0} (> {1})", objectSize, _maxObjectSize), "message"); buf.PutInt32(0, objectSize); buf.Flip(); output.Write(buf); }
public void Encode(IoSession session, object message, IProtocolEncoderOutput output) { WampCommandBase cmd = (WampCommandBase)message; string json = cmd.toCommandJson(); byte[] jsonByteArray = System.Text.Encoding.UTF8.GetBytes(json); int len = jsonByteArray.Length + 4; if (len > 1000000) { throw new ArgumentException("{msg:'data size > 1m', dataSize:" + len + "}"); } IoBuffer buffer = IoBuffer.Allocate(len); buffer.AutoExpand = true; buffer.PutInt32(len); buffer.Put(jsonByteArray); buffer.Flip(); output.Write(buffer); }
private void EncodeAries(IoSession session, object message, IProtocolEncoderOutput output) { IAriesPacket ariesPacket = (IAriesPacket)message; AriesPacketType ariesPacketType = ariesPacket.GetPacketType(); var payload = IoBuffer.Allocate(128); payload.Order = ByteOrder.LittleEndian; payload.AutoExpand = true; ariesPacket.Serialize(payload, Context); payload.Flip(); int payloadSize = payload.Remaining; IoBuffer headers = IoBuffer.Allocate(12); headers.Order = ByteOrder.LittleEndian; /** * Aries header * uint32 type * uint32 timestamp * uint32 payloadSize */ uint timestamp = (uint)TimeSpan.FromTicks(DateTime.Now.Ticks - session.CreationTime.Ticks).TotalMilliseconds; headers.PutUInt32(ariesPacketType.GetPacketCode()); headers.PutUInt32(timestamp); headers.PutUInt32((uint)payloadSize); if (payloadSize > 0) { headers.AutoExpand = true; headers.Put(payload); } headers.Flip(); output.Write(headers); //output.Flush(); }
/// <inheritdoc/> public void Encode(IoSession session, Object message, IProtocolEncoderOutput output) { String value = message == null ? String.Empty : message.ToString(); value += _delimiter.Value; Byte[] bytes = _encoding.GetBytes(value); if (bytes.Length > _maxLineLength) throw new ArgumentException("Line too long: " + bytes.Length); // TODO BufferAllocator IoBuffer buf = IoBuffer.Wrap(bytes); output.Write(buf); }