Improve GVariant text format for 'ay' without NUL terminator
The GVariant text format has special syntax for "byte array with no embedded NUL bytes, but with NUL terminator". In this syntax, b'BTWi-fi'
is shorthand for [byte 0x42, 0x54, 0x57, 0x69, 0x2d, 0x66, 0x69, 0x0]
.
I guess the rationale for encouraging (e.g.) file paths sent as ay
over D-Bus to have a NUL terminator is that the C char *
string can be an offset into the serialized GVariant, without copying to add a NUL.
But there are many D-Bus APIs which do not put a NUL
terminator onto ay
values, which I think is perfectly legitimate. One example is the org.freedesktop.NetworkManager.AccessPoint.Ssid
property. Tools like gdbus
, D-Spy and Bustle use the GVariant text format to display values to the end user & accept input, but in this case when I introspect the Ssid of my neighbours' wireless network I see:
wjt@camille:~$ gdbus introspect --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager/AccessPoint/763 --only-properties
node /org/freedesktop/NetworkManager/AccessPoint/763 {
interface org.freedesktop.NetworkManager.AccessPoint {
properties:
readonly u Flags = 0;
readonly u WpaFlags = 0;
readonly u RsnFlags = 0;
readonly ay Ssid = [0x42, 0x54, 0x57, 0x69, 0x2d, 0x66, 0x69];
readonly u Frequency = 2412;
readonly s HwAddress = [redacted];
readonly u Mode = 2;
readonly u MaxBitrate = 195000;
readonly y Strength = 0x2a;
readonly i LastSeen = 7452;
};
};
and it would be nice if it instead showed me (straw-man syntax) bb'BTWi-fi'
. bb'foo\000'
would correspond to b'foo'
, and embedded NULs could be used if one is really keen.
(This might be a nice cousin of #536 – such values should be accessed in C as GBytes
.)