public void Test_decode_32() { NumHeader.decodeReturn ret = NumHeader.decode(new List <byte> { 0x00 }, 0, 32); Assert.AreEqual(ret.value, (uint)0x00); Assert.AreEqual(ret.bytesParsed, 1); ret = NumHeader.decode(new List <byte> { 0x7F }, 0, 32); Assert.AreEqual(ret.value, (uint)0x7F); Assert.AreEqual(ret.bytesParsed, 1); ret = NumHeader.decode(new List <byte> { 0x80, 0x00, 0x00, 0x80 }, 0, 32); Assert.AreEqual(ret.value, (uint)0x80); Assert.AreEqual(ret.bytesParsed, 4); ret = NumHeader.decode(new List <byte> { 0x80, 0x00, 0x7F, 0xFF }, 0, 32); Assert.AreEqual(ret.value, (uint)0x7FFF); Assert.AreEqual(ret.bytesParsed, 4); ret = NumHeader.decode(new List <byte> { 0x80, 0x00, 0x80, 0x00 }, 0, 32); Assert.AreEqual(ret.value, (uint)0x8000); Assert.AreEqual(ret.bytesParsed, 4); ret = NumHeader.decode(new List <byte> { 0xFF, 0xFF, 0xFF, 0xFF }, 0, 32); Assert.AreEqual(ret.value, (uint)0x7FFFFFFF); Assert.AreEqual(ret.bytesParsed, 4); }
public int _parseMessage(List <byte> data, int iBegin) { NumHeader.decodeReturn ret = NumHeader.decode(data, iBegin, 32); int iNext; if (ret.bytesParsed < 0) { return(ret.bytesParsed); } else if (ret.bytesParsed == 0) { return(iBegin); } else { iNext = iBegin + (int)ret.bytesParsed; if (iNext + ret.value <= data.Count) { List <byte> msg = data.GetRange(iNext, (int)ret.value); if (isAcknowledgeSeen == false) { if (msg.Count == 8 && (msg.SequenceEqual(new byte[] { 0xbf, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00 }))) { // We are connected isAcknowledgeSeen = true; receiveHandler.onConnected(this); return(iNext + (int)ret.value); } else { throw new ArgumentException("expected acknowledge from apx_server but something else"); } } else if (receiveHandler != null) { receiveHandler.onMsgReceived(msg); return(iNext + (int)ret.value); } else { throw new ArgumentException("receiveHandler is null"); } } else { return(iBegin); } } }