jefffhaynes / BinarySerializer

A declarative serialization framework for controlling formatting of data at the byte and bit level using field bindings, converters, and code.
MIT License
292 stars 62 forks source link

Reverse Binding not allowed #172

Closed mganss closed 3 years ago

mganss commented 3 years ago

I have the following class definition:

class Demo
{
    [FieldOrder(0)]
    public uint BodyCrc { get; set; }

    [FieldOrder(1)]
    [FieldCrc32(nameof(BodyCrc))]
    public uint Body { get; set; }
}

When trying to serialize I get

InvalidOperationException: Reverse binding not allowed on FieldValue attributes. Consider swapping source and target.

The file format I'm trying to serialize demands BodyCrc to come before Body. Is there an elegant way to do this?

jefffhaynes commented 3 years ago

Unfortunately no. The nature of the "serializer" is that one thing follows after the other. Recommend firing whomever wrote the format 😉

mganss commented 3 years ago

The pattern is part of the import/export format for a device from a big electronic equipment manufacturer. No docs of course, had to reverse engineer it 🙄