Skip to content

Commit d5d6b6e

Browse files
authored
Merge pull request MessagePack-CSharp#427 from aspnet/aspnetcore
Add a project to build the reader \ writer with internal visibility
2 parents 30953c4 + fba2344 commit d5d6b6e

File tree

14 files changed

+208
-72
lines changed

14 files changed

+208
-72
lines changed

MessagePack.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{
7070
EndProject
7171
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerializerBenchmark", "benchmark\SerializerBenchmark\SerializerBenchmark.csproj", "{4142EA80-FEF4-44A5-8553-1AE84BEBAFED}"
7272
EndProject
73+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePack.Internal", "src\MessagePack.Internal\MessagePack.Internal.csproj", "{C100FBA6-4164-4D6A-A532-5984D2B8DCB0}"
74+
EndProject
75+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePack.Internal.Tests", "tests\MessagePack.Internal.Tests\MessagePack.Internal.Tests.csproj", "{8D9FD130-7905-47D8-A25C-7FDEE28EA0E8}"
76+
EndProject
7377
Global
7478
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7579
Debug|Any CPU = Debug|Any CPU
@@ -148,6 +152,14 @@ Global
148152
{4142EA80-FEF4-44A5-8553-1AE84BEBAFED}.Debug|Any CPU.Build.0 = Debug|Any CPU
149153
{4142EA80-FEF4-44A5-8553-1AE84BEBAFED}.Release|Any CPU.ActiveCfg = Release|Any CPU
150154
{4142EA80-FEF4-44A5-8553-1AE84BEBAFED}.Release|Any CPU.Build.0 = Release|Any CPU
155+
{C100FBA6-4164-4D6A-A532-5984D2B8DCB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
156+
{C100FBA6-4164-4D6A-A532-5984D2B8DCB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
157+
{C100FBA6-4164-4D6A-A532-5984D2B8DCB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
158+
{C100FBA6-4164-4D6A-A532-5984D2B8DCB0}.Release|Any CPU.Build.0 = Release|Any CPU
159+
{8D9FD130-7905-47D8-A25C-7FDEE28EA0E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
160+
{8D9FD130-7905-47D8-A25C-7FDEE28EA0E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
161+
{8D9FD130-7905-47D8-A25C-7FDEE28EA0E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
162+
{8D9FD130-7905-47D8-A25C-7FDEE28EA0E8}.Release|Any CPU.Build.0 = Release|Any CPU
151163
EndGlobalSection
152164
GlobalSection(SolutionProperties) = preSolution
153165
HideSolutionNode = FALSE
@@ -171,6 +183,8 @@ Global
171183
{79C2B2CB-872A-4BA9-82DC-60F6DD77F940} = {19FE674A-AC94-4E7E-B24C-2285D1D04CDE}
172184
{85763F30-7733-44AB-89AB-D1B64F6E0D93} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
173185
{4142EA80-FEF4-44A5-8553-1AE84BEBAFED} = {51A614B0-E583-4DD2-AC7D-6A65634582E0}
186+
{C100FBA6-4164-4D6A-A532-5984D2B8DCB0} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
187+
{8D9FD130-7905-47D8-A25C-7FDEE28EA0E8} = {19FE674A-AC94-4E7E-B24C-2285D1D04CDE}
174188
EndGlobalSection
175189
GlobalSection(ExtensibilityGlobals) = postSolution
176190
SolutionGuid = {B3911209-2DBF-47F8-98F6-BBC0EDFE63DE}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("MessagePack.Internal.Tests")]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netcoreapp2.2</TargetFrameworks>
5+
<DefineConstants>$(DefineConstants);ENABLE_UNSAFE_MSGPACK;SPAN_BUILTIN;MESSAGEPACK_INTERNAL</DefineConstants>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
8+
<NoWarn>CS0436;$(NoWarn)</NoWarn>
9+
10+
<Description>
11+
A project that compiles MessagePackReader \ MessagePackWriter and related types with internal visibility modifier.
12+
This is used as a way to verify that sources in AspNetCore where MessagePackage is
13+
consumed as an implementation detail can compile and run.
14+
</Description>
15+
</PropertyGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Nerdbank.Streams" Version="2.1.28-beta" />
19+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<Compile Include="..\MessagePack\BufferWriter.cs" />
24+
<Compile Include="..\MessagePack\ExtensionHeader.cs" />
25+
<Compile Include="..\MessagePack\ExtensionResult.cs" />
26+
<Compile Include="..\MessagePack\FloatBits.cs" />
27+
<Compile Include="..\MessagePack\MessagePackCode.cs" />
28+
<Compile Include="..\MessagePack\MessagePackReader.cs" />
29+
<Compile Include="..\MessagePack\MessagePackReader.Integers.cs" />
30+
<Compile Include="..\MessagePack\MessagePackWriter.cs" />
31+
<Compile Include="..\MessagePack\Nil.cs" />
32+
<Compile Include="..\MessagePack\SequencePool.cs" />
33+
<Compile Include="..\MessagePack\SequenceReader.cs" />
34+
<Compile Include="..\MessagePack\SequenceReaderExtensions.cs" />
35+
<Compile Include="..\MessagePack\StringEncoding.cs" />
36+
<Compile Include="..\MessagePack\Internal\DateTimeConstants.cs" />
37+
<Compile Include="..\MessagePack\Internal\GuidBits.cs" />
38+
</ItemGroup>
39+
40+
</Project>

src/MessagePack/ExtensionHeader.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
namespace MessagePack
22
{
3-
public struct ExtensionHeader
3+
#if MESSAGEPACK_INTERNAL
4+
internal
5+
#else
6+
public
7+
#endif
8+
struct ExtensionHeader
49
{
510
public sbyte TypeCode { get; private set; }
611
public uint Length { get; private set; }

src/MessagePack/ExtensionResult.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
namespace MessagePack
55
{
6-
public struct ExtensionResult
6+
#if MESSAGEPACK_INTERNAL
7+
internal
8+
#else
9+
public
10+
#endif
11+
struct ExtensionResult
712
{
813
public sbyte TypeCode { get; private set; }
914

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace MessagePack.Formatters
2+
{
3+
public class NilFormatter : IMessagePackFormatter<Nil>
4+
{
5+
public static readonly IMessagePackFormatter<Nil> Instance = new NilFormatter();
6+
7+
NilFormatter()
8+
{
9+
10+
}
11+
12+
public void Serialize(ref MessagePackWriter writer, Nil value, IFormatterResolver typeResolver)
13+
{
14+
writer.WriteNil();
15+
}
16+
17+
public Nil Deserialize(ref MessagePackReader reader, IFormatterResolver typeResolver)
18+
{
19+
return reader.ReadNil();
20+
}
21+
}
22+
23+
// NullableNil is same as Nil.
24+
public class NullableNilFormatter : IMessagePackFormatter<Nil?>
25+
{
26+
public static readonly IMessagePackFormatter<Nil?> Instance = new NullableNilFormatter();
27+
28+
NullableNilFormatter()
29+
{
30+
31+
}
32+
33+
public void Serialize(ref MessagePackWriter writer, Nil? value, IFormatterResolver typeResolver)
34+
{
35+
writer.WriteNil();
36+
}
37+
38+
public Nil? Deserialize(ref MessagePackReader reader, IFormatterResolver typeResolver)
39+
{
40+
return reader.ReadNil();
41+
}
42+
}
43+
}

src/MessagePack/MessagePackCode.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ namespace MessagePack
77
/// <summary>
88
/// https://github.com/msgpack/msgpack/blob/master/spec.md#serialization-type-to-format-conversion
99
/// </summary>
10-
public enum MessagePackType : byte
10+
#if MESSAGEPACK_INTERNAL
11+
internal
12+
#else
13+
public
14+
#endif
15+
enum MessagePackType : byte
1116
{
1217
Unknown = 0,
1318

@@ -25,7 +30,12 @@ public enum MessagePackType : byte
2530
/// <summary>
2631
/// https://github.com/msgpack/msgpack/blob/master/spec.md#overview
2732
/// </summary>
28-
public static class MessagePackCode
33+
#if MESSAGEPACK_INTERNAL
34+
internal
35+
#else
36+
public
37+
#endif
38+
static class MessagePackCode
2939
{
3040
public const byte MinFixInt = 0x00; // 0
3141
public const byte MaxFixInt = 0x7f; // 127
@@ -200,12 +210,22 @@ public static bool IsSignedInteger(byte code)
200210
}
201211
}
202212

203-
public static class ReservedMessagePackExtensionTypeCode
213+
#if MESSAGEPACK_INTERNAL
214+
internal
215+
#else
216+
public
217+
#endif
218+
static class ReservedMessagePackExtensionTypeCode
204219
{
205220
public const sbyte DateTime = -1;
206221
}
207222

208-
public static class MessagePackRange
223+
#if MESSAGEPACK_INTERNAL
224+
internal
225+
#else
226+
public
227+
#endif
228+
static class MessagePackRange
209229
{
210230
public const int MinFixNegativeInt = -32;
211231
public const int MaxFixNegativeInt = -1;

src/MessagePack/MessagePackReader.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ namespace MessagePack
1616
/// <remarks>
1717
/// <see href="https://github.com/msgpack/msgpack/blob/master/spec.md">The MessagePack spec.</see>
1818
/// </remarks>
19-
public ref partial struct MessagePackReader
19+
#if MESSAGEPACK_INTERNAL
20+
internal
21+
#else
22+
public
23+
#endif
24+
ref partial struct MessagePackReader
2025
{
2126
/// <summary>
2227
/// The reader over the sequence.

src/MessagePack/MessagePackWriter.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Andrew Arnott. All rights reserved.
22
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
33

4-
using MessagePack.Formatters;
54
using MessagePack.Internal;
65
using Microsoft;
76
using System;
@@ -19,7 +18,12 @@ namespace MessagePack
1918
/// <remarks>
2019
/// <see href="https://github.com/msgpack/msgpack/blob/master/spec.md">The MessagePack spec.</see>
2120
/// </remarks>
22-
public ref struct MessagePackWriter
21+
#if MESSAGEPACK_INTERNAL
22+
internal
23+
#else
24+
public
25+
#endif
26+
ref struct MessagePackWriter
2327
{
2428
/// <summary>
2529
/// The writer to use.
@@ -86,7 +90,13 @@ public void WriteNil()
8690
/// Copies bytes directly into the message pack writer.
8791
/// </summary>
8892
/// <param name="rawMessagePackBlock">The span of bytes to copy from.</param>
89-
public void WriteRaw(ReadOnlySequence<byte> rawMessagePackBlock) => rawMessagePackBlock.CopyTo(ref writer);
93+
public void WriteRaw(ReadOnlySequence<byte> rawMessagePackBlock)
94+
{
95+
foreach (var segment in rawMessagePackBlock)
96+
{
97+
writer.Write(segment.Span);
98+
}
99+
}
90100

91101
/// <summary>
92102
/// Write the length of the next array to be written in the most compact form of
@@ -665,7 +675,7 @@ public void Write(DateTime dateTime)
665675
{
666676
if (this.OldSpec)
667677
{
668-
throw new NotSupportedException($"The MsgPack spec does not define a format for {nameof(DateTime)} in {nameof(OldSpec)} mode. Turn off {nameof(OldSpec)} mode or use the {nameof(NativeDateTimeFormatter)}.");
678+
throw new NotSupportedException($"The MsgPack spec does not define a format for {nameof(DateTime)} in {nameof(OldSpec)} mode. Turn off {nameof(OldSpec)} mode or use NativeDateTimeFormatter.");
669679
}
670680
else
671681
{

src/MessagePack/Nil.cs

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
namespace MessagePack
55
{
6-
public struct Nil : IEquatable<Nil>
6+
#if MESSAGEPACK_INTERNAL
7+
internal
8+
#else
9+
public
10+
#endif
11+
struct Nil : IEquatable<Nil>
712
{
813
public static readonly Nil Default = new Nil();
914

@@ -28,49 +33,3 @@ public override string ToString()
2833
}
2934
}
3035
}
31-
32-
namespace MessagePack.Formatters
33-
{
34-
public class NilFormatter : IMessagePackFormatter<Nil>
35-
{
36-
public static readonly IMessagePackFormatter<Nil> Instance = new NilFormatter();
37-
38-
NilFormatter()
39-
{
40-
41-
}
42-
43-
public void Serialize(ref MessagePackWriter writer, Nil value, IFormatterResolver typeResolver)
44-
45-
{
46-
writer.WriteNil();
47-
}
48-
49-
public Nil Deserialize(ref MessagePackReader reader, IFormatterResolver typeResolver)
50-
{
51-
return reader.ReadNil();
52-
}
53-
}
54-
55-
// NullableNil is same as Nil.
56-
public class NullableNilFormatter : IMessagePackFormatter<Nil?>
57-
{
58-
public static readonly IMessagePackFormatter<Nil?> Instance = new NullableNilFormatter();
59-
60-
NullableNilFormatter()
61-
{
62-
63-
}
64-
65-
public void Serialize(ref MessagePackWriter writer, Nil? value, IFormatterResolver typeResolver)
66-
67-
{
68-
writer.WriteNil();
69-
}
70-
71-
public Nil? Deserialize(ref MessagePackReader reader, IFormatterResolver typeResolver)
72-
{
73-
return reader.ReadNil();
74-
}
75-
}
76-
}

0 commit comments

Comments
 (0)