예제 #1
0
 public void Should_read_and_write_custom_structs()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         var value = new CustomStruct {Field1 = 42, Field2 = TimeSpan.FromHours(42), Field3 = DateTime.UtcNow};
         wrapper.Write(ref value);
         Assert.AreEqual(wrapper.Position, sizeof(CustomStruct));
         wrapper.ResetCursor();
         var readValue = wrapper.Read<CustomStruct>();
         Assert.AreEqual(value, readValue);
     }
 }
예제 #2
0
 public void Should_read_and_write_decimals()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         const decimal value = 42.42m;
         wrapper.Write(value);
         Assert.AreEqual(wrapper.Position, sizeof (decimal));
         wrapper.ResetCursor();
         var readValue = wrapper.ReadDecimal();
         Assert.AreEqual(value, readValue);
     }
 }
예제 #3
0
 public void Should_read_and_write_bytes()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         const byte value = (byte) 42;
         wrapper.Write(value);
         Assert.AreEqual(wrapper.Position, sizeof (byte));
         wrapper.ResetCursor();
         var readValue = wrapper.ReadByte();
         Assert.AreEqual(value, readValue);
     }
 }
예제 #4
0
 public void Should_read_and_write_chars()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         const char value = 'x';
         wrapper.Write(value);
         Assert.AreEqual(wrapper.Position, sizeof (char));
         wrapper.ResetCursor();
         var readValue = wrapper.ReadChar();
         Assert.AreEqual(value, readValue);
     }
 }
예제 #5
0
        protected override void DoRun(int batchCount, int batchSize, int messagePartCount)
        {
            using (var wrapper = new UnsafeBufferWrapper(new byte[1024 * 100]))
            {
                var message = CreateMessage(messagePartCount);

                for (var i = 0; i < batchCount; i++)
                {
                    wrapper.ResetCursor();

                    for (var j = 0; j < batchSize; j++)
                    {
                        UnsafeBufferWrapperSerializer2.Serialize(message, wrapper);
                    }
                }
            }
        }
예제 #6
0
 public void Should_read_and_write_ushorts()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         const ushort value = 42;
         wrapper.Write(value);
         Assert.AreEqual(wrapper.Position, sizeof (ushort));
         wrapper.ResetCursor();
         var readValue = wrapper.ReadUInt16();
         Assert.AreEqual(value, readValue);
     }
 }
예제 #7
0
 public void Should_read_and_write_structs()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         var value = Guid.NewGuid();
         wrapper.Write(ref value);
         Assert.AreEqual(wrapper.Position, sizeof (Guid));
         wrapper.ResetCursor();
         var readValue = wrapper.Read<Guid>();
         Assert.AreEqual(value, readValue);
     }
 }
예제 #8
0
 public void Should_read_and_write_longs()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         const long value = 42L;
         wrapper.Write(value);
         Assert.AreEqual(wrapper.Position, sizeof (long));
         wrapper.ResetCursor();
         var readValue = wrapper.ReadInt64();
         Assert.AreEqual(value, readValue);
     }
 }
예제 #9
0
 public void Should_read_and_write_floats()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         const float value = 42.42f;
         wrapper.Write(value);
         Assert.AreEqual(wrapper.Position, sizeof (float));
         wrapper.ResetCursor();
         var readValue = wrapper.ReadSingle();
         Assert.AreEqual(value, readValue);
     }
 }
예제 #10
0
 public void Should_read_and_write_enums()
 {
     var buffer = new byte[1024];
     using (var wrapper = new UnsafeBufferWrapper(buffer))
     {
         var value = ConsoleColor.Cyan;
         wrapper.Write(ref value);
         Assert.AreEqual(wrapper.Position, sizeof (ConsoleColor));
         wrapper.ResetCursor();
         var readValue = wrapper.Read<ConsoleColor>();
         Assert.AreEqual(value, readValue);
     }
 }