public void Serialize(CueSerializeContext context) { if (context.Version >= 4) { context.bw.Write(path); } else { throw new NotSupportedException("Legacy formats are not supported."); } }
public void Serialize(CueSerializeContext context) { context.bw.WriteNullableStringNonBlank(friendlyName); context.bw.Write((byte)type); context.bw.Write(radius); context.bw.Write(pitch); context.bw.Write(pan); context.bw.Write(volume); context.bw.Write(sounds.Count); foreach (var sound in sounds) { context.WriteSound(sound); } if (context.Version >= 2) { context.bw.WriteNullableSingle(minPitch); context.bw.WriteNullableSingle(maxPitch); } }
/// <summary>Check that an Cue round-trips through serialization cleanly</summary> public void RoundTripCheck() { // Serialize a first time MemoryStream firstMemoryStream = new MemoryStream(); CueSerializeContext firstSerializeContext = new CueSerializeContext(new BinaryWriter(firstMemoryStream)); Serialize(firstSerializeContext); byte[] originalData = firstMemoryStream.ToArray(); // Then deserialize that data BinaryReader br = new BinaryReader(new MemoryStream(originalData)); CueDeserializeContext deserializeContext = new CueDeserializeContext(br); Cue deserialized = new Cue(deserializeContext); // Then serialize that deserialized data and see if it matches MemoryCompareStream secondMemoryStream = new MemoryCompareStream(originalData); CueSerializeContext secondSerializeContext = new CueSerializeContext(new BinaryWriter(secondMemoryStream)); deserialized.Serialize(secondSerializeContext); }