public void ReadResponse(byte[] datas, long offset, long size, out byte[] rcvData) { serializer.SetBuffer(datas, offset, size); methodId = (ushort)((uint)serializer.ReadUShort() & 0x3FFF); //0x3F (0011 1111) sets left most 2 bits to 00 methodLength = serializer.ReadUShort(); transactionID = serializer.ReadBytes(16); if (!Enum.IsDefined(typeof(STUNMethod), (STUNMethod)methodId) || methodLength != serializer.byteLength - serializer.bytePos) { serializer.SetStartPos(); isIndicateData = IsSTUNMessage = false; serializer.ReverserBuffer((int)offset, 4); ushort appSize = serializer.ReadUShort(); responseChannelNumber = serializer.ReadUShort(); rcvData = new byte[appSize]; Array.Copy(datas, 4, rcvData, 0, appSize); return; } method = (STUNMethod)methodId; isIndicateData = method == STUNMethod.DataIndication; IsSTUNMessage = !isIndicateData; ReadAttribute(out rcvData); }