コード例 #1
0
ファイル: LocatorEncoder.cs プロジェクト: Egipto87/DOOP.ec
        public static void ReadLocator(IoBuffer buffer, ref Locator obj)
        {
            if (obj == null)
                obj = new Locator();
            obj.Kind = (LocatorKind)buffer.GetInt32();
            obj.Port = (int)buffer.GetInt32(); ;
            byte[] tmp = new byte[16];

            buffer.Get(tmp, 0, 16);
            obj.SocketAddressBytes = tmp;
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        /// <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;
        }
コード例 #5
0
        protected override Message.AbstractMessage DecodeBody(IoSession session, IoBuffer input)
        {
            if (input.Remaining < Constants.ADD_BODY_LEN)
            {
                return null;
            }

            AddMessage m = new AddMessage();
            m.Value = input.GetInt32();
            return m;
        }
コード例 #6
0
        public void TestSweepNonZeros()
        {
            IoBuffer buf = ByteBufferAllocator.Instance.Allocate(4);
            Int32    i;

            unchecked
            {
                i = (Int32)0xdeadbeef;
            }
            buf.PutInt32(i);
            buf.Clear();
            Assert.AreEqual(i, buf.GetInt32());
            Assert.AreEqual(4, buf.Position);
            Assert.AreEqual(4, buf.Limit);

            buf.Sweep((byte)0x45);
            Assert.AreEqual(0, buf.Position);
            Assert.AreEqual(4, buf.Limit);
            Assert.AreEqual(0x45454545, buf.GetInt32());
        }
コード例 #7
0
        public void TestSweepWithZeros()
        {
            IoBuffer buf = allocator.Allocate(4);
            Int32    i;

            unchecked
            {
                i = (Int32)0xdeadbeef;
            }
            buf.PutInt32(i);
            buf.Clear();
            Assert.AreEqual(i, buf.GetInt32());
            Assert.AreEqual(4, buf.Position);
            Assert.AreEqual(4, buf.Limit);

            buf.Sweep();
            Assert.AreEqual(0, buf.Position);
            Assert.AreEqual(4, buf.Limit);
            Assert.AreEqual(0x0, buf.GetInt32());
        }
コード例 #8
0
 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;
 }
コード例 #9
0
        public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
        {
            if (input.Remaining < MESSAGE_LENGTH_BYTES_LENGTH)
                return MessageDecoderResult.NeedData;
            var len = input.GetInt32();
            if (len > MAX_MESSAGE_LENGTH)
                return MessageDecoderResult.NotOK;
            if (input.Remaining + MESSAGE_LENGTH_BYTES_LENGTH < len)
                return MessageDecoderResult.NeedData;
            var version = input.Get().ToEnum<MessageVersion>();
            if (version == MessageVersion.BadVersion)
                return MessageDecoderResult.NotOK;
            if (len < FixedHeaderLength(version))
                return MessageDecoderResult.NotOK;

            return MessageDecoderResult.OK;
        }
コード例 #10
0
        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());
        }
コード例 #11
0
ファイル: IoBufferWrapper.cs プロジェクト: eltonfan/Mina.NET
 /// <inheritdoc/>
 public override Int32 GetInt32()
 {
     return(_buf.GetInt32());
 }
コード例 #12
0
ファイル: Primitives.cs プロジェクト: Egipto87/DOOP.ec
 public static void ReadPrimitive(IoBuffer buffer, out int value)
 {
     value = buffer.GetInt32();
 }
コード例 #13
0
            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;
            }