2 using System.Runtime.CompilerServices;
4 namespace kinetica.Records;
37 private readonly
long _intValue;
38 private readonly
double _floatValue;
39 private readonly
object? _objectValue;
45 _floatValue = floatValue;
46 _objectValue = objectValue;
55 #region Factory Methods 83 #region Implicit Conversions 85 public static implicit
operator RecordValue(
int value) =>
Int(value);
90 public static implicit
operator RecordValue(
byte[] value) => value ==
null ?
Null() :
Bytes(value);
94 public static implicit
operator RecordValue(
int? value) => value.HasValue ?
Int(value.Value) :
Null();
95 public static implicit
operator RecordValue(
long? value) => value.HasValue ?
Long(value.Value) :
Null();
96 public static implicit
operator RecordValue(
float? value) => value.HasValue ?
Float(value.Value) :
Null();
97 public static implicit
operator RecordValue(
double? value) => value.HasValue ?
Double(value.Value) :
Null();
98 public static implicit
operator RecordValue(
bool? value) => value.HasValue ?
Boolean(value.Value) :
Null();
102 #region Value Accessors 105 [MethodImpl(MethodImplOptions.AggressiveInlining)]
112 _ =>
throw new InvalidOperationException($
"Cannot convert {_type} to Int")
117 [MethodImpl(MethodImplOptions.AggressiveInlining)]
125 _ =>
throw new InvalidOperationException($
"Cannot convert {_type} to Long")
130 [MethodImpl(MethodImplOptions.AggressiveInlining)]
137 _ =>
throw new InvalidOperationException($
"Cannot convert {_type} to Float")
142 [MethodImpl(MethodImplOptions.AggressiveInlining)]
150 _ =>
throw new InvalidOperationException($
"Cannot convert {_type} to Double")
155 [MethodImpl(MethodImplOptions.AggressiveInlining)]
162 _ =>
throw new InvalidOperationException($
"Cannot convert {_type} to String")
167 [MethodImpl(MethodImplOptions.AggressiveInlining)]
174 _ =>
throw new InvalidOperationException($
"Cannot convert {_type} to Bytes")
179 [MethodImpl(MethodImplOptions.AggressiveInlining)]
186 _ =>
throw new InvalidOperationException($
"Cannot convert {_type} to Boolean")
192 #region TryGet Methods 199 value = (int)_intValue;
223 value = (float)_floatValue;
247 value = (
string?)_objectValue;
264 value = (
byte[]?)_objectValue;
281 value = _intValue != 0;
290 #region Equality and Hashing 294 if (_type != other._type)
return false;
301 RecordValueType.String =>
string.Equals((
string?)_objectValue, (
string?)other._objectValue, StringComparison.Ordinal),
302 RecordValueType.Bytes => ByteArrayEquals((
byte[]?)_objectValue, (
byte[]?)other._objectValue),
307 private static bool ByteArrayEquals(
byte[]? a,
byte[]? b)
309 if (ReferenceEquals(a, b))
return true;
310 if (a ==
null || b ==
null)
return false;
311 if (a.Length != b.Length)
return false;
312 for (
int i = 0; i < a.Length; i++)
314 if (a[i] != b[i])
return false;
329 RecordValueType.Bytes => HashCode.Combine(_type, ((
byte[]?)_objectValue)?.Length ?? 0),
347 RecordValueType.Bytes => $
"bytes[{((byte[]?)_objectValue)?.Length ?? 0}]",
string? AsString()
Gets the value as a string.
static RecordValue Null()
Creates a null record value.
static RecordValue Long(long value)
Creates a 64-bit integer record value.
bool TryGetFloat(out float value)
Tries to get the value as a float.
long? AsLong()
Gets the value as a 64-bit integer.
bool TryGetInt(out int value)
Tries to get the value as an integer.
static RecordValue Boolean(bool value)
Creates a boolean record value (stored as int).
bool IsNull
Returns true if this value is null.
override string ToString()
byte? [] AsBytes()
Gets the value as a byte array.
bool? AsBool()
Gets the value as a boolean (from int).
int? AsInt()
Gets the value as a 32-bit integer.
override int GetHashCode()
bool TryGetBool(out bool value)
Tries to get the value as a boolean.
static RecordValue Float(float value)
Creates a 32-bit float record value.
bool TryGetBytes(out byte[]? value)
Tries to get the value as bytes.
static RecordValue String(string value)
Creates a string record value.
static bool operator !=(RecordValue left, RecordValue right)
static RecordValue Bytes(byte[] value)
Creates a bytes record value.
double? AsDouble()
Gets the value as a 64-bit double.
Immutable collection of metadata about a Kinetica type.
static RecordValue Int(int value)
Creates a 32-bit integer record value.
bool TryGetString(out string? value)
Tries to get the value as a string.
RecordValueType
Represents the type of a record value.
32-bit signed integer (also used for boolean, int8, int16)
bool TryGetDouble(out double value)
Tries to get the value as a double.
float? AsFloat()
Gets the value as a 32-bit float.
static RecordValue Double(double value)
Creates a 64-bit double record value.
A typed value that can be stored in a GenericRecord.
bool TryGetLong(out long value)
Tries to get the value as a long.
bool Equals(RecordValue other)
static bool operator==(RecordValue left, RecordValue right)