question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing long message

See original GitHub issue

If I attempt to parse a long message (this one in particular contains large amounts of Base64 encoded data in the form of GIF/PNG/PDF/JPG/TIF, nothing breaks but the parsing is incomplete.

I’ve tried “cheating” a bit and breaking up the message to circumvent any internal length restriction that’s happening during parsing like so:

    public bool ParseAllMessage(HL7.Dotnetcore.Message message)
    {
        try
        {
            var hl7 = message.HL7Message;
            var segments = hl7.Split('\r').ToList();

            List<string> hl7SubBlocks = new List<string>();
            int counter = 0;
            string currentBlock = "";
            string msh = "";
            List<string> waitingSegments = new List<string>() { "MSH", "MSA", "QAK", "ERQ", "PID", "PV1", "ORC", "OBR", "ZBR", "BLG", "OBX", "ZBX", "NTE", "ZNT" };
            foreach (var segment in segments)
            {
                if (segment.Substring(0, 3) == "MSH") msh = segment;
                if (waitingSegments.Contains(segment.Substring(0, 3))) waitingSegments.Remove(segment.Substring(0, 3));
                currentBlock += segment + '\r';
                if (segment.Substring(0, 3) == "BLG" && waitingSegments.Count == 0) counter++;
                if (counter >= 5)
                {
                    hl7SubBlocks.Add(currentBlock);
                    currentBlock = "";
                    counter = 0;
                }
            }

            foreach (var hl7SubBlock in hl7SubBlocks)
            {
                HL7.Dotnetcore.Message tmpMessage = new HL7.Dotnetcore.Message(msh+'\r'+hl7SubBlock);
                tmpMessage.ParseMessage();
                foreach (var innerSegment in tmpMessage.Segments())
                {
                    message.Segments(innerSegment.Name).Add(innerSegment);
                }
            }
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

But this doesn’t have the desired effect. I can’t just add the segment data in this way. Is there an internal limit being placed on the parse method? I don’t see it in your code, though stepping through it is in the next step.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
kulakcommented, Nov 6, 2018

I just run into possibly similar issue. The fix was to change to RegexOptions.Singleline:

    public static string[] ExtractMessages(string messages)
    {
        var expr = "\x0B(.*?)\x1C\x0D";
        var matches = Regex.Matches(messages, expr, RegexOptions.Singleline);  <-- fix
0reactions
jaime-olivarescommented, Nov 10, 2018

It is now published in NuGet.org as version 2.7.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is this an efficient way to parse a large string in FIX format?
My only suggestion at first glance is to replace string concatenations that are done in loops, such as TagString = TagString + ...
Read more >
String to long in Java
The correct way to convert a String to long in Java is to use the parseLong(String x) method of the Long wrapper class....
Read more >
Java Long parseLong() Method
The parseLong() method of Java Long class is used to parse the CharSequence argument as a signed long with the specified radix ,...
Read more >
Parse a Message
With LogViewPlus log entry messages are parsed separately from log entries. Parsing a log entry message allows you to extract and display the...
Read more >
Parsing strategies
Partial parsing (also referred to as On-demand parsing ) improves the performance of message flows, and reduces the amount of parsed data that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found