How can we define a type tree for a variable string, where the first two bytes indicate the length and then the actual string, characters that follow with the length?

02ab, here ab is the string.

03abcghj. here abc is the string, the rest of the part something else

有帮助吗?

解决方案

You can create a group with two fields, a size and a string. Then right click on the size field and select the Sized attribute for that field. The attribute means that the first field contains the length of the next field.

From the manual:

Sized Attribute

The sized attribute is used on a component whose value specifies the size (in bytes) of the component immediately following it. The sized attribute can be used on more than one component of a group.

Size

For example, you may have a variable length component with a number immediately preceding it that indicates the length of the component:

10Washington

The 10 indicates the size of the following component.

Some important points about using the sized attribute are:

  • The component with the sized attribute must be defined as an unsigned integer.

  • If a binary byte stream item does not have a fixed size, the component preceding it must specify its size and the sized attribute must be used on that component.

The size of a component is the number of bytes from the beginning of that component, up to and including the end of the component. If a component has a series range [such as (1:3)], the size includes all of the members in the series of that component. If a delimiter separates each member of that series, the delimiters must be included in the size. Also, if release characters appear in the component, they must be included in the size.

The size does not include delimiters that separate one component type from the next.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top