Add FrozenDictionary and FrozenSet serialization support#187
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 4 |
| Duplication | 3 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Agent-Logs-Url: https://github.com/dameng324/LightProto/sessions/e08a097c-4c65-476b-bfe7-c740061e1134 Co-authored-by: dameng324 <4465571+dameng324@users.noreply.github.com>
|
@copilot FrozenSet should be supported as well. |
Agent-Logs-Url: https://github.com/dameng324/LightProto/sessions/5be79ed4-03b6-47e6-944d-cd19255da29b Co-authored-by: dameng324 <4465571+dameng324@users.noreply.github.com>
Done — added |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #187 +/- ##
==========================================
+ Coverage 95.36% 95.40% +0.04%
==========================================
Files 121 123 +2
Lines 3061 3093 +32
Branches 423 425 +2
==========================================
+ Hits 2919 2951 +32
Misses 76 76
Partials 66 66 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
Register FrozenSet<> and FrozenDictionary<,> parsers (NET8+) and add necessary using. Extend non-generic serializer tests to handle FrozenSet/FrozenDictionary: add them to AOT-unsupported value providers, introduce a non-generic AOT helper that accepts an explicit Type and obtains reader/writer via Serializer.GetProtoReader/GetProtoWriter, and update non-generic serialize calls to pass the writer. Add SkipAot empty-deserialize tests for FrozenSet and FrozenDictionary. Conditional compilation is used to only enable parser registration on .NET 8 or greater.
|
There was a problem hiding this comment.
Pull request overview
Adds runtime serialization/deserialization support for .NET 8+ System.Collections.Frozen collections (FrozenDictionary<TKey,TValue> and FrozenSet<T>) to the LightProto runtime, mirroring the existing Immutable* collection parser patterns, and wires them into the dynamic (non-generic) serializer path.
Changes:
- Introduces
FrozenDictionaryProtoReader/WriterandFrozenSetProtoReader/Writerunder#if NET8_0_OR_GREATER. - Registers
FrozenSet<>/FrozenDictionary<,>inSerializer.Dynamically(NET8+ only) so non-generic APIs can resolve these parsers. - Adds NET8+ test coverage for both new parsers and extends non-generic serializer tests to include Frozen collection cases.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/LightProto/Parser/FrozenDictionary.cs |
Adds FrozenDictionary parser reader/writer (NET8+). |
src/LightProto/Parser/FrozenSet.cs |
Adds FrozenSet parser reader/writer (NET8+). |
src/LightProto/Serializer.Dynamically.cs |
Registers Frozen parsers (NET8+), enabling non-generic dynamic resolution. |
src/LightProto/PublicAPI/net/PublicAPI.Unshipped.txt |
Declares the new public parser types on the net API surface. |
tests/LightProto.Tests/Parsers/FrozenDictionaryTests.cs |
Adds NET8+ tests for FrozenDictionary parsing behavior. |
tests/LightProto.Tests/Parsers/FrozenSetTests.cs |
Adds NET8+ tests for FrozenSet parsing behavior. |
tests/LightProto.Tests/NonGenericSerializerTests.cs |
Adds Frozen types to non-generic test data and refactors to pass explicit writers for serialization. |
Comments suppressed due to low confidence (1)
tests/LightProto.Tests/NonGenericSerializerTests.cs:715
- In
LightProto_SerializeDeserialize_NonGeneric_AOT_WithType,readeris retrieved but never used. This also means the deserialization path still calls theDeserializeNonGeneric(Type, ...)overloads that internally callGetProtoReader(type)(dynamic-code path) instead of using the AOT-friendly overloads that accept anIProtoReader. Consider removing the unused local or (preferably) usingDeserializeNonGeneric(..., reader)overloads in the localDeserializedFrom*functions for consistency with the writer changes and to avoid unnecessary dynamic parsing work.
async Task LightProto_SerializeDeserialize_NonGeneric_AOT_WithType(object value, Type type)
{
var reader = Serializer.GetProtoReader(type);
var writer = Serializer.GetProtoWriter(type);
var bytes1 = SerializeToArray();
Adds
FrozenDictionary<TKey, TValue>andFrozenSet<T>as supported collection types, following the same patterns as theirImmutable*counterparts.Changes
src/LightProto/Parser/FrozenDictionary.cs—FrozenDictionaryProtoWriter<TKey, TValue>andFrozenDictionaryProtoReader<TKey, TValue>, guarded by#if NET8_0_OR_GREATER. Reader wrapsDictionaryProtoReaderand converts via.ToFrozenDictionary(); empty value isFrozenDictionary<TKey, TValue>.Empty.src/LightProto/Parser/FrozenSet.cs—FrozenSetProtoWriter<T>andFrozenSetProtoReader<TItem>, guarded by#if NET8_0_OR_GREATER. Reader wrapsArrayProtoReaderand converts via.ToFrozenSet(); empty value isFrozenSet<TItem>.Empty.tests/LightProto.Tests/Parsers/FrozenDictionaryTests.cs— Test coverage mirroringImmutableDictionaryTests, gated onNET8_0_OR_GREATER.tests/LightProto.Tests/Parsers/FrozenSetTests.cs— Test coverage mirroringImmutableHashSetTests, gated onNET8_0_OR_GREATER.PublicAPI/net/PublicAPI.Unshipped.txt— New public API declarations added to thenetsurface only (notnetstandard2.0).No generator changes required — the existing codegen path already handles these types.
Usage