-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #701 from SteveDunn/memorypack-support
Implement MessagePack support
- Loading branch information
Showing
80 changed files
with
5,119 additions
and
821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...SerializationAndConversion/MessagePack/MessagePackScenario_using_conversion_attributes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#if NULLABLE_DISABLED_BUILD | ||
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. | ||
#endif | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using MessagePack; | ||
using MessagePack.Formatters; | ||
|
||
namespace Vogen.Examples.SerializationAndConversion.MessagePackScenario.UsingConversionAttributes; | ||
|
||
[ValueObject<int>(conversions: Conversions.MessagePack)] | ||
public readonly partial struct Age; | ||
|
||
[ValueObject<int>(conversions: Conversions.MessagePack)] | ||
public readonly partial struct PersonId; | ||
|
||
[ValueObject<string>(conversions: Conversions.MessagePack)] | ||
public readonly partial struct Name; | ||
|
||
[UsedImplicitly] | ||
[MessagePackObject] | ||
public class Person | ||
{ | ||
[Key(0)] | ||
public PersonId Id { get; set; } | ||
|
||
[Key(1)] | ||
public Name Name { get; set; } | ||
|
||
[Key(2)] | ||
public Age Age { get; set; } | ||
} | ||
|
||
[UsedImplicitly] | ||
public class MessagePackScenario_using_conversion_attributes : IScenario | ||
{ | ||
public Task Run() | ||
{ | ||
var customResolver = MessagePack.Resolvers.CompositeResolver.Create( | ||
[new PersonIdMessagePackFormatter(), new NameMessagePackFormatter(), new AgeMessagePackFormatter()], | ||
[MessagePack.Resolvers.StandardResolver.Instance] | ||
); | ||
|
||
var options = MessagePackSerializerOptions.Standard.WithResolver(customResolver); | ||
|
||
var originalObject = new Person | ||
{ | ||
Id = PersonId.From(123), | ||
Name = Name.From("Test"), | ||
Age = Age.From(42) | ||
}; | ||
|
||
byte[] serializedObject = MessagePackSerializer.Serialize(originalObject, options); | ||
|
||
var deserializedObject = MessagePackSerializer.Deserialize<Person>(serializedObject, options); | ||
|
||
Console.WriteLine($"Id: {deserializedObject.Id}, Name: {deserializedObject.Name}, Active: {deserializedObject.Age}"); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ogen.Examples/SerializationAndConversion/MessagePack/MessagePackScenario_using_markers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#if NULLABLE_DISABLED_BUILD | ||
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. | ||
#endif | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
using MessagePack; | ||
using MessagePack.Formatters; | ||
|
||
namespace Vogen.Examples.SerializationAndConversion.MessagePackScenario.UsingMarkers; | ||
|
||
[ValueObject<int>] | ||
public readonly partial struct Age; | ||
|
||
[ValueObject<int>] | ||
public readonly partial struct PersonId; | ||
|
||
[ValueObject<string>] | ||
public readonly partial struct Name; | ||
|
||
[UsedImplicitly] | ||
[MessagePackObject] | ||
public class Person | ||
{ | ||
[Key(0)] | ||
public PersonId Id { get; set; } | ||
|
||
[Key(1)] | ||
public Name Name { get; set; } | ||
|
||
[Key(2)] | ||
public Age Age { get; set; } | ||
} | ||
|
||
[MessagePack<PersonId>] | ||
[MessagePack<Name>] | ||
[MessagePack<Age>] | ||
public partial class Markers; | ||
|
||
[UsedImplicitly] | ||
public class MessagePackScenario_using_markers : IScenario | ||
{ | ||
public Task Run() | ||
{ | ||
var customResolver = MessagePack.Resolvers.CompositeResolver.Create( | ||
Markers.MessagePackFormatters, | ||
[MessagePack.Resolvers.StandardResolver.Instance] | ||
); | ||
|
||
var options = MessagePackSerializerOptions.Standard.WithResolver(customResolver); | ||
|
||
var originalObject = new Person | ||
{ | ||
Id = PersonId.From(123), | ||
Name = Name.From("Test"), | ||
Age = Age.From(42) | ||
}; | ||
|
||
byte[] serializedObject = MessagePackSerializer.Serialize(originalObject, options); | ||
|
||
var deserializedObject = MessagePackSerializer.Deserialize<Person>(serializedObject, options); | ||
|
||
Console.WriteLine($"Id: {deserializedObject.Id}, Name: {deserializedObject.Name}, Active: {deserializedObject.Age}"); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace Vogen; | ||
|
||
/// <summary> | ||
/// Represent a marker for MessagePack generation. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the value object.</typeparam> | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | ||
public class MessagePackAttribute<T> : ConversionMarkerAttribute | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
; Unshipped analyzer release | ||
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md | ||
|
||
|
||
### New Rules | ||
|
||
Rule ID | Category | Severity | Notes | ||
--------|----------|----------|------- | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Vogen; | ||
|
||
/// <summary> | ||
/// Represents an instance of a marker attribute, e.g. `EfCoreConverterAttribute` or a `MemoryPackageConverterAttribute`, and its | ||
/// containing marker class. | ||
/// </summary> | ||
/// <param name="VoSymbol">The symbol for the value object being referenced. In effect, the generic value of the attribute.</param> | ||
/// <param name="UnderlyingTypeSymbol">The symbol for the underlying type that is represented by the value object.</param> | ||
/// <param name="MarkerClassSymbol">The symbol for the marker class that has the marker attribute(s).</param> | ||
internal record ConversionMarker( | ||
ConversionMarkerKind Kind, | ||
INamedTypeSymbol VoSymbol, | ||
INamedTypeSymbol UnderlyingTypeSymbol, | ||
INamedTypeSymbol MarkerClassSymbol); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Vogen; | ||
|
||
public enum ConversionMarkerKind | ||
{ | ||
Unrecognized, | ||
EFCore, | ||
MessagePack, | ||
} |
Oops, something went wrong.