Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default Message processing - what's a better way?

    Support you need to consume this messasge and pick up a tag 107.

    8=FIX.4.49=64235=X49=CME52=1269878006469107=ZTZ048 =470015269=0276=K270=-271=-1023=0269=0276=K270=-271=-1023=1269=1276=K270=-271=-1023=0269=1276=K270=-271=-1023=1269=0270=107.4453125271=251023=0269=0270=-271=-1023=1269=0270=-271=-1023=2269=0270=-271=-1023=3269=0270=-271=-1023=4269=0270=-271=-1023=5269=0270=-271=-1023=6269=0270=-271=-1023=7269=0270=-271=-1023=8269=0270=-271=-1023=9269=1270=-271=-1023=0269=1270=-271=-1023=1269=1270=-271=-1023=2269=1270=-271=-1023=3269=1270=-271=-1023=4269=1270=-271=-1023=5269=1270=-271=-1023=6269=1270=-271=-1023=7269=1270=-271=-1023=8269=1270=-271=-1023=94101=110=138

    so, i have

    Java Code:
    processMessage(data, 107);
    and then ...

    Java Code:
    private String processMessage(String data) {
    
       ix = data.indexOf(107);
       ig = data.substring(ix).indexOf(fixDelimiter);
    
       return (data.substring(ix, ix + ig))
    }
    Is there an easier/better way?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default

    Won't that simply return the first 107?
    What about all the others?
    And also, won't it simply return from the 107 onwards?
    Not the whole value of (presumably) the stuff between a pair of "="?

  3. #3
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default

    I oversimplified this for this example. Value assigjned to tag 107 is returned.
    But with regard to workign with data that consists of the format A=1B=2C=3, what's the best way to retrieve value assigned to A,B or C?

    Propeties won't work - too heavy of an operation - need to process these messages on the fly at a rate fo 200-2000 per second.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default

    Well, beyond me not actually understanding how you differentiate between a value and a key there, I'm not sure how else you would get that value out.

    Do you need to parse all the values coming in? In which case you ought to (somehow) split them into there key/value pairs and then work on them, but if you are simply hunting for a single value in a string, then the method you have is about as good as you're going to get I'd have thought. As to performance, if you have to do it, you have to do it...

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default

    Oh, and could you edit your OP so that line isn't so blimmin' long?
    :)

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    I can't make any sense out of what you're trying to do at all. Are these supposed to be key/value pairs? How are you to know where a value ends and the next key begins? Can you explain the contents of your message a little better?

    -Gary-

  7. #7
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default

    Ok guys, let me try:

    There is a message that is being received and processed. That message follows the following format:

    Java Code:
    Tag=ValueDelimiterTag=ValueDelimiter
    where Delimiter is known and is consistent

    In reality message looks like like:
    Java Code:
    8=FIX.4.49=64235=X49=CME52=1269878006469107=ZTZ048
    This way, i would like to be able to "request" value assigned to tag 8 and be able to receive "FIX.4.4"

    I hope this adds some clarity

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by mac View Post
    Ok guys, let me try:

    There is a message that is being received and processed. That message follows the following format:

    Java Code:
    Tag=ValueDelimiterTag=ValueDelimiter
    where Delimiter is known and is consistent

    In reality message looks like like:
    Java Code:
    8=FIX.4.49=64235=X49=CME52=1269878006469107=ZTZ048
    This way, i would like to be able to "request" value assigned to tag 8 and be able to receive "FIX.4.4"

    I hope this adds some clarity
    Why is it FIX.4.4 and not FIX.4.49?

    -Gary-

  9. #9
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default

    There is a invisible delimiter '\u0001' between 4 and 9

    (sorry)

  10. #10
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    OK, now it starts to make sense.

    I can't deal with this right now, but if nobody else has answered, I'll take a look in an hour or two.

    -Gary-

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by mac View Post
    There is a invisible delimiter '\u0001' between 4 and 9

    (sorry)
    Does the entire message end with \u0001? i.e. is the entire message composed of {key=value\u0001}*

    If so a simple regexp and a bit of fiddling can do the job.

    kind regards,

    Jos

  12. #12
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default

    Yes, entire message is delimited as you have described:

    Java Code:
    Key=Value\u0001
    Regex and such have always been my weakest point, i would appreciate greatly if you can give me a sample on how i can retrieve a particular Key

  13. #13
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Based on
    Quote Originally Posted by mac View Post
    need to process these messages on the fly at a rate fo 200-2000 per second.
    ...I don't think I would recommend regexp. Out of a typical message, how many key/value pairs will you be interested in? One? A handful? Most? All? How will the messages be arriving? On a network stream? In a complete string (e-mail, HTTP POST, something like that)? Depending on your answers, I would recommend different approaches.

    -Gary-

  14. #14
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default

    Realistically i would need to be able to pick up 2-3 tags out of approximately 40 tags that make up the message.
    Message will arriove via aTibco bus

  15. #15
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Also, it looks like some keys appear multiple times in the message. How do you want to handle that?

    -Gary-

  16. #16
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    I think I would probably try to do this on a sort of dispatch model, parsing the messages char-by-char as they come in, and sending off the key/value pairs to another method. The idea being that we want to look at each character of the message only once. So assuming the Tibco bus can somehow be bound to a BufferedReader, it would go something like this (not tested):
    Java Code:
            public void parseAndDispatch(BufferedReader source) {
                    String key;
                    String value;
                    int size = MAX_KEY_OR_VALUE_LENGTH;
                    StringBuilder sb = new StringBuilder(size);
                    while (source.ready()) {
                            char c = source.read();
                            if (c == '=') {
                                    key = sb.toString();
                                    sb.setLength(0);
                            } else if (c == DELIMITER) {
                                    value = sb.toString();
                                    sb.setLength(0);
                                    doSomethingWithThis(key, value);
                            } else {
                                    sb.append(c);
                            }
                    }
            }
    I'm sure there are bugs here, and this assumes that each key/value pair is atomic, and doesn't need anything else from the message (probably a faulty assumption). Think of this more as a sketch of a possible approach. Good luck!

    -Gary-

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default

    And can you pleeeeease fix that first post?

    Is no one else suffering from the Horizontal Scrollbar From Hell?

  18. #18
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by Tolls View Post
    And can you pleeeeease fix that first post?

    Is no one else suffering from the Horizontal Scrollbar From Hell?
    It's wrapping for me. You see it all on one line?

    -Gary-

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default

    It's Firefox...presumably because there's no actual obvious break in the string.
    IE wraps it on the "-", presumably taking those as natural breaks...even though there's actually nothing to indicate that they are in this case.

  20. #20
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by gcalvin View Post
    ...I don't think I would recommend regexp.
    Why not? A simple "([^=]+)=([^\u0001]+)\u0001" would make a Matcher find the keys as group #1 and their associated values as group #2; if the keys are unique you can stick those pairs in a Map or a Properties object and voila.

    kind regards,

    Jos

Page 1 of 2 12 LastLast

Similar Threads

  1. image processing
    By sunithamm in forum Advanced Java
    Replies: 6
    Last Post: 12-30-2010, 11:46 AM
  2. Processing help
    By menez in forum Java Applets
    Replies: 3
    Last Post: 02-23-2010, 02:13 AM
  3. Image processing
    By syarizma in forum Advanced Java
    Replies: 6
    Last Post: 08-17-2009, 05:15 AM
  4. image processing
    By sathish natrajan in forum Java 2D
    Replies: 2
    Last Post: 11-06-2008, 05:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •