mdavidsaver / pvxs

PVA protocol client/server library and utilities.
https://mdavidsaver.github.io/pvxs/
Other
19 stars 25 forks source link

Deserialize Size #62

Closed mdavidsaver closed 7 months ago

mdavidsaver commented 7 months ago

The PVD notion of "size" is ambiguous in being used both for counts (number of characters in a string, or members of structure or array) and as the index of a union. "size" has a special encoding "\xff" as a shorthand for size_t(-1) used to indicate a "null" string or union.

In C++ (PVXS and pvDataCPP) there is no "null" string, so only "\x00" will be emitted, and "\x00" and "\xff" decode as an empty string. However, pvDataJava will encode a "null" string as "\xff".

With both C++ implementations, a resulting quirk of portability is that "\xff" and "\xfe\xff\xff\xff\xff" will both decode as size_t(-1) on 32-bit targets, but not on 64-bit targets.

17464a117acc9d225904c4f92cc9dc44bef2ccc0 previously avoids an issue where a bitmask "size" of "\xff" results in an integer overflow.

This PR goes further to add a distinct type Selector type for union index where the special "null" encoding is recognized. "null" is also recognized when decoding a string. In other cases, a "null" Size will now be a decode error.