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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }