Skip to content

Commit ce2bfcf

Browse files
committed
Fix built-in Guid and BigInteger serializer do not honor PackerCompatibilityOptions #270
This commit fixes a bug that built-in Guid and BigInteger serializer do not honor PackerCompatibilityOptions and always they as raw(str) type. Note that PackBinary methods honor PackerCompatibilityOptions and output raw type header when PackBinaryAsRaw flag is specified.
1 parent 52c15ab commit ce2bfcf

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/MsgPack/Serialization/DefaultSerializers/DefaultSerializers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public System_GuidMessagePackSerializer( SerializationContext ownerContext )
320320
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
321321
protected internal override void PackToCore( Packer packer, System.Guid value )
322322
{
323-
packer.PackRaw( value.ToByteArray() );
323+
packer.PackBinary( value.ToByteArray() );
324324
}
325325

326326
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
@@ -345,7 +345,7 @@ protected internal override System.Guid UnpackFromCore( Unpacker unpacker )
345345
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
346346
protected internal override async Task PackToAsyncCore( Packer packer, System.Guid value, CancellationToken cancellationToken )
347347
{
348-
await packer.PackRawAsync( value.ToByteArray(), cancellationToken ).ConfigureAwait( false );
348+
await packer.PackBinaryAsync( value.ToByteArray(), cancellationToken ).ConfigureAwait( false );
349349
}
350350

351351
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
@@ -922,7 +922,7 @@ public System_Numerics_BigIntegerMessagePackSerializer( SerializationContext own
922922
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
923923
protected internal override void PackToCore( Packer packer, System.Numerics.BigInteger value )
924924
{
925-
packer.PackRaw( value.ToByteArray() );
925+
packer.PackBinary( value.ToByteArray() );
926926
}
927927

928928
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
@@ -947,7 +947,7 @@ protected internal override System.Numerics.BigInteger UnpackFromCore( Unpacker
947947
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
948948
protected internal override async Task PackToAsyncCore( Packer packer, System.Numerics.BigInteger value, CancellationToken cancellationToken )
949949
{
950-
await packer.PackRawAsync( value.ToByteArray(), cancellationToken ).ConfigureAwait( false );
950+
await packer.PackBinaryAsync( value.ToByteArray(), cancellationToken ).ConfigureAwait( false );
951951
}
952952

953953
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]

src/MsgPack/Serialization/DefaultSerializers/DefaultSerializers.tt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ var workArounds =
166166
{
167167
{ typeof( char ), new WorkAround(){ PackCode = "packer.Pack( ( System.UInt16 )value );", UnpackCode = "return ( System.Char ) unpacker.LastReadData.AsUInt16(); " } },
168168
{ typeof( decimal ), new WorkAround(){ PackCode = "packer.PackString( value.ToString( \"G\", CultureInfo.InvariantCulture ) );", UnpackCode = "return System.Decimal.Parse( unpacker.LastReadData.AsString(), CultureInfo.InvariantCulture ); " } },
169-
{ typeof( Guid ), new WorkAround(){ PackCode = "packer.PackRaw( value.ToByteArray() );", UnpackCode = "return new System.Guid( unpacker.LastReadData.AsBinary() ); " } },
170-
{ typeof( BigInteger ), new WorkAround(){ PackCode = "packer.PackRaw( value.ToByteArray() );", UnpackCode = "return new System.Numerics.BigInteger( unpacker.LastReadData.AsBinary() ); " } },
169+
{ typeof( Guid ), new WorkAround(){ PackCode = "packer.PackBinary( value.ToByteArray() );", UnpackCode = "return new System.Guid( unpacker.LastReadData.AsBinary() ); " } },
170+
{ typeof( BigInteger ), new WorkAround(){ PackCode = "packer.PackBinary( value.ToByteArray() );", UnpackCode = "return new System.Numerics.BigInteger( unpacker.LastReadData.AsBinary() ); " } },
171171
};
172172

173173
var asyncWorkArounds =
174174
new Dictionary<Type, string>()
175175
{
176176
{ typeof( char ), "packer.PackAsync( ( System.UInt16 )value, cancellationToken ).ConfigureAwait( false );" },
177177
{ typeof( decimal ), "packer.PackStringAsync( value.ToString( \"G\", CultureInfo.InvariantCulture ), cancellationToken ).ConfigureAwait( false );" },
178-
{ typeof( Guid ), "packer.PackRawAsync( value.ToByteArray(), cancellationToken ).ConfigureAwait( false );" },
179-
{ typeof( BigInteger ), "packer.PackRawAsync( value.ToByteArray(), cancellationToken ).ConfigureAwait( false );" },
178+
{ typeof( Guid ), "packer.PackBinaryAsync( value.ToByteArray(), cancellationToken ).ConfigureAwait( false );" },
179+
{ typeof( BigInteger ), "packer.PackBinaryAsync( value.ToByteArray(), cancellationToken ).ConfigureAwait( false );" },
180180
};
181181

182182
var notInSLs =

0 commit comments

Comments
 (0)