SIGN IN SIGN UP

Only serialize key when C function asks for a key

For some operations, the DDS API requires a key instead of a sample ("dispose" is one of
those), and does this by invoking the "ddsi_serdata_from_sample" operation with kind set
to "SDK_KEY".

The Python binding is a bit unusual in that it serializes the data before calling into C
because that allows using Python code to serialize the data without having to call back
into Python code from C or being forced to interpret Python objects from C.  A mismatch is
possible, and this causes failures if the serialized form of the key is not a prefix of
the serialized form of the full sample.  For example:

    @dataclass
    class S(idl.IdlStruct, typename="S"):
        v: int
        k: int
        key("k")

    ih0 = dw.register_instance(S(0, 1))

Will misinterpret the bytes and treat the key value as 0 instead of as 1.

It can be dealt with in two ways:

* One is to continue always serializing a full sample in Python, fixing it up in the
  serdata implementation if a serialized key is requested.  This is small change in the
  Python "clayer";

* The other is to serialize a key when a key is expected. This is somewhat fragile, but
  the list of operations is small and the API rather stable.

This commit implements the second option, and mostly because it means the serializer will
not touch the non-key fields.

Signed-off-by: Erik Boasson <eb@ilities.com>
E
Erik Boasson committed
9d3fde8aca3fd6c22bf37ccd5000b5258f2a00b4
Parent: 2b5231f