public async Task <decimal> ReadDecimal(int type, int scale, AsyncWrappingCommonArgs async) { switch (type & ~1) { case IscCodes.SQL_SHORT: return(TypeDecoder.DecodeDecimal(await ReadInt16(async).ConfigureAwait(false), scale, type)); case IscCodes.SQL_LONG: return(TypeDecoder.DecodeDecimal(await ReadInt32(async).ConfigureAwait(false), scale, type)); case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: return(TypeDecoder.DecodeDecimal(await ReadInt64(async).ConfigureAwait(false), scale, type)); case IscCodes.SQL_DOUBLE: case IscCodes.SQL_D_FLOAT: return(TypeDecoder.DecodeDecimal(await ReadDouble(async).ConfigureAwait(false), scale, type)); case IscCodes.SQL_INT128: return(TypeDecoder.DecodeDecimal(await ReadInt128(async).ConfigureAwait(false), scale, type)); default: throw new ArgumentOutOfRangeException(nameof(type), $"{nameof(type)}={type}"); } }
public decimal ReadDecimal(int type, int scale) { var value = 0m; switch (type & ~1) { case IscCodes.SQL_SHORT: value = TypeDecoder.DecodeDecimal(ReadInt16(), scale, type); break; case IscCodes.SQL_LONG: value = TypeDecoder.DecodeDecimal(ReadInt32(), scale, type); break; case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: value = TypeDecoder.DecodeDecimal(ReadInt64(), scale, type); break; case IscCodes.SQL_DOUBLE: case IscCodes.SQL_D_FLOAT: value = Convert.ToDecimal(ReadDouble()); break; } return(value); }
public decimal ReadDecimal(int type, int scale) { switch (type & ~1) { case IscCodes.SQL_SHORT: return(TypeDecoder.DecodeDecimal(ReadInt16(), scale, type)); case IscCodes.SQL_LONG: return(TypeDecoder.DecodeDecimal(ReadInt32(), scale, type)); case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: return(TypeDecoder.DecodeDecimal(ReadInt64(), scale, type)); case IscCodes.SQL_DOUBLE: case IscCodes.SQL_D_FLOAT: return(TypeDecoder.DecodeDecimal(ReadDouble(), scale, type)); case IscCodes.SQL_INT128: return(TypeDecoder.DecodeDecimal(ReadInt128(), scale, type)); default: throw new ArgumentOutOfRangeException(nameof(type), $"{nameof(type)}={type}"); } }
public async ValueTask <decimal> ReadDecimalAsync(int type, int scale, CancellationToken cancellationToken = default) { switch (type & ~1) { case IscCodes.SQL_SHORT: return(TypeDecoder.DecodeDecimal(await ReadInt16Async(cancellationToken).ConfigureAwait(false), scale, type)); case IscCodes.SQL_LONG: return(TypeDecoder.DecodeDecimal(await ReadInt32Async(cancellationToken).ConfigureAwait(false), scale, type)); case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: return(TypeDecoder.DecodeDecimal(await ReadInt64Async(cancellationToken).ConfigureAwait(false), scale, type)); case IscCodes.SQL_DOUBLE: case IscCodes.SQL_D_FLOAT: return(TypeDecoder.DecodeDecimal(await ReadDoubleAsync(cancellationToken).ConfigureAwait(false), scale, type)); case IscCodes.SQL_INT128: return(TypeDecoder.DecodeDecimal(await ReadInt128Async(cancellationToken).ConfigureAwait(false), scale, type)); default: throw new ArgumentOutOfRangeException(nameof(type), $"{nameof(type)}={type}"); } }
public Guid GetGuid() { return(_value switch { Guid guid => guid, byte[] bytes => TypeDecoder.DecodeGuid(bytes), _ => throw new InvalidOperationException($"Incorrect {nameof(Guid)} value."), });
public void Init(ulong programCounter) { // Set the instruction decoder and type decoder instructionDecoder = new InstructionDecoder(EndianType.Little); typeDecoder = new TypeDecoder(); rvcDecoder = new RvcDecoder(architecture); InitDetails(programCounter); environment.ApplyOutputParameter(configuration.Debug, configuration.VerboseMode); isInitialized = true; }
protected override Array DecodeSlice(byte[] slice) { Array sliceData = null; var slicePosition = 0; var type = 0; var dbType = DbDataType.Array; var systemType = GetSystemType(); var charset = _db.Charset; var lengths = new int[Descriptor.Dimensions]; var lowerBounds = new int[Descriptor.Dimensions]; for (var i = 0; i < Descriptor.Dimensions; i++) { lowerBounds[i] = Descriptor.Bounds[i].LowerBound; lengths[i] = Descriptor.Bounds[i].UpperBound; if (lowerBounds[i] == 0) { lengths[i]++; } } sliceData = Array.CreateInstance(systemType, lengths, lowerBounds); var tempData = Array.CreateInstance(systemType, sliceData.Length); type = TypeHelper.GetSqlTypeFromBlrType(Descriptor.DataType); dbType = TypeHelper.GetDbDataTypeFromBlrType(Descriptor.DataType, 0, Descriptor.Scale); int itemLength = Descriptor.Length; for (var i = 0; i < tempData.Length; i++) { if (slicePosition >= slice.Length) { break; } switch (dbType) { case DbDataType.Char: tempData.SetValue(charset.GetString(slice, slicePosition, itemLength), i); break; case DbDataType.VarChar: { var index = slicePosition; var count = 0; while (slice[index++] != 0) { count++; } tempData.SetValue(charset.GetString(slice, slicePosition, count), i); slicePosition += 2; } break; case DbDataType.SmallInt: tempData.SetValue(BitConverter.ToInt16(slice, slicePosition), i); break; case DbDataType.Integer: tempData.SetValue(BitConverter.ToInt32(slice, slicePosition), i); break; case DbDataType.BigInt: tempData.SetValue(BitConverter.ToInt64(slice, slicePosition), i); break; case DbDataType.Decimal: case DbDataType.Numeric: { object evalue = null; switch (type) { case IscCodes.SQL_SHORT: evalue = BitConverter.ToInt16(slice, slicePosition); break; case IscCodes.SQL_LONG: evalue = BitConverter.ToInt32(slice, slicePosition); break; case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: evalue = BitConverter.ToInt64(slice, slicePosition); break; } var dvalue = TypeDecoder.DecodeDecimal(evalue, Descriptor.Scale, type); tempData.SetValue(dvalue, i); } break; case DbDataType.Double: tempData.SetValue(BitConverter.ToDouble(slice, slicePosition), i); break; case DbDataType.Float: tempData.SetValue(BitConverter.ToSingle(slice, slicePosition), i); break; case DbDataType.Date: { var idate = BitConverter.ToInt32(slice, slicePosition); var date = TypeDecoder.DecodeDate(idate); tempData.SetValue(date, i); } break; case DbDataType.Time: { var itime = BitConverter.ToInt32(slice, slicePosition); var time = TypeDecoder.DecodeTime(itime); tempData.SetValue(time, i); } break; case DbDataType.TimeStamp: { var idate = BitConverter.ToInt32(slice, slicePosition); var itime = BitConverter.ToInt32(slice, slicePosition + 4); var date = TypeDecoder.DecodeDate(idate); var time = TypeDecoder.DecodeTime(itime); var timestamp = date.Add(time); tempData.SetValue(timestamp, i); } break; } slicePosition += itemLength; } if (systemType.GetTypeInfo().IsPrimitive) { // For primitive types we can use System.Buffer to copy generated data to destination array Buffer.BlockCopy(tempData, 0, sliceData, 0, Buffer.ByteLength(tempData)); } else { sliceData = tempData; } return(sliceData); }
public async ValueTask <TimeSpan> ReadTimeAsync(CancellationToken cancellationToken = default) { return(TypeDecoder.DecodeTime(await ReadInt32Async(cancellationToken).ConfigureAwait(false))); }
public async Task <TimeSpan> ReadTime(AsyncWrappingCommonArgs async) { return(TypeDecoder.DecodeTime(await ReadInt32(async).ConfigureAwait(false))); }
public DateTime ReadDate() { return(TypeDecoder.DecodeDate(ReadInt32())); }
public TimeSpan ReadTime() { return(TypeDecoder.DecodeTime(ReadInt32())); }
public async Task <bool> ReadBoolean(AsyncWrappingCommonArgs async) { return(TypeDecoder.DecodeBoolean(await ReadOpaque(1, async).ConfigureAwait(false))); }
public async ValueTask <Guid> ReadGuidAsync(CancellationToken cancellationToken = default) { return(TypeDecoder.DecodeGuid(await ReadOpaqueAsync(16, cancellationToken).ConfigureAwait(false))); }
public async ValueTask <FbDecFloat> ReadDec34Async(CancellationToken cancellationToken = default) { return(TypeDecoder.DecodeDec34(await ReadOpaqueAsync(16, cancellationToken).ConfigureAwait(false))); }
public async ValueTask <BigInteger> ReadInt128Async(CancellationToken cancellationToken = default) { return(TypeDecoder.DecodeInt128(await ReadOpaqueAsync(16, cancellationToken).ConfigureAwait(false))); }
public bool ReadBoolean() { return(TypeDecoder.DecodeBoolean(ReadOpaque(1))); }
public FbDecFloat ReadDec16() { return(TypeDecoder.DecodeDec16(ReadOpaque(8))); }
public async Task <FbDecFloat> ReadDec34(AsyncWrappingCommonArgs async) { return(TypeDecoder.DecodeDec34(await ReadOpaque(16, async).ConfigureAwait(false))); }
public bool ReadBoolean() { return(TypeDecoder.DecodeBoolean(InternalReadBuffer(1, opaque: true))); }
public TimeSpan ReadTime() => TypeDecoder.DecodeTime(ReadInt32());
public DateTime ReadDate() => TypeDecoder.DecodeDate(ReadInt32());
public async Task <BigInteger> ReadInt128(AsyncWrappingCommonArgs async) { return(TypeDecoder.DecodeInt128(await ReadOpaque(16, async).ConfigureAwait(false))); }
public async ValueTask <bool> ReadBooleanAsync(CancellationToken cancellationToken = default) { return(TypeDecoder.DecodeBoolean(await ReadOpaqueAsync(1, cancellationToken).ConfigureAwait(false))); }
public int ReadInt32() { ReadBytes(_smallBuffer, 4); return(TypeDecoder.DecodeInt32(_smallBuffer)); }
public FbDecFloat ReadDec34() { return(TypeDecoder.DecodeDec34(ReadOpaque(16))); }
public long ReadInt64() { ReadBytes(_smallBuffer, 8); return(TypeDecoder.DecodeInt64(_smallBuffer)); }
public BigInteger ReadInt128() { return(TypeDecoder.DecodeInt128(ReadOpaque(16))); }
public async ValueTask <long> ReadInt64Async(CancellationToken cancellationToken = default) { await ReadBytesAsync(_smallBuffer, 8, cancellationToken).ConfigureAwait(false); return(TypeDecoder.DecodeInt64(_smallBuffer)); }
protected override System.Array DecodeSlice(byte[] slice) { Array sliceData = null; int slicePosition = 0; int type = 0; DbDataType dbType = DbDataType.Array; Type systemType = this.GetSystemType(); Charset charset = this.db.Charset; int[] lengths = new int[this.Descriptor.Dimensions]; int[] lowerBounds = new int[this.Descriptor.Dimensions]; // Get upper and lower bounds of each dimension for (int i = 0; i < this.Descriptor.Dimensions; i++) { lowerBounds[i] = this.Descriptor.Bounds[i].LowerBound; lengths[i] = this.Descriptor.Bounds[i].UpperBound; if (lowerBounds[i] == 0) { lengths[i]++; } } // Create slice arrays sliceData = Array.CreateInstance(systemType, lengths, lowerBounds); Array tempData = Array.CreateInstance(systemType, sliceData.Length); // Infer data types type = TypeHelper.GetFbType(this.Descriptor.DataType); dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, 0, this.Descriptor.Scale); int itemLength = this.Descriptor.Length; for (int i = 0; i < tempData.Length; i++) { if (slicePosition >= slice.Length) { break; } switch (dbType) { case DbDataType.Char: tempData.SetValue(charset.GetString(slice, slicePosition, itemLength), i); break; case DbDataType.VarChar: { int index = slicePosition; int count = 0; while (slice[index++] != 0) { count++; } tempData.SetValue(charset.GetString(slice, slicePosition, count), i); slicePosition += 2; } break; case DbDataType.SmallInt: tempData.SetValue(BitConverter.ToInt16(slice, slicePosition), i); break; case DbDataType.Integer: tempData.SetValue(BitConverter.ToInt32(slice, slicePosition), i); break; case DbDataType.BigInt: tempData.SetValue(BitConverter.ToInt64(slice, slicePosition), i); break; case DbDataType.Decimal: case DbDataType.Numeric: { object evalue = null; switch (type) { case IscCodes.SQL_SHORT: evalue = BitConverter.ToInt16(slice, slicePosition); break; case IscCodes.SQL_LONG: evalue = BitConverter.ToInt32(slice, slicePosition); break; case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: evalue = BitConverter.ToInt64(slice, slicePosition); break; } decimal dvalue = TypeDecoder.DecodeDecimal(evalue, this.Descriptor.Scale, type); tempData.SetValue(dvalue, i); } break; case DbDataType.Double: tempData.SetValue(BitConverter.ToDouble(slice, slicePosition), i); break; case DbDataType.Float: tempData.SetValue(BitConverter.ToSingle(slice, slicePosition), i); break; case DbDataType.Date: { int idate = BitConverter.ToInt32(slice, slicePosition); DateTime date = TypeDecoder.DecodeDate(idate); tempData.SetValue(date, i); } break; case DbDataType.Time: { int itime = BitConverter.ToInt32(slice, slicePosition); TimeSpan time = TypeDecoder.DecodeTime(itime); tempData.SetValue(time, i); } break; case DbDataType.TimeStamp: { int idate = BitConverter.ToInt32(slice, slicePosition); int itime = BitConverter.ToInt32(slice, slicePosition + 4); DateTime date = TypeDecoder.DecodeDate(idate); TimeSpan time = TypeDecoder.DecodeTime(itime); DateTime timestamp = new System.DateTime( date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds); tempData.SetValue(timestamp, i); } break; } slicePosition += itemLength; } if (systemType.IsPrimitive) { // For primitive types we can use System.Buffer to copy generated data to destination array Buffer.BlockCopy(tempData, 0, sliceData, 0, Buffer.ByteLength(tempData)); } else { sliceData = tempData; } return(sliceData); }
public Guid ReadGuid() { return(TypeDecoder.DecodeGuid(ReadOpaque(16))); }