コード例 #1
0
ファイル: BinaryDataSaver.cs プロジェクト: remy22/DeltaEngine
 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);
 }
コード例 #2
0
		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();
		}
コード例 #3
0
		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);
		}
コード例 #4
0
		private static void SaveCharArray(object data, BinaryWriter writer)
		{
			writer.WriteNumberMostlyBelow255(((char[])data).Length);
			writer.Write((char[])data);
		}
コード例 #5
0
		private static void SaveMemoryStream(object data, BinaryWriter writer)
		{
			var stream = data as MemoryStream;
			writer.WriteNumberMostlyBelow255((int)stream.Length);
			writer.Write(stream.ToArray());
		}
コード例 #6
0
		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());
		}
コード例 #7
0
ファイル: TcpSocket.cs プロジェクト: remy22/DeltaEngine
 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();
     }
 }