public void SetVehicleCode(byte[] src, int srcOffset) { const int length = 6; if (srcOffset < 0 || srcOffset > (src.Length - length)) { throw new IndexOutOfRangeException("srcOffset out of range for copy: offset=" + srcOffset); } _buffer.SetBytes(_offset + 32, src, srcOffset, length); }
public void SetSessionID(ReadOnlySpan <byte> src) { const int length = 10; if (src.Length > length) { ThrowHelper.ThrowWhenSpanLengthTooLarge(src.Length); } _buffer.SetBytes(_offset + 0, src); }
public void SetEnteringTrader(ReadOnlySpan <byte> src) { const int length = 5; if (src.Length > length) { ThrowHelper.ThrowWhenSpanLengthTooLarge(src.Length); } _buffer.SetBytes(_offset + 36, src); }
public void SetVehicleCode(ReadOnlySpan <byte> src) { const int length = 6; if (src.Length > length) { ThrowHelper.ThrowWhenSpanLengthTooLarge(src.Length); } _buffer.SetBytes(_offset + 28, src); }
public void SetQuoteEntryID(byte[] src, int srcOffset) { const int length = 10; if (srcOffset < 0 || srcOffset > (src.Length - length)) { throw new IndexOutOfRangeException("srcOffset out of range for copy: offset=" + srcOffset); } _buffer.SetBytes(_offset + 0, src, srcOffset, length); }
public int SetPackageName(byte[] src, int srcOffset, int length) { const int sizeOfLengthField = 1; int limit = Limit; Limit = limit + sizeOfLengthField + length; _buffer.Uint8Put(limit, (byte)length); _buffer.SetBytes(limit + sizeOfLengthField, src, srcOffset, length); return(length); }
public int SetText(ReadOnlySpan <byte> src) { const int sizeOfLengthField = 1; int limit = _parentMessage.Limit; _parentMessage.Limit = limit + sizeOfLengthField + src.Length; _buffer.Uint8Put(limit, (byte)src.Length); _buffer.SetBytes(limit + sizeOfLengthField, src); return(src.Length); }
public void ShouldGetStringNullTerminated() { var encoding = System.Text.Encoding.ASCII; const string value = "abc123"; var bytes = encoding.GetBytes(value); const int index = 0; var written = _directBuffer.SetBytes(index, bytes, 0, bytes.Length); Assert.AreEqual(bytes.Length, written); var written2 = _directBuffer.SetBytes(index + bytes.Length, new byte[] { Terminator }, 0, 1); Assert.AreEqual(1, written2); string result = _directBuffer.GetStringFromNullTerminatedBytes(encoding, index, _directBuffer.Capacity - index, Terminator); Assert.AreEqual(value, result); }
public void SetVehicleCode(byte[] src, int srcOffset) { const int length = 6; if (srcOffset < 0 || srcOffset > src.Length) { throw new IndexOutOfRangeException("srcOffset out of range for copy: offset=" + srcOffset); } if (src.Length > length) { throw new ArgumentOutOfRangeException($"src.Length={src.Length} is too large."); } _buffer.SetBytes(_offset + 32, src, srcOffset, src.Length - srcOffset); }
public int SetUri(ReadOnlySpan <byte> src) { const int sizeOfLengthField = 4; int limit = _parentMessage.Limit; _parentMessage.Limit = limit + sizeOfLengthField + src.Length; _buffer.Uint32PutLittleEndian(limit, (uint)src.Length); _buffer.SetBytes(limit + sizeOfLengthField, src); return(src.Length); }
public int SetUsageDescription(byte[] src, int srcOffset, int length) { const int sizeOfLengthField = 4; int limit = _parentMessage.Limit; _parentMessage.Limit = limit + sizeOfLengthField + length; _buffer.Uint32PutLittleEndian(limit, (uint)length); _buffer.SetBytes(limit + sizeOfLengthField, src, srcOffset, length); return(length); }
public void SetManufacturerCode(ReadOnlySpan <byte> src) { const int length = 3; if (src.Length > length) { ThrowHelper.ThrowWhenSpanLengthTooLarge(src.Length); } _buffer.SetBytes(_offset + 3, src); }
public static int Put(DirectBuffer buffer, PrimitiveValue value, PrimitiveType type) { if (value == null) { return(0); } switch (type.Type) { case SbePrimitiveType.Char: if (value.Size == 1) { buffer.CharPut(0, (byte)value.LongValue()); return(1); } else { var byteArrayValue = value.ByteArrayValue(); buffer.SetBytes(0, byteArrayValue, 0, byteArrayValue.Length); return(byteArrayValue.Length); } case SbePrimitiveType.Int8: buffer.Int8Put(0, (sbyte)value.LongValue()); return(1); case SbePrimitiveType.Int16: buffer.Int16PutLittleEndian(0, (short)value.LongValue()); return(2); case SbePrimitiveType.Int32: buffer.Int32PutLittleEndian(0, (int)value.LongValue()); return(4); case SbePrimitiveType.Int64: buffer.Int64PutLittleEndian(0, value.LongValue()); return(8); case SbePrimitiveType.UInt8: buffer.Uint8Put(0, (byte)value.LongValue()); return(1); case SbePrimitiveType.UInt16: buffer.Uint16PutLittleEndian(0, (ushort)value.LongValue()); return(2); case SbePrimitiveType.UInt32: buffer.Uint32PutLittleEndian(0, (uint)value.LongValue()); return(4); case SbePrimitiveType.UInt64: buffer.Uint64PutLittleEndian(0, value.ULongValue()); return(8); case SbePrimitiveType.Float: buffer.FloatPutLittleEndian(0, (float)value.DoubleValue()); return(4); case SbePrimitiveType.Double: buffer.DoublePutLittleEndian(0, value.DoubleValue()); return(8); default: return(0); } }
public static int Put(DirectBuffer buffer, PrimitiveValue value, PrimitiveType type) { if (value == null) { return 0; } switch (type.Type) { case SbePrimitiveType.Char: if (value.Size == 1) { buffer.CharPut(0, (byte)value.LongValue()); return 1; } else { var byteArrayValue = value.ByteArrayValue(); buffer.SetBytes(0, byteArrayValue, 0, byteArrayValue.Length); return byteArrayValue.Length; } case SbePrimitiveType.Int8: buffer.Int8Put(0, (sbyte)value.LongValue()); return 1; case SbePrimitiveType.Int16: buffer.Int16PutLittleEndian(0, (short)value.LongValue()); return 2; case SbePrimitiveType.Int32: buffer.Int32PutLittleEndian(0, (int)value.LongValue()); return 4; case SbePrimitiveType.Int64: buffer.Int64PutLittleEndian(0, value.LongValue()); return 8; case SbePrimitiveType.UInt8: buffer.Uint8Put(0, (byte)value.LongValue()); return 1; case SbePrimitiveType.UInt16: buffer.Uint16PutLittleEndian(0, (ushort)value.LongValue()); return 2; case SbePrimitiveType.UInt32: buffer.Uint32PutLittleEndian(0, (uint) value.LongValue()); return 4; case SbePrimitiveType.UInt64: buffer.Uint64PutLittleEndian(0, value.ULongValue()); return 8; case SbePrimitiveType.Float: buffer.FloatPutLittleEndian(0, (float) value.DoubleValue()); return 4; case SbePrimitiveType.Double: buffer.DoublePutLittleEndian(0, value.DoubleValue()); return 8; default: return 0; } }
private int WriteUpdateValue(IReactiveTable table, TableUpdate tableUpdate, DirectBuffer buffer, int offset) { var column = tableUpdate.Column; if (column.Type == typeof(int)) { buffer.Int32PutLittleEndian(offset, table.GetValue <int>(column.ColumnId, tableUpdate.RowIndex)); return(sizeof(int)); } if (column.Type == typeof(short)) { buffer.Int16PutLittleEndian(offset, table.GetValue <short>(column.ColumnId, tableUpdate.RowIndex)); return(sizeof(short)); } if (column.Type == typeof(string)) { var stringValue = table.GetValue <string>(column.ColumnId, tableUpdate.RowIndex) ?? string.Empty; // Set the length var length = (ushort)stringValue.Length; buffer.Uint16PutLittleEndian(offset, length); var written = sizeof(ushort); offset += written; // And then the value var bytesWritten = Encoding.Default.GetBytes(stringValue, 0, stringValue.Length, _stringBuffer, 0); _buffer.SetBytes(offset, _stringBuffer, 0, bytesWritten); written += bytesWritten; //written += WriteStringToByteArray(stringValue, _byteArray, offset); return(written); } if (column.Type == typeof(bool)) { buffer.CharPut(offset, (byte)(table.GetValue <bool>(column.ColumnId, tableUpdate.RowIndex) ? 1 : 0)); return(sizeof(byte)); } if (column.Type == typeof(double)) { var value = table.GetValue <double>(column.ColumnId, tableUpdate.RowIndex); buffer.DoublePutLittleEndian(offset, value); return(sizeof(double)); } if (column.Type == typeof(long)) { buffer.Int64PutLittleEndian(offset, table.GetValue <long>(column.ColumnId, tableUpdate.RowIndex)); return(sizeof(long)); } if (column.Type == typeof(decimal)) { var decimalVal = table.GetValue <decimal>(column.ColumnId, tableUpdate.RowIndex); _decimalGetBytes(decimalVal, _decimalBuffer); buffer.SetBytes(offset, _decimalBuffer, 0, _decimalBuffer.Length); return(_decimalBuffer.Length); } if (column.Type == typeof(DateTime)) { throw new NotImplementedException(); } if (column.Type == typeof(TimeSpan)) { throw new NotImplementedException(); } if (column.Type == typeof(Guid)) { throw new NotImplementedException(); } if (column.Type == typeof(float)) { buffer.FloatPutLittleEndian(offset, table.GetValue <float>(column.ColumnId, tableUpdate.RowIndex)); return(sizeof(float)); } if (column.Type == typeof(byte)) { buffer.CharPut(offset, table.GetValue <byte>(column.ColumnId, tableUpdate.RowIndex)); return(sizeof(byte)); } if (column.Type == typeof(char)) { buffer.Uint16PutLittleEndian(offset, table.GetValue <char>(column.ColumnId, tableUpdate.RowIndex)); return(sizeof(char)); } return(0); }