| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Lattice.ECS.Core |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// 当前快照 / checkpoint 实际写出的组件 schema 清单摘要。 |
| | | 7 | | /// 用于把“这一份序列化负载依赖的组件协议是什么”显式固化到代码层, |
| | | 8 | | /// 避免未来格式演进时只能靠经验判断兼容性。 |
| | | 9 | | /// </summary> |
| | | 10 | | public readonly struct ComponentSchemaManifest : IEquatable<ComponentSchemaManifest> |
| | | 11 | | { |
| | | 12 | | public const int CurrentVersion = 1; |
| | | 13 | | |
| | | 14 | | public ComponentSchemaManifest( |
| | | 15 | | ComponentSerializationMode serializationMode, |
| | | 16 | | ulong fingerprint, |
| | | 17 | | int serializedComponentCount, |
| | | 18 | | int version = CurrentVersion) |
| | | 19 | | { |
| | 322 | 20 | | if (version < 0) |
| | | 21 | | { |
| | 0 | 22 | | throw new ArgumentOutOfRangeException(nameof(version), "Component schema manifest version cannot be nega |
| | | 23 | | } |
| | | 24 | | |
| | 322 | 25 | | if (serializedComponentCount < 0) |
| | | 26 | | { |
| | 0 | 27 | | throw new ArgumentOutOfRangeException(nameof(serializedComponentCount), "Serialized component count cann |
| | | 28 | | } |
| | | 29 | | |
| | 322 | 30 | | SerializationMode = serializationMode; |
| | 322 | 31 | | Fingerprint = fingerprint; |
| | 322 | 32 | | SerializedComponentCount = serializedComponentCount; |
| | 322 | 33 | | Version = version; |
| | 322 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// 当前 manifest 是否已经明确指定。 |
| | | 38 | | /// 旧兼容入口构造的快照可能不包含 schema 摘要,此时不强制执行 schema 校验。 |
| | | 39 | | /// </summary> |
| | 237 | 40 | | public bool IsSpecified => Version > 0; |
| | | 41 | | |
| | 478 | 42 | | public int Version { get; } |
| | | 43 | | |
| | 318 | 44 | | public ComponentSerializationMode SerializationMode { get; } |
| | | 45 | | |
| | 243 | 46 | | public ulong Fingerprint { get; } |
| | | 47 | | |
| | 239 | 48 | | public int SerializedComponentCount { get; } |
| | | 49 | | |
| | | 50 | | public static ComponentSchemaManifest Unspecified(ComponentSerializationMode serializationMode) |
| | | 51 | | { |
| | 0 | 52 | | return new ComponentSchemaManifest(serializationMode, 0, 0, version: 0); |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | public bool Equals(ComponentSchemaManifest other) |
| | | 56 | | { |
| | 120 | 57 | | return Version == other.Version && |
| | 120 | 58 | | SerializationMode == other.SerializationMode && |
| | 120 | 59 | | Fingerprint == other.Fingerprint && |
| | 120 | 60 | | SerializedComponentCount == other.SerializedComponentCount; |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | public override bool Equals(object? obj) |
| | | 64 | | { |
| | 0 | 65 | | return obj is ComponentSchemaManifest other && Equals(other); |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | public override int GetHashCode() |
| | | 69 | | { |
| | 0 | 70 | | return HashCode.Combine(Version, (int)SerializationMode, Fingerprint, SerializedComponentCount); |
| | | 71 | | } |
| | | 72 | | } |
| | | 73 | | } |