Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
Hylo
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Zig
Javascript
GIMPLE
nim source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
nim (trunk)
nim 1.0.4
nim 1.0.6
nim 1.2.0
nim 1.4.2
nim 1.4.4
nim 1.4.6
nim 1.4.8
nim 1.6.0
nim 1.6.16
nim 2.0.0
Options
Source code
import parseutils type Fields* = enum Account = 1 AdvId = 2 AdvRefID = 3 CheckSum = 10 MsgType = 35 BidSpotRate = 188 OfferSpotRate = 190 QuoteSetID = 302 type GroupRange = range[0..980] GroupSet = set[GroupRange] GroupDesc[num: static int, fields: static GroupSet] = object const GrpNoHops* = GroupDesc[627, {628.GroupRange, 629, 630}]() const GrpNoIOIQualifiers* = GroupDesc[199, {104.GroupRange}]() const GrpNoRoutingIDs* = GroupDesc[215, {216.GroupRange, 217}]() const GrpNoContraBrokers* = GroupDesc[382, {375.GroupRange, 337, 437, 438, 655}]() const GrpNoMsgTypes* = GroupDesc[384, {372.GroupRange, 385}]() const GrpNoQuoteSets* = GroupDesc[296, {302.GroupRange, 311, 312, 309, 305, 457, 462, 463, 310, 763, 313, 542, 315, 241, 242, 243, 244, 245, 246, 256, 595, 592, 593, 594, 247, 316, 941, 317, 436, 435, 308, 306, 362, 363, 307, 364, 365, 877, 878, 318, 879, 810, 882, 883, 884, 885, 886, 887, 304, 893, 295, 367}]() const GrpNoQuoteEntries* = GroupDesc[295, {55.GroupRange, 65, 48, 22, 454, 460, 461, 167, 762, 200, 541, 201, 224, 225, 239, 226, 227, 228, 255, 543, 470, 471, 472, 240, 202, 947, 206, 231, 223, 207, 106, 348, 349, 107, 350, 351, 691, 667, 875, 876, 864, 873, 874, 913, 914, 915, 918, 788, 916, 917, 919, 898, 711, 555, 299, 132, 133, 134, 135, 62, 188, 190, 189, 191, 631, 632, 633, 634, 60, 336, 625, 64, 40, 193, 192, 642, 643, 15, 368}]() type StreamFix* = object msg: string pos: int len: int StreamFixRef* = ref StreamFix Group*[grp: static[GroupSet]] = object sf: StreamFixRef len*: int const DELIMITER = '\x01' proc initFix*(msg: string): StreamFixRef = new(result) result.msg = msg result.pos = 0 result.len = result.msg.len proc getAnyTagGrp*[N: static(int), T](fs: StreamFixRef, grp: GroupSet, tag: array[N, int], val: var T): int = while fs.pos < fs.len: let prev = fs.pos while fs.msg[fs.pos] != '=': result = result * 10 + fs.msg[fs.pos].int - '0'.int inc fs.pos inc fs.pos if tag.contains(result): when T is string: let start = fs.pos while fs.msg[fs.pos] != DELIMITER: inc fs.pos val = fs.msg[start..<fs.pos] elif T is char: let start = fs.pos while fs.msg[fs.pos] != DELIMITER: inc fs.pos val = fs.msg[start] elif T is int: while fs.msg[fs.pos] != DELIMITER: val = val * 10 + fs.msg[fs.pos].int - '0'.int inc fs.pos elif T is uint: while fs.msg[fs.pos] != DELIMITER: val = val * 10 + fs.msg[fs.pos].uint - '0'.uint inc fs.pos elif T is float: discard parseFloat(fs.msg, val, fs.pos) else: {.error: "getTag does not support the generic type".} inc fs.pos return elif result in grp: result = 0 while fs.msg[fs.pos] != DELIMITER: inc fs.pos inc fs.pos else: result = 0 fs.pos = prev return proc getAnyTag*[N: static(int), T](fs: StreamFixRef, tag: array[N, int], val: var T): int = var pos = fs.pos while pos < fs.len: while fs.msg[pos] != '=': result = result * 10 + fs.msg[pos].int - '0'.int inc pos inc pos if result in tag: fs.pos = pos when T is string: while fs.msg[fs.pos] != DELIMITER: inc fs.pos val = fs.msg[pos..<fs.pos] elif T is char: while fs.msg[fs.pos] != DELIMITER: inc fs.pos val = fs.msg[pos] elif T is int: while fs.msg[fs.pos] != DELIMITER: val = val * 10 + fs.msg[fs.pos].int - '0'.int inc fs.pos elif T is uint: while fs.msg[fs.pos] != DELIMITER: val = val * 10 + fs.msg[fs.pos].uint - '0'.uint inc fs.pos elif T is float: fs.pos += parseFloat(fs.msg, val, fs.pos) else: {.error: "getTag does not support the generic type".} inc fs.pos return else: result = 0 while fs.msg[pos] != DELIMITER: inc pos inc pos proc getGroup*[N, F](fs: StreamFixRef, gd: static GroupDesc[N, F]): Group[F] = discard getAnyTag[1, int](fs, [gd.num], result.len) result.sf = fs return proc getAnyTagG*[N: static(int), T](g: Group, tag: array[N, int], val: var T): int = getAnyTagGrp[N, T](g.sf, g.grp, tag, val) template mkTag(name: untyped, t: untyped) = proc `tag name`*(fs: StreamFixRef, tag: int, val: var t): bool = 0 < getAnyTag[1, t](fs, [tag], val) proc `tagAny name`*[N: static int](fs: StreamFixRef, tag: array[N, int], val: var t): int = getAnyTag[N, t](fs, tag, val) proc `get name`*(fs: StreamFixRef, tag: int): t = discard getAnyTag[1, t](fs, [tag], result) mkTag(Str, string) mkTag(Char, char) mkTag(Int, int) mkTag(UInt, uint) mkTag(Float, float) proc main() = var f = initFix("") doAssert 'i' == f.getChar(MsgType.int) var v: string let gr1 = f.getGroup(GrpNoQuoteSets) doAssert 5 == gr1.len while true: let t = gr1.getAnyTagG([QuoteSetID.int], v) if 0 == t: break echo t, ": ", v let gr2 = f.getGroup(GrpNoQuoteEntries) while true: let t = gr2.getAnyTagG([BidSpotRate.int, OfferSpotRate.int], v) if 0 == t: break echo t, ": ", v let t = f.tagAnyStr([CheckSum.int], v) echo t, ": ", v main()
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree