private static void SaveArray(IList list, BinaryWriter writer) { writer.WriteNumberMostlyBelow255(list.Count); if (list.Count == 0) return; if (AreAllElementsTheSameType(list)) SaveArrayWhenAllElementsAreTheSameType(list, writer); else SaveArrayWhenAllElementsAreNotTheSameType(list, writer); }
public static byte[] GetTestBytesWithLengthHeader(int numberOfWishedTestBytes) { var data = new MemoryStream(); var writer = new BinaryWriter(data); writer.WriteNumberMostlyBelow255(numberOfWishedTestBytes); writer.Write(false); for (int num = 0; num < numberOfWishedTestBytes; num++) writer.Write((byte)(100 + num)); return data.ToArray(); }
private static void SaveDictionary(IDictionary data, BinaryWriter writer) { writer.WriteNumberMostlyBelow255(data.Count); if (data.Count == 0) return; if (AreAllDictionaryValuesTheSameType(data)) SaveDictionaryWhenAllValuesAreTheSameType(data, writer); else SaveDictionaryWhenAllValuesAreNotTheSameType(data, writer); }
private static void SaveCharArray(object data, BinaryWriter writer) { writer.WriteNumberMostlyBelow255(((char[])data).Length); writer.Write((char[])data); }
private static void SaveMemoryStream(object data, BinaryWriter writer) { var stream = data as MemoryStream; writer.WriteNumberMostlyBelow255((int)stream.Length); writer.Write(stream.ToArray()); }
public void WriteAndReadNumberMostlyBelow255WithANumberOver255() { var data = new MemoryStream(); var writer = new BinaryWriter(data); const int NumberOver255 = 123456; writer.WriteNumberMostlyBelow255(NumberOver255); data.Position = 0; var reader = new BinaryReader(data); Assert.AreEqual(NumberOver255, reader.ReadNumberMostlyBelow255()); }
public static byte[] ToByteArrayWithLengthHeader(byte[] messageData, bool dataIsCompressed) { using (var total = new MemoryStream()) using (var writer = new BinaryWriter(total)) { writer.WriteNumberMostlyBelow255(messageData.Length); writer.Write(dataIsCompressed); writer.Write(messageData); return total.ToArray(); } }