public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { // Try to skip header if not read. if (!_readHeader) { input.GetInt16(); // Skip 'type'. _sequence = input.GetInt32(); // Get 'sequence'. _readHeader = true; } // Try to decode body AbstractMessage m = DecodeBody(session, input); // Return NEED_DATA if the body is not fully read. if (m == null) { return(MessageDecoderResult.NeedData); } else { _readHeader = false; // reset readHeader for the next decode } m.Sequence = _sequence; output.Write(m); return(MessageDecoderResult.OK); }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { // Try to skip header if not read. if (!_readHeader) { input.GetInt16(); // Skip 'type'. _sequence = input.GetInt32(); // Get 'sequence'. _readHeader = true; } // Try to decode body AbstractMessage m = DecodeBody(session, input); // Return NEED_DATA if the body is not fully read. if (m == null) { return MessageDecoderResult.NeedData; } else { _readHeader = false; // reset readHeader for the next decode } m.Sequence = _sequence; output.Write(m); return MessageDecoderResult.OK; }
/// <inheritdoc/> protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { if (!input.PrefixedDataAvailable(4, _maxObjectSize)) return false; input.GetInt32(); output.Write(input.GetObject()); return true; }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { var instr = session.GetAttribute <IInstruction>(KeyName.INSTRUCTION); if (instr != null) { output.Write(instr.CreateDecoder().Decode(input)); } return(MessageDecoderResult.OK); }
/// <inheritdoc/> protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { if (!input.PrefixedDataAvailable(4, _maxObjectSize)) { return(false); } input.GetInt32(); output.Write(input.GetObject()); return(true); }
protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { if (input.PrefixedDataAvailable(PrefixLength, MaxDataLength)) { String msg = input.GetPrefixedString(PrefixLength, Encoding); output.Write(msg); return true; } return false; }
protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { if (input.PrefixedDataAvailable(PrefixLength, MaxDataLength)) { String msg = input.GetPrefixedString(PrefixLength, Encoding); output.Write(msg); return(true); } return(false); }
protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { Assert.IsTrue(input.HasRemaining); if (input.Remaining < 4) { return(false); } output.Write(input.GetInt32()); return(true); }
protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { if (input.Remaining >= 4) { Message request = input.GetMessage(); output.Write(request); return true; } else { return false; } }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { var value = input.GetRemaining().Array; input.Position = value.Length; if (value == null) { return(MessageDecoderResult.NeedData); } output.Write(value); return(MessageDecoderResult.OK); }
/// <summary> /// Decodes the specified session. /// </summary> /// <param name="inbuf">The inbuf.</param> /// <param name="output">The protocol output.</param> /// <returns></returns> public MessageDecoderResult Decode(ByteBuffer inbuf, IProtocolDecoderOutput output) { byte[] header = new byte[4]; inbuf.GetBytes(header); ProtocolInitiation pi = new ProtocolInitiation(); pi.Header = new char[] { 'A', 'M', 'Q', 'P' }; pi.ProtocolClass = inbuf.GetByte(); pi.ProtocolInstance = inbuf.GetByte(); pi.ProtocolMajor = inbuf.GetByte(); pi.ProtocolMinor = inbuf.GetByte(); output.Write(pi); return(MessageDecoderResult.OK); }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { int totalLen = input.GetInt32(); int len = totalLen - 4; if (input.Remaining < len) { return(MessageDecoderResult.NeedData); } byte[] jsonBuffer = new byte[len]; input.Get(jsonBuffer, 0, len); string msg = System.Text.Encoding.UTF8.GetString(jsonBuffer); output.Write(msg); return(MessageDecoderResult.OK); }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { int limit = input.Limit; int position = input.Position; var len = input.GetInt32(); var version = input.Get(); input.Position = position; input.Limit = input.Position + len; var buffer = input.Slice(); input.Position = input.Limit; input.Limit = limit; var message = DoDecode(version.ToEnum<MessageVersion>(), buffer); if (message != null) output.Write(message); return MessageDecoderResult.OK; }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { try { input.Skip(MIN_REQUIRED_FRAME_LENGTH); var command = commandParser.Parse(input); output.Write(command); return MessageDecoderResult.OK; } catch (Exception ex) { var remoteAddr = string.Empty; if (session != null && session.RemoteEndPoint != null) remoteAddr = session.RemoteEndPoint.ToString(); log.Error(ex, new Dictionary<string, string> { { "RemoteAddr", remoteAddr } }); return MessageDecoderResult.NotOK; } }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { int limit = input.Limit; int position = input.Position; var len = input.GetInt32(); var version = input.Get(); input.Position = position; input.Limit = input.Position + len; var buffer = input.Slice(); input.Position = input.Limit; input.Limit = limit; var message = DoDecode(version.ToEnum <MessageVersion>(), buffer); if (message != null) { output.Write(message); } return(MessageDecoderResult.OK); }
private void DecodeVoltronStylePackets(IoBuffer buffer, ref uint payloadSize, IProtocolDecoderOutput output, Func <ushort, Type> typeResolver) { while (payloadSize > 0) { /** Voltron packet **/ buffer.Order = ByteOrder.BigEndian; ushort type = buffer.GetUInt16(); uint innerPayloadSize = buffer.GetUInt32() - 6; byte[] data = new byte[(int)innerPayloadSize]; buffer.Get(data, 0, (int)innerPayloadSize); var packetClass = typeResolver(type); if (packetClass != null) { IoBufferDeserializable packet = (IoBufferDeserializable)Activator.CreateInstance(packetClass); packet.Deserialize(IoBuffer.Wrap(data), Context); output.Write(packet); } payloadSize -= innerPayloadSize + 6; } }
protected override bool DoDecode(IoSession session, IoBuffer buffer, IProtocolDecoderOutput output) { if (buffer.Remaining < 8) { return(false); } /** * We expect aries, voltron or electron packets */ var startPosition = buffer.Position; buffer.Order = ByteOrder.LittleEndian; uint packetType = buffer.GetUInt32(); //currently unused uint payloadSize = buffer.GetUInt32(); if (buffer.Remaining < payloadSize) { /** Not all here yet **/ buffer.Position = startPosition; return(false); } var type = (VMNetMessageType)buffer.Get(); var data = new List <byte>(); for (int i = 0; i < payloadSize - 1; i++) { data.Add(buffer.Get()); } var packet = new VMNetMessage(type, data.ToArray()); output.Write(packet); return(true); }
/// <summary> /// By default, this method propagates the decoded line of text to <see cref="IProtocolDecoderOutput"/>. /// You may override this method to modify the default behavior. /// </summary> protected virtual void WriteText(IoSession session, String text, IProtocolDecoderOutput output) { output.Write(text); }
/// <summary> /// Decodes the specified session. /// </summary> /// <param name="inbuf">The inbuf.</param> /// <param name="output">The protocol output.</param> /// <returns></returns> public MessageDecoderResult Decode(ByteBuffer inbuf, IProtocolDecoderOutput output) { byte[] header = new byte[4]; inbuf.GetBytes(header); ProtocolInitiation pi = new ProtocolInitiation(); pi.Header = new char[]{'A','M','Q','P'}; pi.ProtocolClass = inbuf.GetByte(); pi.ProtocolInstance = inbuf.GetByte(); pi.ProtocolMajor = inbuf.GetByte(); pi.ProtocolMinor = inbuf.GetByte(); output.Write(pi); return MessageDecoderResult.OK; }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { var instr = session.GetAttribute<IInstruction>(KeyName.INSTRUCTION); if (instr != null) output.Write(instr.CreateDecoder().Decode(input)); return MessageDecoderResult.OK; }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { output.Write(input); return(MessageDecoderResult.OK); }
protected override bool DoDecode(IoSession session, IoBuffer buffer, IProtocolDecoderOutput output) { if (buffer.Remaining < 12) { return(false); } /** * We expect aries, voltron or electron packets */ var startPosition = buffer.Position; buffer.Order = ByteOrder.LittleEndian; uint packetType = buffer.GetUInt32(); uint timestamp = buffer.GetUInt32(); uint payloadSize = buffer.GetUInt32(); if (buffer.Remaining < payloadSize) { /** Not all here yet **/ buffer.Position = startPosition; return(false); } //LOG.Info("[ARIES] " + packetType + " (" + payloadSize + ")"); if (packetType == AriesPacketType.Voltron.GetPacketCode()) { DecodeVoltronStylePackets(buffer, ref payloadSize, output, VoltronPackets.GetByPacketCode); } else if (packetType == AriesPacketType.Electron.GetPacketCode()) { DecodeVoltronStylePackets(buffer, ref payloadSize, output, ElectronPackets.GetByPacketCode); } else if (packetType == AriesPacketType.Gluon.GetPacketCode()) { DecodeVoltronStylePackets(buffer, ref payloadSize, output, GluonPackets.GetByPacketCode); } else { //Aries var packetClass = AriesPackets.GetByPacketCode(packetType); if (packetClass != null) { byte[] data = new byte[(int)payloadSize]; buffer.Get(data, 0, (int)payloadSize); IAriesPacket packet = (IAriesPacket)Activator.CreateInstance(packetClass); packet.Deserialize(IoBuffer.Wrap(data), Context); output.Write(packet); payloadSize = 0; } else { buffer.Skip((int)payloadSize); payloadSize = 0; } } return(true); }
protected override Boolean DoDecode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { Assert.IsTrue(input.HasRemaining); if (input.Remaining < 4) return false; output.Write(input.GetInt32()); return true; }
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output) { output.Write(_decodeMessage); return MessageDecoderResult.OK; }
public MessageDecoderResult Decode(ByteBuffer input, IProtocolDecoderOutput output) { output.Write(CreateAndPopulateFrame(input)); return(MessageDecoderResult.OK); }
protected virtual void WriteText(IoSession session, String text, IProtocolDecoderOutput output) { output.Write(text); }
public MessageDecoderResult Decode(ByteBuffer input, IProtocolDecoderOutput output) { output.Write(CreateAndPopulateFrame(input)); return MessageDecoderResult.OK; }