mikee47 / ConfigDB

Configuration database for Sming
GNU General Public License v3.0
3 stars 1 forks source link

Store counted strings in StringPool #16

Closed mikee47 closed 3 months ago

mikee47 commented 3 months ago

The StringPool storage currently stores string items as a sequence of NUL-terminated C-strings, identified by a StringId type which represents the starting offset for the value.

The main disadvantage of this is that it cannot accommodate binary data. This PR updates the pool to use counted strings instead. It adds CountedString to manage instances, with the length encoded in a prefix of one or two bytes.

A quick test shows that JsonStreamingParser can only handle a limited set of single-character escapes, such as \n, so requires updating to handle escapes such as \0 or \xfe.

mikee47 commented 3 months ago

Done some checking an according to the JSON spec escape support is strictly limited to text. \xnn is not available, only \u+nnnn for unicode escapes. So we'd need to use our own encoding (base64) to store binary data in JSON.

I'd better revise the Format::Json stuff as well. Sigh.