Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BlobContentId.cs
Go to the documentation of this file.
5
7
8public readonly struct BlobContentId : IEquatable<BlobContentId>
9{
10 public Guid Guid { get; }
11
12 public uint Stamp { get; }
13
14 public bool IsDefault
15 {
16 get
17 {
18 if (Guid == default(Guid))
19 {
20 return Stamp == 0;
21 }
22 return false;
23 }
24 }
25
26 public BlobContentId(Guid guid, uint stamp)
27 {
28 Guid = guid;
29 Stamp = stamp;
30 }
31
33 : this(ImmutableByteArrayInterop.DangerousGetUnderlyingArray(id))
34 {
35 }
36
37 public unsafe BlobContentId(byte[] id)
38 {
39 if (id == null)
40 {
41 throw new ArgumentNullException("id");
42 }
43 if (id.Length != 20)
44 {
46 }
47 fixed (byte* buffer = &id[0])
48 {
49 BlobReader blobReader = new BlobReader(buffer, id.Length);
50 Guid = blobReader.ReadGuid();
51 Stamp = blobReader.ReadUInt32();
52 }
53 }
54
59
60 public static BlobContentId FromHash(byte[] hashCode)
61 {
62 if (hashCode == null)
63 {
64 throw new ArgumentNullException("hashCode");
65 }
66 if (hashCode.Length < 20)
67 {
68 throw new ArgumentException(System.SR.Format(System.SR.HashTooShort, 20), "hashCode");
69 }
70 uint a = (uint)((hashCode[3] << 24) | (hashCode[2] << 16) | (hashCode[1] << 8) | hashCode[0]);
71 ushort num = (ushort)((hashCode[5] << 8) | hashCode[4]);
72 ushort num2 = (ushort)((hashCode[7] << 8) | hashCode[6]);
73 byte b = hashCode[8];
74 byte e = hashCode[9];
75 byte f = hashCode[10];
76 byte g = hashCode[11];
77 byte h = hashCode[12];
78 byte i = hashCode[13];
79 byte j = hashCode[14];
80 byte k = hashCode[15];
81 num2 = (ushort)((num2 & 0xFFFu) | 0x4000u);
82 b = (byte)((b & 0x3Fu) | 0x80u);
83 Guid guid = new Guid((int)a, (short)num, (short)num2, b, e, f, g, h, i, j, k);
84 uint stamp = 0x80000000u | (uint)((hashCode[19] << 24) | (hashCode[18] << 16) | (hashCode[17] << 8) | hashCode[16]);
85 return new BlobContentId(guid, stamp);
86 }
87
89 {
90 uint timestamp = (uint)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
91 return (IEnumerable<Blob> content) => new BlobContentId(Guid.NewGuid(), timestamp);
92 }
93
95 {
96 if (Guid == other.Guid)
97 {
98 return Stamp == other.Stamp;
99 }
100 return false;
101 }
102
103 public override bool Equals([NotNullWhen(true)] object? obj)
104 {
106 {
107 return Equals(other);
108 }
109 return false;
110 }
111
112 public override int GetHashCode()
113 {
114 return Hash.Combine(Stamp, Guid.GetHashCode());
115 }
116
117 public static bool operator ==(BlobContentId left, BlobContentId right)
118 {
119 return left.Equals(right);
120 }
121
122 public static bool operator !=(BlobContentId left, BlobContentId right)
123 {
124 return !left.Equals(right);
125 }
126}
static int Combine(int newKey, int currentKey)
Definition Hash.cs:11
static ? byte[] DangerousGetUnderlyingArray(ImmutableArray< byte > array)
static string UnexpectedArrayLength
Definition SR.cs:216
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string HashTooShort
Definition SR.cs:214
Definition SR.cs:7
static unsafe DateTime UtcNow
Definition DateTime.cs:142
Guid(byte[] b)
Definition Guid.cs:110
override int GetHashCode()
Definition Guid.cs:700
static Guid NewGuid()
Definition Guid.cs:1283
override bool Equals([NotNullWhen(true)] object? obj)
static BlobContentId FromHash(ImmutableArray< byte > hashCode)
static bool operator==(BlobContentId left, BlobContentId right)
static bool operator!=(BlobContentId left, BlobContentId right)
BlobContentId(ImmutableArray< byte > id)
static Func< IEnumerable< Blob >, BlobContentId > GetTimeBasedProvider()
static BlobContentId FromHash(byte[] hashCode)