예제 #1
0
        private void FlushReceivingQueue()
        {
            if (this.mReceivingSemaphore.WaitOne(0) == true)
            {
                // handle required packets
                while (this.mPacketizer.PacketCount > 0 && this.mPacketReceiveCallback != null)
                {
                    try
                    {
                        // unmarshal the packet
                        PyDataType packet = Unmarshal.ReadFromByteArray(this.mPacketizer.PopItem());
#if DEBUG
                        this.mPacketLog.Trace(PrettyPrinter.FromDataType(packet));
#endif
                        // and invoke the callback for the packet handling if it is present
                        this.mPacketReceiveCallback.Invoke(packet);
                    }
                    catch (Exception e)
                    {
                        this.HandleException(e);
                    }
                }

                // finally free the receiving semaphore
                this.mReceivingSemaphore.Release();
            }

            // semaphore not acquired, there's something already sending data, so we're sure the data will get there eventually
        }
예제 #2
0
        public void BooleanUnmarshal_False()
        {
            PyDataType result = Unmarshal.ReadFromByteArray(sBooleanMarshal_FalseValueBuffer, false);

            Assert.IsInstanceOf <PyBool>(result);

            PyBool pyBool = result as PyBool;

            Assert.AreEqual(sBooleanMarshal_FalseValue, pyBool.Value);
        }
예제 #3
0
        public void ListUnmarshal_Empty()
        {
            PyDataType value = Unmarshal.ReadFromByteArray(sListMarshaling_Empty, false);

            Assert.IsInstanceOf <PyList>(value);

            PyList list = value as PyList;

            Assert.AreEqual(0, list.Count);
        }
예제 #4
0
        public void TupleUnmarshal_Empty()
        {
            PyDataType value = Unmarshal.ReadFromByteArray(sTupleMarshaling_Empty, false);

            Assert.IsInstanceOf <PyTuple>(value);

            PyTuple tuple = value as PyTuple;

            Assert.AreEqual(0, tuple.Count);
        }
예제 #5
0
        public void DecimalUnmarshal_Value()
        {
            PyDataType value = Unmarshal.ReadFromByteArray(sDecimal_ValueBuffer, false);

            Assert.IsInstanceOf <PyDecimal>(value);

            PyDecimal @decimal = value as PyDecimal;

            Assert.AreEqual(sDecimal_Value, @decimal.Value);
        }
예제 #6
0
        public void TokenUmarshal_Normal()
        {
            PyDataType result = Unmarshal.ReadFromByteArray(sTokenMarshal_NormalBuffer, false);

            Assert.IsInstanceOf <PyToken>(result);

            PyToken pyToken = result as PyToken;

            Assert.AreEqual(sTokenMarshal_Normal.Length, pyToken.Length);
            Assert.AreEqual(sTokenMarshal_Normal, pyToken.Token);
        }
예제 #7
0
        public void ListUnmarshal_One()
        {
            PyDataType value = Unmarshal.ReadFromByteArray(sListMarshaling_One, false);

            Assert.IsInstanceOf <PyList>(value);

            PyList list = value as PyList;

            Assert.AreEqual(1, list.Count);
            Assert.IsInstanceOf <PyInteger>(list[0]);
            Assert.AreEqual(sListMarshaling_FirstValue, (list[0] as PyInteger).Value);
        }
예제 #8
0
        public void IntegerUnmarshal_Long2()
        {
            PyDataType result = Unmarshal.ReadFromByteArray(sIntegerMarshal_LongValue2Buffer, false);

            Assert.IsInstanceOf <PyInteger>(result);

            PyInteger pyInteger = result as PyInteger;

            Assert.AreEqual(sIntegerMarshal_LongValue2, pyInteger.Value);
            Assert.AreEqual(true, sIntegerMarshal_LongValue2 == pyInteger);
            Assert.AreEqual(PyInteger.IntegerTypeEnum.Long, pyInteger.IntegerType);
        }
예제 #9
0
        public void TupleUnmarshal_One()
        {
            PyDataType value = Unmarshal.ReadFromByteArray(sTupleMarshaling_One, false);

            Assert.IsInstanceOf <PyTuple>(value);

            PyTuple tuple = value as PyTuple;

            Assert.AreEqual(1, tuple.Count);
            Assert.IsInstanceOf <PyInteger>(tuple[0]);
            Assert.AreEqual(sTupleMarshaling_FirstValue, (tuple[0] as PyInteger).Value);
        }
예제 #10
0
        public void StringUnmarshal_LongMultiByteString()
        {
            PyDataType result = Unmarshal.ReadFromByteArray(sStringMarshal_LongMultiByteStringBuffer, false);

            Assert.IsInstanceOf <PyString>(result);

            PyString pyString = result as PyString;

            Assert.AreEqual(sStringMarshal_LongString.Length, pyString.Length);
            Assert.AreEqual(sStringMarshal_LongString, pyString.Value);
            Assert.AreEqual(true, pyString.IsUTF8);
            Assert.AreEqual(false, pyString.IsStringTableEntry);
        }
예제 #11
0
        public void StringUnmarshal_StringTableString()
        {
            PyDataType result = Unmarshal.ReadFromByteArray(sStringMarshal_StringTableBuffer, false);

            Assert.IsInstanceOf <PyString>(result);

            PyString pyString = result as PyString;

            Assert.AreEqual(sStringMarshal_StringTable.Length, pyString.Length);
            Assert.AreEqual(sStringMarshal_StringTable, pyString.Value);
            Assert.AreEqual(StringTableUtils.EntryList.contraband, pyString.StringTableEntryIndex);
            Assert.AreEqual(false, pyString.IsUTF8);
            Assert.AreEqual(true, pyString.IsStringTableEntry);
        }
예제 #12
0
        public void ListUnmarshal_Big()
        {
            PyDataType value = Unmarshal.ReadFromByteArray(sListMarshaling_Big, false);

            Assert.IsInstanceOf <PyList>(value);

            PyList list = value as PyList;

            Assert.AreEqual(256, list.Count);

            foreach (PyDataType entry in list)
            {
                Assert.AreEqual(null, entry);
            }
        }
예제 #13
0
        public void TupleUnmarshal_Big()
        {
            PyDataType value = Unmarshal.ReadFromByteArray(sTupleMarshaling_Big, false);

            Assert.IsInstanceOf <PyTuple>(value);

            PyTuple tuple = value as PyTuple;

            Assert.AreEqual(256, tuple.Count);

            foreach (PyDataType entry in tuple)
            {
                Assert.AreEqual(null, entry);
            }
        }
예제 #14
0
        public void TupleUnmarshal_Three()
        {
            PyDataType value = Unmarshal.ReadFromByteArray(sTupleMarshaling_Three, false);

            Assert.IsInstanceOf <PyTuple>(value);

            PyTuple tuple = value as PyTuple;

            Assert.AreEqual(3, tuple.Count);
            Assert.IsInstanceOf <PyInteger>(tuple[0]);
            Assert.AreEqual(sTupleMarshaling_FirstValue, (tuple[0] as PyInteger).Value);
            Assert.IsInstanceOf <PyString>(tuple[1]);
            Assert.AreEqual(sTupleMarshaling_SecondValue, (tuple[1] as PyString).Value);
            Assert.IsInstanceOf <PyDecimal>(tuple[2]);
            Assert.AreEqual(sTupleMarshaling_ThirdValue, (tuple[2] as PyDecimal).Value);
        }