24 using System.Runtime.InteropServices;
26 using SiliconStudio.Core.Serialization;
27 using SiliconStudio.Core.Serialization.Serializers;
35 [StructLayout(LayoutKind.Sequential, Size = 4)]
36 internal struct FourCC : IEquatable<FourCC>
38 private readonly uint value;
44 public FourCC(
string fourCC)
46 if (fourCC.Length != 4)
47 throw new ArgumentException(
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"Invalid length for FourCC(\"{0}\". Must be be 4 characters long ", fourCC),
"fourCC");
48 this.value = ((uint)fourCC[3]) << 24 | ((uint)fourCC[2]) << 16 | ((uint)fourCC[1]) << 8 | ((uint)fourCC[0]);
58 public FourCC(
char byte1,
char byte2,
char byte3,
char byte4)
60 this.value = ((uint)byte4) << 24 | ((uint)byte3) << 16 | ((uint)byte2) << 8 | ((uint)byte1);
67 public FourCC(uint fourCC)
76 public FourCC(
int fourCC)
78 this.value = unchecked((uint)fourCC);
88 public static implicit
operator uint(FourCC d)
100 public static implicit
operator int(FourCC d)
102 return unchecked((
int)d.value);
112 public static implicit
operator FourCC(uint d)
114 return new FourCC(d);
124 public static implicit
operator FourCC(
int d)
126 return new FourCC(d);
136 public static implicit
operator string(FourCC d)
148 public static implicit
operator FourCC(
string d)
150 return new FourCC(d);
153 public override string ToString()
155 return string.Format(
"{0}",
new string(
new[]
157 (char) (value & 0xFF),
158 (char) ((value >> 8) & 0xFF),
159 (
char) ((value >> 16) & 0xFF),
160 (char) ((value >> 24) & 0xFF),
164 public bool Equals(FourCC other)
166 return value == other.value;
169 public override bool Equals(
object obj)
171 if (ReferenceEquals(null, obj))
return false;
172 return obj is FourCC && Equals((FourCC) obj);
175 public override int GetHashCode()
180 public static bool operator ==(FourCC left, FourCC right)
182 return left.Equals(right);
185 public static bool operator !=(FourCC left, FourCC right)
187 return !left.Equals(right);
195 stream.Write(fourCC.value);
197 fourCC =
new FourCC(stream.ReadUInt32());
override void Serialize(ref FourCC fourCC, ArchiveMode mode, SerializationStream stream)
Base class for implementation of SerializationStream.
Describes how to serialize and deserialize an object without knowing its type. Used as a common base ...
ArchiveMode
Enumerates the different mode of serialization (either serialization or deserialization).