public BitReaderWriter(IBitSerializable writeData) { m_writeData = writeData; m_readStream = null; m_readStreamPosition = 0; IsReading = false; }
private BitReaderWriter(BitStream readStream, int readPos) { m_writeData = null; m_readStream = readStream; m_readStreamPosition = readPos; IsReading = true; }
static void Prefix(int eventIndex, IBitSerializable serializable) { var outputTxt = ""; outputTxt += $"{debugCount} SEND ReceiveSerializeEvent\n"; debugCount++; if (eventIndex < 0 || eventIndex >= InstancedDataList.Count) { outputTxt += $"\tSending invalid event index: {eventIndex} out of {InstancedDataList.Count}\n"; outputTxt += $"\t{serializable.GetType()}"; } else { outputTxt += $"\t{InstancedDataList[eventIndex]}\n"; } try { outputTxt += DeepPrint(serializable, 2, printableProps) + "\n"; } catch (Exception e) { outputTxt += $"\tFailed to read data because: {e}\n"; } Console.WriteLine(outputTxt); }
static void DebugBytes(string name, byte[] bytes, List <Type> dataLookup) { var hex = System.BitConverter.ToString(bytes).Replace("-", ""); var ascii = System.Text.Encoding.ASCII.GetString(bytes); var outputTxt = ""; outputTxt += $"{debugCount} RECV {name}\n"; debugCount++; if (dataLookup == null) { outputTxt += $"\tNo data lookup\n"; outputTxt += $"\tHex: {hex}\n"; outputTxt += $"\tAscii: {ascii}\n"; } else { debugBitStreamReader.Encapsulate(bytes); int index = 0; debugBitStreamReader.Serialize(ref index); if (index < 0 || index >= dataLookup.Count) { outputTxt += $"\tReceived invalid event index: {index} out of {dataLookup.Count}\n"; outputTxt += $"\tHex: {hex}\n"; outputTxt += $"\tAscii: {ascii}\n"; } else { try { IBitSerializable data = (IBitSerializable)Activator.CreateInstance(dataLookup[index]); data.Serialize(debugBitStreamReader); outputTxt += $"\t{dataLookup[index]}\n"; outputTxt += DeepPrint(data, 2, printableProps) + "\n"; } catch (Exception e) { outputTxt += $"\tFailed to read data because: {e}"; } } } Console.WriteLine(outputTxt); }
/// <summary> /// Returns false when validation was required and failed, otherwise true. /// </summary> public bool ReadData(IBitSerializable readDataInto, bool validate) { Debug.Assert(m_readStream != null, "Local invocation is not supported for BitReaderWriter"); //if (m_readStream == null) //{ // tmpStream.ResetWrite(); // Write(tmpStream); // tmpStream.ResetRead(); // return ReadFrom(tmpStream).ReadData(readDataInto, validate, null); //} int oldPos = m_readStream.BitPosition; m_readStream.SetBitPositionRead(m_readStreamPosition); try { return readDataInto.Serialize(m_readStream, validate); } finally { m_readStream.SetBitPositionRead(oldPos); } }
/// <summary> /// Returns false when validation was required and failed, otherwise true. /// </summary> public bool ReadData(IBitSerializable readDataInto, bool validate) { Debug.Assert(m_readStream != null, "Local invocation is not supported for BitReaderWriter"); //if (m_readStream == null) //{ // tmpStream.ResetWrite(); // Write(tmpStream); // tmpStream.ResetRead(); // return ReadFrom(tmpStream).ReadData(readDataInto, validate, null); //} int oldPos = m_readStream.BitPosition; m_readStream.SetBitPositionRead(m_readStreamPosition); try { return(readDataInto.Serialize(m_readStream, validate)); } finally { m_readStream.SetBitPositionRead(oldPos); } }
public void ReadSerializable(IBitSerializable obj) { obj.Deserialize(this); }
public void Read(ref IBitSerializable obj) { ReadSerializable(obj); }
public void WriteSerializable(IBitSerializable obj) { obj.Serialize(this); }
static void Prefix(NetworkGroup group, string rpcName, NetworkTarget networkTarget, int eventIndex, IBitSerializable serializable) { var outputTxt = ""; outputTxt += $"{debugCount} SEND {rpcName}\n"; debugCount++; if (networkTarget.UsingRPCMode_) { var mode = typeof(NetworkTarget) .GetField( "mode_", BindingFlags.Instance | BindingFlags.NonPublic ) .GetValue(networkTarget); if (networkTarget.SendToSelf_) { mode = RPCMode.All; } outputTxt += $"\tTo RPCMode {mode}\n"; } else { var recipient = typeof(NetworkTarget) .GetField( "recipient_", BindingFlags.Instance | BindingFlags.NonPublic ) .GetValue(networkTarget); outputTxt += $"\tTo Player {recipient}\n"; } outputTxt += $"\tIn {group}\n"; List <Type> dataLookup = null; if (rpcName == "ReceiveBroadcastAllEvent") { dataLookup = ClientToClientDataList; } else if (rpcName == "ReceiveClientToServerEvent") { dataLookup = ClientToServerDataList; } else if (rpcName == "ReceiveServerToClientEvent" || rpcName == "ReceiveTargetedEventServerToClient") { dataLookup = ServerToClientDataList; } else { outputTxt += "\tUnknown Event\n"; } if (dataLookup != null) { if (eventIndex < 0 || eventIndex >= dataLookup.Count) { outputTxt += $"\tSending invalid event index: {eventIndex} out of {dataLookup.Count}\n"; } } try { var data = serializable; if (dataLookup != null) { outputTxt += $"\t{dataLookup[eventIndex]}\n"; } else { outputTxt += $"\t{data.GetType()}"; } outputTxt += DeepPrint(data, 2, printableProps) + "\n"; } catch (Exception e) { outputTxt += $"\tFailed to read data because: {e}\n"; } if (outputTxt.Length > 0) { outputTxt = outputTxt.Substring(0, outputTxt.Length - 1); } Console.WriteLine(outputTxt); }