From add0b3311085b737e45110a09bb69bbfe3059dee Mon Sep 17 00:00:00 2001 From: AKosylo Date: Fri, 13 Oct 2023 15:17:50 +0200 Subject: [PATCH] change format for hex values in toString --- .../Events/Market/Candles/Candle.swift | 3 +- .../Events/Market/Extra/OrderBase.swift | 4 +-- DXFeedFramework/Events/Market/Greeks.swift | 3 +- .../Events/Market/OptionSale.swift | 4 +-- DXFeedFramework/Events/Market/Series.swift | 4 +-- DXFeedFramework/Events/Market/TheoPrice.swift | 3 +- .../Events/Market/TimeAndSale.swift | 3 +- .../Events/Market/Underlying.swift | 3 +- DXFeedFramework/Utils/BinaryInteger+Ext.swift | 36 ++++++++++--------- DXFeedFramework/Utils/StringUtil.swift | 3 +- Samples/PerfTestCL/ConnectCommand.swift | 1 - 11 files changed, 38 insertions(+), 29 deletions(-) diff --git a/DXFeedFramework/Events/Market/Candles/Candle.swift b/DXFeedFramework/Events/Market/Candles/Candle.swift index 3fb265832..04163bf34 100644 --- a/DXFeedFramework/Events/Market/Candles/Candle.swift +++ b/DXFeedFramework/Events/Market/Candles/Candle.swift @@ -137,7 +137,8 @@ extension Candle { return """ \(eventSymbol), \ eventTime=" + \(TimeUtil.toLocalDateString(millis: eventTime)), \ -eventFlags=0x\(String(format: "%02X", eventFlags)), \ +eventFlags=\(eventFlags.toHexString()), \ +index=\(index.toHexString()), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ sequence=\(getSequence()), \ count=\(count), \ diff --git a/DXFeedFramework/Events/Market/Extra/OrderBase.swift b/DXFeedFramework/Events/Market/Extra/OrderBase.swift index e048acb1f..aedb62812 100644 --- a/DXFeedFramework/Events/Market/Extra/OrderBase.swift +++ b/DXFeedFramework/Events/Market/Extra/OrderBase.swift @@ -290,8 +290,8 @@ extension OrderBase { \(eventSymbol), \ eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \ source=\(eventSource.name), \ -eventFlags=0x\(String(format: "%02X", eventFlags)), \ -index=0x\(String(format: "%02X", index)), \ +eventFlags=\(eventFlags.toHexString()), \ +index=\(index.toHexString()), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ sequence=\(getSequence()), \ timeNanoPart=\(timeNanoPart), \ diff --git a/DXFeedFramework/Events/Market/Greeks.swift b/DXFeedFramework/Events/Market/Greeks.swift index 7a1a17232..05b32130b 100644 --- a/DXFeedFramework/Events/Market/Greeks.swift +++ b/DXFeedFramework/Events/Market/Greeks.swift @@ -120,7 +120,8 @@ extension Greeks { return """ Greeks{\(eventSymbol), \ eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \ -eventFlags=0x\(String(format: "%02X", eventFlags)), \ +eventFlags=\(eventFlags.toHexString()), \ +index=\(index.toHexString()), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ sequence=\(self.getSequence()), \ price=\(price), \ diff --git a/DXFeedFramework/Events/Market/OptionSale.swift b/DXFeedFramework/Events/Market/OptionSale.swift index 0a04c6c3a..a1a7d10eb 100644 --- a/DXFeedFramework/Events/Market/OptionSale.swift +++ b/DXFeedFramework/Events/Market/OptionSale.swift @@ -239,8 +239,8 @@ extension OptionSale { return """ OptionSale{\(eventSymbol), \ eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \ -eventFlags=0x\(String(format: "%02X", eventFlags)), \ -index=0x\(String(format: "%02X", index)), \ +eventFlags=\(eventFlags.toHexString()), \ +index=\(index.toHexString()), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ timeNanoPart=\(timeNanoPart), \ sequence=\(getSequence()), \ diff --git a/DXFeedFramework/Events/Market/Series.swift b/DXFeedFramework/Events/Market/Series.swift index d328e35ef..25e09f4d8 100644 --- a/DXFeedFramework/Events/Market/Series.swift +++ b/DXFeedFramework/Events/Market/Series.swift @@ -110,8 +110,8 @@ extension Series { """ Series{\(eventSymbol), \ eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \ -eventFlags=0x\(String(format: "%02X", eventFlags)), \ -index=0x\(String(format: "%02X", index)), \ +eventFlags=\(eventFlags.toHexString()), \ +index=\(index.toHexString()), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ sequence=\(self.getSequence()), \ expiration=\(DayUtil.getYearMonthDayByDayId(Int(expiration))), \ diff --git a/DXFeedFramework/Events/Market/TheoPrice.swift b/DXFeedFramework/Events/Market/TheoPrice.swift index f13d0dea8..bbf8b6d0e 100644 --- a/DXFeedFramework/Events/Market/TheoPrice.swift +++ b/DXFeedFramework/Events/Market/TheoPrice.swift @@ -111,7 +111,8 @@ extension TheoPrice { return """ TheoPrice{\(eventSymbol) \ eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \ -eventFlags=0x\(String(format: "%02X", eventFlags)), \ +eventFlags=\(eventFlags.toHexString()), \ +index=\(index.toHexString()), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ sequence=\(self.getSequence()), \ price=\(price) \ diff --git a/DXFeedFramework/Events/Market/TimeAndSale.swift b/DXFeedFramework/Events/Market/TimeAndSale.swift index 8c7d13f3d..a4c44d650 100644 --- a/DXFeedFramework/Events/Market/TimeAndSale.swift +++ b/DXFeedFramework/Events/Market/TimeAndSale.swift @@ -256,7 +256,8 @@ extension TimeAndSale { return """ TimeAndSale{\(eventSymbol), \ eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \ -eventFlags=0x\(String(format: "%02X", eventFlags)), \ +eventFlags=\(eventFlags.toHexString()), \ +index=\(index.toHexString()), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ timeNanoPart=\(timeNanoPart), \ sequence=\(getSequence()), \ diff --git a/DXFeedFramework/Events/Market/Underlying.swift b/DXFeedFramework/Events/Market/Underlying.swift index fffa659ae..0bf49b7b5 100644 --- a/DXFeedFramework/Events/Market/Underlying.swift +++ b/DXFeedFramework/Events/Market/Underlying.swift @@ -112,7 +112,8 @@ extension Underlying { return """ Underlying{"\(eventSymbol) \ eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \ -eventFlags=0x\(String(format: "%02X", eventFlags)), \ +eventFlags=\(eventFlags.toHexString()), \ +index=\(index.toHexString()), \ time=\(TimeUtil.toLocalDateString(millis: time)), \ sequence=\(self.getSequence()), \ volatility=\(volatility), \ diff --git a/DXFeedFramework/Utils/BinaryInteger+Ext.swift b/DXFeedFramework/Utils/BinaryInteger+Ext.swift index 863897d80..fa1519b89 100644 --- a/DXFeedFramework/Utils/BinaryInteger+Ext.swift +++ b/DXFeedFramework/Utils/BinaryInteger+Ext.swift @@ -8,23 +8,27 @@ import Foundation extension BinaryInteger { - func roundedTowardZero(toMultipleOf multiplier: Self) -> Self { - return self - (self % multiplier) - } + func roundedTowardZero(toMultipleOf multiplier: Self) -> Self { + return self - (self % multiplier) + } - func roundedAwayFromZero(toMultipleOf multiplier: Self) -> Self { - let xValue = self.roundedTowardZero(toMultipleOf: multiplier) - if xValue == self { return xValue } - return (multiplier.signum() == self.signum()) ? (xValue + multiplier) : (xValue - multiplier) - } + func roundedAwayFromZero(toMultipleOf multiplier: Self) -> Self { + let xValue = self.roundedTowardZero(toMultipleOf: multiplier) + if xValue == self { return xValue } + return (multiplier.signum() == self.signum()) ? (xValue + multiplier) : (xValue - multiplier) + } - func roundedDown(toMultipleOf multiplier: Self) -> Self { - return (self < 0) ? self.roundedAwayFromZero(toMultipleOf: multiplier) - : self.roundedTowardZero(toMultipleOf: multiplier) - } + func roundedDown(toMultipleOf multiplier: Self) -> Self { + return (self < 0) ? self.roundedAwayFromZero(toMultipleOf: multiplier) + : self.roundedTowardZero(toMultipleOf: multiplier) + } - func roundedUp(toMultipleOf multiplier: Self) -> Self { - return (self > 0) ? self.roundedAwayFromZero(toMultipleOf: multiplier) - : self.roundedTowardZero(toMultipleOf: multiplier) - } + func roundedUp(toMultipleOf multiplier: Self) -> Self { + return (self > 0) ? self.roundedAwayFromZero(toMultipleOf: multiplier) + : self.roundedTowardZero(toMultipleOf: multiplier) + } + + func toHexString() -> String { + return "0x\(String(format: "%01X", Int(self)))" + } } diff --git a/DXFeedFramework/Utils/StringUtil.swift b/DXFeedFramework/Utils/StringUtil.swift index e8826cf08..b3c0b1b74 100644 --- a/DXFeedFramework/Utils/StringUtil.swift +++ b/DXFeedFramework/Utils/StringUtil.swift @@ -13,7 +13,8 @@ class StringUtil { return String(UnicodeScalar(UInt8(char))) } let value = (String(format: "%02X", Int(char) + 65536).substring(fromIndex: 1)) - return char == 0 ? "\0" : "\\u" + value + let res = char == 0 ? "\\0" : "\\u" + value + return res } static func checkChar(char: Character, mask: Int, name: String) throws { diff --git a/Samples/PerfTestCL/ConnectCommand.swift b/Samples/PerfTestCL/ConnectCommand.swift index e3f96f7d9..92f36cf6b 100644 --- a/Samples/PerfTestCL/ConnectCommand.swift +++ b/Samples/PerfTestCL/ConnectCommand.swift @@ -45,7 +45,6 @@ Where: func execute() { var arguments: [String]! - do { arguments = try ArgumentParser().parse(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 4) } catch {