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 }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); } }
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); } }
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); }