public void WriteSByte(sbyte value, int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing sbyte ({0} bits)", bits); } #endif InternalWriteByte((byte)value, bits); }
public byte ReadByte(int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading byte ({0} bits)", bits); } #endif return(InternalReadByte(bits)); }
public bool ReadBool() { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading bool (1 bit)"); } #endif return(InternalReadByte(1) == 1); }
public bool WriteBool(bool value) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing bool (1 bit)"); } #endif InternalWriteByte(value ? (byte)1 : (byte)0, 1); return(value); }
public void WriteFloat(float value) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing float (32 bits)"); } #endif UdpByteConverter bytes = value; InternalWriteByte(bytes.Byte0, 8); InternalWriteByte(bytes.Byte1, 8); InternalWriteByte(bytes.Byte2, 8); InternalWriteByte(bytes.Byte3, 8); }
public bool ReadBool() { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading bool (1 bit)"); } #endif //Core.net.bitsIn += 1; Core.net.AddToBandwidthInBuffer(1); //UnityEngine.Debug.Log("Read Bool (1 bit"); return(InternalReadByte(1) == 1); }
public bool WriteBool(bool value) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing bool (1 bit)"); } #endif //Core.net.bitsOut += 1; Core.net.AddToBandwidthOutBuffer(1); //UnityEngine.Debug.Log("Write Bool (1 bit"); InternalWriteByte(value ? (byte)1 : (byte)0, 1); return(value); }
public float ReadFloat() { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading float (32 bits)"); } #endif UdpByteConverter bytes = default(UdpByteConverter); bytes.Byte0 = InternalReadByte(8); bytes.Byte1 = InternalReadByte(8); bytes.Byte2 = InternalReadByte(8); bytes.Byte3 = InternalReadByte(8); return(bytes.Float32); }
public ushort ReadUShort(int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading ushort ({0} bits)", bits); } #endif if (bits <= 8) { return(InternalReadByte(bits)); } else { return((ushort)(InternalReadByte(8) | (InternalReadByte(bits - 8) << 8))); } }
public void WriteUShort(ushort value, int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing ushort ({0} bits)", bits); } #endif if (bits <= 8) { InternalWriteByte((byte)(value & 0xFF), bits); } else { InternalWriteByte((byte)(value & 0xFF), 8); InternalWriteByte((byte)(value >> 8), bits - 8); } }
public void WriteULong(ulong value, int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing ulong ({0} bits)", bits); } #endif if (bits <= 32) { WriteUInt((uint)(value & 0xFFFFFFFF), bits); } else { WriteUInt((uint)(value), 32); WriteUInt((uint)(value >> 32), bits - 32); } }
public void WriteDouble(double value) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing double (64 bits)"); } #endif UdpByteConverter bytes = value; InternalWriteByte(bytes.Byte0, 8); InternalWriteByte(bytes.Byte1, 8); InternalWriteByte(bytes.Byte2, 8); InternalWriteByte(bytes.Byte3, 8); InternalWriteByte(bytes.Byte4, 8); InternalWriteByte(bytes.Byte5, 8); InternalWriteByte(bytes.Byte6, 8); InternalWriteByte(bytes.Byte7, 8); }
public uint ReadUInt(int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading uint ({0} bits)", bits); } #endif //UnityEngine.Debug.Log("Read Int (" + bits + " bits)"); //Core.net.bitsIn += bits; Core.net.AddToBandwidthInBuffer(bits); int a = 0, b = 0, c = 0, d = 0; switch ((bits + 7) / 8) { case 1: a = InternalReadByte(bits); break; case 2: a = InternalReadByte(8); b = InternalReadByte(bits - 8); break; case 3: a = InternalReadByte(8); b = InternalReadByte(8); c = InternalReadByte(bits - 16); break; case 4: a = InternalReadByte(8); b = InternalReadByte(8); c = InternalReadByte(8); d = InternalReadByte(bits - 24); break; } return((uint)(a | (b << 8) | (c << 16) | (d << 24))); }
public double ReadDouble() { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading double (64 bits)"); } #endif UdpByteConverter bytes = default(UdpByteConverter); bytes.Byte0 = InternalReadByte(8); bytes.Byte1 = InternalReadByte(8); bytes.Byte2 = InternalReadByte(8); bytes.Byte3 = InternalReadByte(8); bytes.Byte4 = InternalReadByte(8); bytes.Byte5 = InternalReadByte(8); bytes.Byte6 = InternalReadByte(8); bytes.Byte7 = InternalReadByte(8); return(bytes.Float64); }
public void WriteUInt(uint value, int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing uint ({0} bits)", bits); } #endif //UnityEngine.Debug.Log("Write Int (" + bits + " bits)"); Core.net.AddToBandwidthOutBuffer(bits); //Core.net.bitsOut += bits; //UnityEngine.Debug.Log(string.Format("Writing uint ({0} bits)", bits)); byte a = (byte)(value >> 0), b = (byte)(value >> 8), c = (byte)(value >> 16), d = (byte)(value >> 24); switch ((bits + 7) / 8) { case 1: InternalWriteByte(a, bits); break; case 2: InternalWriteByte(a, 8); InternalWriteByte(b, bits - 8); break; case 3: InternalWriteByte(a, 8); InternalWriteByte(b, 8); InternalWriteByte(c, bits - 16); break; case 4: InternalWriteByte(a, 8); InternalWriteByte(b, 8); InternalWriteByte(c, 8); InternalWriteByte(d, bits - 24); break; } }
public ulong ReadULong(int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading ulong ({0} bits)", bits); } #endif if (bits <= 32) { return(ReadUInt(bits)); } else { ulong a = ReadUInt(32); ulong b = ReadUInt(bits - 32); return(a | (b << 32)); } }
public uint ReadUInt(int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Reading uint ({0} bits)", bits); } #endif int a = 0, b = 0, c = 0, d = 0; switch ((bits + 7) / 8) { case 1: a = InternalReadByte(bits); break; case 2: a = InternalReadByte(8); b = InternalReadByte(bits - 8); break; case 3: a = InternalReadByte(8); b = InternalReadByte(8); c = InternalReadByte(bits - 16); break; case 4: a = InternalReadByte(8); b = InternalReadByte(8); c = InternalReadByte(8); d = InternalReadByte(bits - 24); break; } return((uint)(a | (b << 8) | (c << 16) | (d << 24))); }
public void WriteUInt(uint value, int bits) { #if TRACE_RW if (UdpLog.IsEnabled(UdpLog.TRACE)) { UdpLog.Trace("Writing uint ({0} bits)", bits); } #endif byte a = (byte)(value >> 0), b = (byte)(value >> 8), c = (byte)(value >> 16), d = (byte)(value >> 24); switch ((bits + 7) / 8) { case 1: InternalWriteByte(a, bits); break; case 2: InternalWriteByte(b, 8); InternalWriteByte(c, bits - 8); break; case 3: InternalWriteByte(a, 8); InternalWriteByte(b, 8); InternalWriteByte(c, bits - 16); break; case 4: InternalWriteByte(a, 8); InternalWriteByte(b, 8); InternalWriteByte(c, 8); InternalWriteByte(d, bits - 24); break; } }