Bug 421357

Summary: Support for variable-length strings w/o terminator
Product: [Applications] okteta Reporter: Johannes Zarl-Zierl <johannes>
Component: Structures ToolAssignee: Alex Richardson <arichardson.kde>
Status: REPORTED ---    
Severity: wishlist CC: bart+kde, kossebau
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

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>