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; }
protected override AbstractMessage DecodeBody(IoSession session, IoBuffer input) { if (!_readCode) { if (input.Remaining < Constants.RESULT_CODE_LEN) { return null; // Need more data. } _code = input.GetInt16(); _readCode = true; } if (_code == Constants.RESULT_OK) { if (input.Remaining < Constants.RESULT_VALUE_LEN) { return null; } ResultMessage m = new ResultMessage(); m.OK = true; m.Value = input.GetInt32(); _readCode = false; return m; } else { ResultMessage m = new ResultMessage(); m.OK = false; _readCode = false; return m; } }
internal ParameterListEncapsulation(IoBuffer bb) { #if TODO this.options = bb.GetInt16(); this.parameters = bb.GetParameterList(); #endif throw new NotImplementedException(); }
public MessageDecoderResult Decodable(IoSession session, IoBuffer input) { // Return NeedData if the whole header is not read yet. if (input.Remaining < Constants.HEADER_LEN) return MessageDecoderResult.NeedData; // Return OK if type and bodyLength matches. if (_type == input.GetInt16()) return MessageDecoderResult.OK; // Return NotOK if not matches. return MessageDecoderResult.NotOK; }
public void TestGetUnsigned() { IoBuffer buf = IoBuffer.Allocate(16); buf.Put((byte)0xA4); buf.Put((byte)0xD0); buf.Put((byte)0xB3); buf.Put((byte)0xCD); buf.Flip(); buf.Order = ByteOrder.LittleEndian; buf.Mark(); Assert.AreEqual(0xA4, buf.Get()); buf.Reset(); Assert.AreEqual(0xD0A4, (UInt16)buf.GetInt16()); buf.Reset(); Assert.AreEqual(0xCDB3D0A4L, (UInt32)buf.GetInt32()); }
/// <inheritdoc/> public override Int16 GetInt16() { return(_buf.GetInt16()); }
public static void ReadPrimitive(IoBuffer buffer, out short value) { value = buffer.GetInt16(); }