Guidance on encoder/decoder for compound types? #63
-
I have an F# record type which is marked as a ValueType via the [<Struct; StructLayout(LayoutKind.Sequential, Pack = 1)>]
type Peak<[<Measure>] 'm> =
{
mz : double<'m>
ic : single<intensity>
} In terms of the
Is there any info on how to either:
Thanks for any advice! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I was able to make a successful roundtrip (encode then decode) with the following unit test code: [Fact]
public void Test()
{
const string filePath = "test.h5";
const string datasetName = "data";
var writeData = new Peak[] {
new Peak(1.1, 2.2f),
new Peak(3.1, 4.5f)
};
// encode data
var writeFile = new H5File
{
[datasetName] = writeData
};
var options = new H5WriteOptions(
IncludeStructProperties: true
);
writeFile.Write(filePath, options);
// decode data
var readFile = H5File.OpenRead(filePath);
var readData = readFile.Dataset(datasetName).Read<Peak[]>();
Assert.True(writeData.SequenceEqual(readData));
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly record struct Peak(double mz, float ic); EncodingThe important part is When going this encode path only public fields are being considered to construct the HDF5 compound type while all others (static and private fields and all properties) are being ignored. By setting Now the two relevant properties are being detected with their proper names and PureHDF is able to copy over the property values into the HDF5 file. The disadvantage is the lower performance of this operation (now every value is being copied individually instead of bulk copying the whole instance data as it is the case with the DecodingWith the [StructLayout(LayoutKind.Sequential, Pack = 1)] PureHDF does not behave symmetrically here in that for decoding, the So to make it more consistent, PureHDF should also select the The problem which then arises is that the dotnet/runtime#38539 (comment) I did not yet implement this "constructor-based" instantiation and so the I will create a new issue to ensure that future versions do not have this asymmetric behavior anymore (i.e. slow Regarding your point A hook into the encoding / decoding logic would be nice for the users to have but it would mean for me to make large portions of the internally API public (there are many HDF5 format specific types involved) and I am not sure how such an extension point would look like so that the custom implementation has access to all relevant data structures but at the same time it should not be able to make the serialization too faulty. Debugging a wrong bit in an HDF5 file can take a while. I`d say it would be possible to build such an API but it requires some effort which I cannot put time into myself right now :-( |
Beta Was this translation helpful? Give feedback.
-
I'll give your explanation a proper read soon, but since I'm storing a compressed 2D-dataset where every 'cell' is a variable-length list of compound types, I think my performance is probably doomed anyway. |
Beta Was this translation helpful? Give feedback.
I was able to make a successful roundtrip (encode then decode) with the following unit test code: