none
How to determine the length of the data by the first bit in NPL parser? RRS feed

  • Question

  • I am writing a parser for my UDP protocol.
    -- Data Field 1 (1 or 2 bytes)
    -- Data Field 2 (1 or 2 bytes)
    -- Data Field 3 1 byte

    As Data Field 1 and 2 depend the first bit which indicates whether another byte is needed.
    How to define this data in NPL parser file?

    Thanks in advance.

    Thursday, August 9, 2012 10:30 AM

All replies

  • Hi John,

    Just wanted to let you know I think I've got a good solution for you, just trying to run it by someone on our parser team first.

    Thanks,


    Michael Hawker | Program Manager | Network Monitor

    Saturday, August 11, 2012 1:31 AM
    Moderator
  • Hi John,

    Sorry for the delay on this.  As with any language there's a few ways to tackle this.  Here's the method suggested from one of our parser experts.

    He suggests using a variable length type.

    UnsignedNumber MyType(ByteLength)

    {

                    Size = PacketSize;

                    DisplayFormat = FormatString("%s, %d(%#x)", PPPPacketTypeTable( this ), this, this);

    }


    And then to use it like so:


    protocol MyProtocol

    {

                    MyType((UINT8( Framedata, Offset ) & 0x80) == 0 ? 1 : 2) DataField1;

                    MyType((UINT8( Framedata, Offset ) & 0x80) == 0 ? 1 : 2) DataField2;

                    UINT8 DataField3;

    }


    Hope that helps!

    Thanks,


    Michael Hawker | Program Manager | Network Monitor

    Thursday, August 16, 2012 5:50 PM
    Moderator