Closed Blackclaws closed 1 month ago
Probably I forgot the create a unit test for this case. Nullable value types are special because they become reference types. I`ll check that today evening.
I won't make it today but on Monday I`ll find the time for it :-)
v1.0.0-beta.19 adds write support for nullable value types (released in a few minutes). I will work on read support the next days.
Since the value can now be null, it will be encoded as variable length sequence
(H5T_VLEN
) data with a single element. This is the closest match to a nullable value type in the HDF5 spec.
Here you can see how public record Compound(double A, uint? Channel);
is being encoded to the H5 file (and then dumped via h5dump):
In case you have no record encapsulating the uint? Channel
field but the bare uint?
variable, you would need to write such kind of data using the generic H5Attribute<T>
like so:
uint? data = null;
file.Attributes["nullable"] = new H5Attribute<uint?>(data);
If you do not use the generic attribute you will get a compiler warning. It is necessary to use the generic version in combination with null
data because null
looses all runtime type information and then PureHDF does not know how to encode it. The generic H5Attribute<T>
keeps that type information.
When using nullable value types for Compound types an exception gets thrown:
Expected result was that it works. But it might not be able to work with null, the exception is not helpful though.