Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UInt64 seqnums to support Continous Markets #773

Merged
merged 5 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions QuickFIXn/Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ public long GetLong(string key)
}
}

public ulong GetULong(string key)
{
try
{
return Convert.ToUInt64(GetString(key));
}
catch(FormatException)
{
throw new ConfigError("Incorrect data type");
}
catch(QuickFIXException)
{
throw new ConfigError("No value for key: " + key);
}
}

public double GetDouble(string key)
{
try
Expand Down
29 changes: 29 additions & 0 deletions QuickFIXn/Fields/Converters/AsciiConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

namespace QuickFix.Fields.Converters
{
/// <summary>
/// convert Int64 to/from string
/// </summary>
public static class AsciiValidator
{
public const int ASCII_ZERO = 48;
public const int ASCII_NINE = 57;
public const int ASCII_MINUS = 45;

/// <summary>
/// TODO can we use NumberFormatInfo or NumberStyles to avoid this bit of ASCII hackery?
/// Validates that a string looks like number (for use before conversion to an int, ulong, etc.).
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static void Validate(string i)
{
if ((null == i) || (i.Length < 1))
throw new FieldConvertError("The argument string cannot be null or empty");
int asciiValOfFirstChar = System.Convert.ToInt32(i[0]);
if ((asciiValOfFirstChar < ASCII_ZERO) || (asciiValOfFirstChar > ASCII_NINE))
if (asciiValOfFirstChar != ASCII_MINUS)
throw new FieldConvertError("Could not convert string to int (" + i + "): The first character must be a digit or a minus sign");
}
}
}
4 changes: 2 additions & 2 deletions QuickFIXn/Fields/Converters/DecimalConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static Decimal Convert(string d)
if((null == d) || (d.Length < 1))
throw new FieldConvertError("The argument string cannot be null or empty");
int asciiValOfFirstChar = System.Convert.ToInt32(d[0]);
if ((asciiValOfFirstChar < IntConverter.ASCII_ZERO) || (asciiValOfFirstChar > IntConverter.ASCII_NINE))
if (asciiValOfFirstChar != IntConverter.ASCII_MINUS && asciiValOfFirstChar != ASCII_DECIMALPOINT)
if ((asciiValOfFirstChar < AsciiValidator.ASCII_ZERO) || (asciiValOfFirstChar > AsciiValidator.ASCII_NINE))
if (asciiValOfFirstChar != AsciiValidator.ASCII_MINUS && asciiValOfFirstChar != ASCII_DECIMALPOINT)
throw new FieldConvertError("Could not convert string to decimal (" + d + "): The first character must be a digit, decimal point, or minus sign");
return decimal.Parse(d, System.Globalization.NumberStyles.AllowExponent | System.Globalization.NumberStyles.AllowLeadingSign | System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture);
}
Expand Down
14 changes: 2 additions & 12 deletions QuickFIXn/Fields/Converters/IntConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ namespace QuickFix.Fields.Converters
/// </summary>
public static class IntConverter
{
public const int ASCII_ZERO = 48;
public const int ASCII_NINE = 57;
public const int ASCII_MINUS = 45;

/// <summary>
/// TODO can we use NumberFormatInfo or NumberStyles to avoid this bit of ASCII hackery?
/// Converts string to int.
/// </summary>
/// <param name="i"></param>
Expand All @@ -20,12 +15,7 @@ public static int Convert(string i)
{
try
{
if ((null == i) || (i.Length < 1))
throw new FieldConvertError("The argument string cannot be null or empty");
int asciiValOfFirstChar = System.Convert.ToInt32(i[0]);
if ((asciiValOfFirstChar < ASCII_ZERO) || (asciiValOfFirstChar > ASCII_NINE))
if (asciiValOfFirstChar != ASCII_MINUS)
throw new FieldConvertError("Could not convert string to int (" + i + "): The first character must be a digit or a minus sign");
AsciiValidator.Validate(i);
return System.Convert.ToInt32(i);
}
catch (System.FormatException e)
Expand All @@ -34,7 +24,7 @@ public static int Convert(string i)
}
catch (System.OverflowException e)
{
throw new FieldConvertError("Could not convert string to int(" + i + ")", e);
throw new FieldConvertError("Could not convert string to int (" + i + ")", e);
}
}

Expand Down
39 changes: 39 additions & 0 deletions QuickFIXn/Fields/Converters/ULongConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

namespace QuickFix.Fields.Converters
{
/// <summary>
/// convert UInt64 to/from string
/// </summary>
public static class ULongConverter
{
/// <summary>
/// Converts string to ulong.
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static ulong Convert(string i)
{
try
{
AsciiValidator.Validate(i);
return System.Convert.ToUInt64(i);
}
catch (System.FormatException e)
{
throw new FieldConvertError("Could not convert string to ulong (" + i + ")", e);
}
catch (System.OverflowException e)
{
throw new FieldConvertError("Could not convert string to ulong (" + i + ")", e);
}
}

/// <summary>
/// convert ulong to string
/// </summary>
public static string Convert(System.UInt64 i)
{
return i.ToString();
}
}
}
Loading