Exemplo n.º 1
0
        public static void WriteValueImpl(Stream stream, string s, SerializerSession session)
        {
            int byteCount;
            var bytes = NoAllocBitConverter.GetBytes(s, session, out byteCount);

            stream.Write(bytes, 0, byteCount);
        }
Exemplo n.º 2
0
        private void WriteNewSize()
        {
            // Package size without first bytes reserved for size
            int packageSize = _length - initialPosition;

            // Write size to the reserved bytes without allocation
            NoAllocBitConverter.GetBytes(packageSize, _pool);
        }
Exemplo n.º 3
0
        public void GetBytes_Ulong_ReturnsCorrectValue()
        {
            // Arrange
            ulong source = 5;

            // Act
            byte[] buffer = new byte[8];
            NoAllocBitConverter.GetBytes(source, buffer);
            ulong result = BitConverter.ToUInt64(buffer, 0);

            // Assert
            Assert.Equal(source, result);
        }
Exemplo n.º 4
0
        public void GetBytes_Char_ReturnsCorrectValue()
        {
            // Arrange
            char source = (char)5;

            // Act
            byte[] buffer = new byte[2];
            NoAllocBitConverter.GetBytes(source, buffer);
            char result = BitConverter.ToChar(buffer, 0);

            // Assert
            Assert.Equal(source, result);
        }
Exemplo n.º 5
0
        public void GetBytes_Uint_ReturnsCorrectValue()
        {
            // Arrange
            uint source = 5;

            // Act
            byte[] buffer = new byte[4];
            NoAllocBitConverter.GetBytes(source, buffer);
            uint result = BitConverter.ToUInt32(buffer, 0);

            // Assert
            Assert.Equal(source, result);
        }
Exemplo n.º 6
0
        public void GetBytes_Short_ReturnsCorrectValue()
        {
            // Arrange
            short source = 5;

            // Act
            byte[] buffer = new byte[2];
            NoAllocBitConverter.GetBytes(source, buffer);
            short result = BitConverter.ToInt16(buffer, 0);

            // Assert
            Assert.Equal(source, result);
        }
Exemplo n.º 7
0
        public void GetBytes_Double_ReturnsCorrectValue()
        {
            // Arrange
            double source = 5;

            // Act
            byte[] buffer = new byte[8];
            NoAllocBitConverter.GetBytes(source, buffer);
            double result = BitConverter.ToDouble(buffer, 0);

            // Assert
            Assert.Equal(source, result);
        }
Exemplo n.º 8
0
        public void GetBytes_float_ReturnsCorrectValue()
        {
            // Arrange
            float source = 5;

            // Act
            byte[] buffer = new byte[4];
            NoAllocBitConverter.GetBytes(source, buffer);
            float result = BitConverter.ToSingle(buffer, 0);

            // Assert
            Assert.Equal(source, result);
        }
Exemplo n.º 9
0
        private static void Send(IRequest request, Socket server)
        {
            // todo array pool and stackalloc
            byte[] data;
            using (MemoryStream ms = new MemoryStream())
            {
                SerializationUtils.SerializeToStream(ms, request.Type);
                SerializationUtils.SerializeToStream(ms, request);
                data = ms.ToArray();
            }

            byte[] lengthBytes = new byte[IntSize]; // stackalloc
            NoAllocBitConverter.GetBytes(data.Length, lengthBytes);

            SocketUtils.SendAll(server, lengthBytes);
            SocketUtils.SendAll(server, data);
        }
Exemplo n.º 10
0
 public static void WriteValueImpl(Stream stream, ushort u, byte[] bytes)
 {
     NoAllocBitConverter.GetBytes(u, bytes);
     stream.Write(bytes, 0, Size);
 }
 private static void WriteValueImpl(Stream stream, DateTime dateTime, byte[] bytes)
 {
     NoAllocBitConverter.GetBytes(dateTime, bytes);
     stream.Write(bytes, 0, Size);
 }