public static unsafe void SendProtocolVersion(DynamicBuffer <OutgoingRpcDataStreamBufferComponent> buffer, NetworkProtocolVersion version) { DataStreamWriter writer = new DataStreamWriter(UnsafeUtility.SizeOf <NetworkProtocolVersion>() + 2 + 1, Allocator.Temp); #if ENABLE_UNITY_COLLECTIONS_CHECKS if (buffer.Length != 0) { throw new InvalidOperationException("Protocol version must be the very first RPC sent"); } #endif writer.Write((byte)NetworkStreamProtocol.Rpc); writer.Write(ushort.MaxValue); writer.Write(version.NetCodeVersion); writer.Write(version.GameVersion); writer.Write(version.RpcCollectionVersion); var prevLen = buffer.Length; buffer.ResizeUninitialized(buffer.Length + writer.Length); byte *ptr = (byte *)buffer.GetUnsafePtr(); ptr += prevLen; UnsafeUtility.MemCpy(ptr, writer.GetUnsafeReadOnlyPtr(), writer.Length); }
public static unsafe void SendProtocolVersion(DynamicBuffer <OutgoingRpcDataStreamBufferComponent> buffer, NetworkProtocolVersion version) { bool dynamicAssemblyList = (version.RpcCollectionVersion == 0); int msgHeaderLen = dynamicAssemblyList ? 10 : 4; DataStreamWriter writer = new DataStreamWriter(UnsafeUtility.SizeOf <NetworkProtocolVersion>() + msgHeaderLen + 1, Allocator.Temp); #if ENABLE_UNITY_COLLECTIONS_CHECKS if (buffer.Length != 0) { throw new InvalidOperationException("Protocol version must be the very first RPC sent"); } #endif writer.WriteByte((byte)NetworkStreamProtocol.Rpc); if (dynamicAssemblyList) { writer.WriteULong(0); } else { writer.WriteUShort(ushort.MaxValue); } var lenWriter = writer; writer.WriteUShort((ushort)0); writer.WriteInt(version.NetCodeVersion); writer.WriteInt(version.GameVersion); if (dynamicAssemblyList) { writer.WriteULong(0); writer.WriteULong(0); } else { writer.WriteULong(version.RpcCollectionVersion); writer.WriteULong(version.ComponentCollectionVersion); } lenWriter.WriteUShort((ushort)(writer.Length - msgHeaderLen - 1)); var prevLen = buffer.Length; buffer.ResizeUninitialized(buffer.Length + writer.Length); byte *ptr = (byte *)buffer.GetUnsafePtr(); ptr += prevLen; UnsafeUtility.MemCpy(ptr, writer.AsNativeArray().GetUnsafeReadOnlyPtr(), writer.Length); }