Bug 421357 - Support for variable-length strings w/o terminator
Summary: Support for variable-length strings w/o terminator
Status: REPORTED
Alias: None
Product: okteta
Classification: Applications
Component: Structures Tool (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Alex Richardson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-11 18:19 UTC by Johannes Zarl-Zierl
Modified: 2022-05-23 11:15 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Zarl-Zierl 2020-05-11 18:19:52 UTC
SUMMARY
Okteta currently supports fixed-length and character-terminated strings. Arrays OTOH can have a variable length dependent on a previously parsed primitive value.

It would be really nice to have this option for the maxCharCount and maxByteCount arguments as well. This would allow parsing of strings stored as length+stringdata without null-terminator.

Workarounds:
Use an array instead and look at the string value byte by byte.
Comment 1 Friedrich W. H. Kossebau 2022-05-23 11:15:16 UTC
Alex, would you remember a reason besides no spare time resources that maxCharCount and maxByteCount could not be also optionally scripted properties? Would look into this otherwise in the next weeks.

FTR, as another work-around (though resulting in data reparsing) one can use the updateFunc, starting with maxCharCount or maxByteCount set to 0 and then have the value updated from that type-wide generic function.

E.g. with JS:
	var obj = struct({
		length: uint16(),
		data: string("utf-8").set({
                    maxByteCount: 0,
                    updateFunc: function() { this.maxByteCount = this.parent.length.value; }
            })
	});
or with XML
	<struct name="variablelengthstring">
		<primitive name="length" type="uint16" />
		<string name="data" encoding="utf-8" maxByteCount="0" updateFunc="function() { this.maxByteCount = this.parent.length.value; }">
	</struct>