Serialization Guidance for Source-Generated Fields (Vogen)
- Dominant language
- C#
- Stars
- 10.9k
- Forks
- 2.1k
- Avg merge
- 13h 56m
- Merged PRs (30d)
- 351
Description
It would be fantastic if Orleans could support Value Objects source-generated by Vogen.
There is currently an outstanding issue on the Vogen library here:
https://github.com/SteveDunn/Vogen/issues/385
We can't simply source generate the `[GenerateSerializer]` and `[Id]` attributes because the Orleans codegen won't pick them up at its source generation time.
Is there any guidance around minimally structuring user-land code to better inform the Orleans serializer how to serialize the value type?
Here's the intial approach I came up w/ -- it uses the assumption that each ValueObject will have one and only one field, `Value` (which Vogen enforces during compilation)
edit: did some more testing and need to add a implementation of `IFieldCodec` as well.
```csharp
[ValueObject]
[Immutable, RegisterSerializer]
public readonly partial record struct ValueObjectTest : IValueSerializer, IFieldCodec
{
[GenerateSerializer]
public readonly record struct Surrogate(string Value);
public void WriteField(ref Writer writer, uint fieldIdDelta, Type expectedType, ValueObjectTest value)
where TBufferWriter : IBufferWriter
{
StringCodec.WriteField(ref writer, fieldIdDelta, value.Value);
}
public ValueObjectTest ReadValue(ref Reader reader, Field field)
{
var value = StringCodec.ReadValue(ref reader, field);
return From(value);
}
public void Serialize(ref Writer writer, scoped ref ValueObjectTest value) where TBufferWriter : IBufferWriter
{
StringCodec.WriteField(ref writer, 0, value.Value);
}
public void Deserialize(ref Reader reader, scoped ref ValueObjectTest value)
{
var header = reader.ReadFieldHeader();
var stringValue = StringCodec.ReadValue(ref reader, header);
value = From(stringValue);
}
}
```
Contributor guide
Research direction
Start with the Vogen issue 385 and the C# ValueObjectTest implementation in this report, then inspect Orleans serializer and source-generation guidance. Done should be a documented, supported user-land pattern for serializing Vogen-generated value objects, or a clear statement of the remaining limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- distributed-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100