Skip to content

Commit 5dd1564

Browse files
committed
initial drop
1 parent 521c7b5 commit 5dd1564

17 files changed

+1516
-0
lines changed

.gitattributes

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.vs
2+
artifacts
3+
bin
4+
obj
5+
*.user
6+
TestFiles/
7+
*.suo
8+
Tools/PEVerify.*
9+
packages/
10+
project.lock.json
11+
Tests.Dnx/*.dll
12+
Tests.Dnx/*.bin
13+
Tests.Dnx/*.dat
14+
Tests.Dnx/*.dump
15+
Tests.Dnx/Data.protobuf
16+
Tests.Dnx/big.file
17+
Tests.Dnx/sandbox.txt
18+
Tests.Dnx/protoTest.txt
19+
Tests.Dnx/TraceCompile.txt
20+
*.NoCommit.*
21+
*.pubxml
22+
del.me
23+
_ReSharper.Caches/
24+
BenchmarkDotNet.Artifacts/
25+
filedata.bin
26+
*.binlog
27+
src/VBTest/*
28+
src/Benchmark/DalSerializer.dll

Directory.build.props

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<Project>
2+
<PropertyGroup>
3+
<RootNamespace>ProtoBuf</RootNamespace>
4+
<Authors>Marc Gravell</Authors>
5+
<OutputType>Library</OutputType>
6+
<SignAssembly>true</SignAssembly>
7+
<DelaySign>False</DelaySign>
8+
<NoWarn>NU5105;CS1701;BC42016</NoWarn>
9+
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)ProtoBuf.snk</AssemblyOriginatorKeyFile>
10+
<Copyright>See https://github.com/mgravell/protobuf-net</Copyright>
11+
<PackageLicenseUrl>https://github.com/mgravell/protobuf-net/blob/master/Licence.txt</PackageLicenseUrl>
12+
<PackageProjectUrl>https://github.com/mgravell/protobuf-net</PackageProjectUrl>
13+
<RepositoryUrl>https://github.com/mgravell/protobuf-net</RepositoryUrl>
14+
<RepositoryType>git</RepositoryType>
15+
<Product>protobuf-net ($(TargetFramework))</Product>
16+
<PackageReleaseNotes>https://mgravell.github.io/protobuf-net/releasenotes#$(VersionPrefix)</PackageReleaseNotes>
17+
18+
<PackageTags>binary;serialization;protobuf;grpc</PackageTags>
19+
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>embedded</DebugType>
22+
<DefaultLanguage>en-US</DefaultLanguage>
23+
<IncludeSymbols>false</IncludeSymbols>
24+
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
25+
<LangVersion>preview</LangVersion>
26+
<Nullable>enable</Nullable>
27+
<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)Shared.ruleset</CodeAnalysisRuleset>
28+
</PropertyGroup>
29+
<PropertyGroup Condition="'$(Configuration)'=='Release' or '$(Configuration)'=='VS'">
30+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
31+
<Optimize>true</Optimize>
32+
</PropertyGroup>
33+
34+
<ItemGroup>
35+
<PackageReference Include="SourceLink.Create.GitHub" Version="2.8.3" PrivateAssets="All" />
36+
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.3" />
37+
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.8.3" />
38+
<PackageReference Include="Nerdbank.GitVersioning" Version="2.3.138">
39+
<PrivateAssets>all</PrivateAssets>
40+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
41+
</PackageReference>
42+
</ItemGroup>
43+
</Project>

ProtoBuf.snk

596 Bytes
Binary file not shown.

global.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "3.0.100-preview7-012341"
4+
}
5+
}

protobuf-net.Grpc.sln

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29006.145
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "protobuf-net.Grpc", "src\protobuf-net.Grpc\protobuf-net.Grpc.csproj", "{30D0874E-DA1A-497E-A181-37739A46CF32}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3E0CF81A-BA7A-4AAB-B46D-5AC8E22B0644}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{F7FAC6AD-62B0-4B79-98AA-DBD99F84E4E9}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "grpc", "grpc", "{ABFDBC40-BB23-4E19-80C8-8ACC96671B63}"
13+
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet-grpc", "dotnet-grpc", "{BCE4682E-1594-4DEF-BC23-35E8571FD002}"
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pb-net-grpc", "pb-net-grpc", "{7F457A71-E0C6-4DB1-B692-56541CAEDB5A}"
17+
EndProject
18+
Global
19+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
20+
Debug|Any CPU = Debug|Any CPU
21+
Release|Any CPU = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
24+
{30D0874E-DA1A-497E-A181-37739A46CF32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{30D0874E-DA1A-497E-A181-37739A46CF32}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{30D0874E-DA1A-497E-A181-37739A46CF32}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{30D0874E-DA1A-497E-A181-37739A46CF32}.Release|Any CPU.Build.0 = Release|Any CPU
28+
EndGlobalSection
29+
GlobalSection(SolutionProperties) = preSolution
30+
HideSolutionNode = FALSE
31+
EndGlobalSection
32+
GlobalSection(NestedProjects) = preSolution
33+
{30D0874E-DA1A-497E-A181-37739A46CF32} = {3E0CF81A-BA7A-4AAB-B46D-5AC8E22B0644}
34+
{ABFDBC40-BB23-4E19-80C8-8ACC96671B63} = {F7FAC6AD-62B0-4B79-98AA-DBD99F84E4E9}
35+
{BCE4682E-1594-4DEF-BC23-35E8571FD002} = {F7FAC6AD-62B0-4B79-98AA-DBD99F84E4E9}
36+
{7F457A71-E0C6-4DB1-B692-56541CAEDB5A} = {F7FAC6AD-62B0-4B79-98AA-DBD99F84E4E9}
37+
EndGlobalSection
38+
GlobalSection(ExtensibilityGlobals) = postSolution
39+
SolutionGuid = {BA14B07C-CA29-430D-A600-F37A050636D3}
40+
EndGlobalSection
41+
EndGlobal

src/protobuf-net.Grpc/CallContext.cs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Grpc.Core;
2+
using ProtoBuf.Grpc.Internal;
3+
using System;
4+
using System.Threading;
5+
using System.Runtime.CompilerServices;
6+
using System.ComponentModel;
7+
8+
namespace ProtoBuf.Grpc
9+
{
10+
/// <summary>
11+
/// Unifies the API for client and server gRPC call contexts; the API intersection is available
12+
/// directly - for client-specific or server-specific options: use .Client or .Server; note that
13+
/// whether this is a client or server context depends on the usage. Silent conversions are available.
14+
/// </summary>
15+
public readonly struct CallContext
16+
{
17+
public static readonly CallContext Default; // it is **not** accidental that this is a field - allows effective ldsflda usage
18+
19+
public CallOptions Client { get; }
20+
public ServerCallContext? Server { get; }
21+
22+
public Metadata RequestHeaders => Client.Headers;
23+
public CancellationToken CancellationToken => Client.CancellationToken;
24+
public DateTime? Deadline => Client.Deadline;
25+
public WriteOptions WriteOptions => Client.WriteOptions;
26+
27+
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
28+
internal MetadataContext? Prepare() => _metadataContext?.Reset();
29+
30+
public CallContext(ServerCallContext server)
31+
{
32+
Server = server;
33+
Client = server == null ? default : new CallOptions(server.RequestHeaders, server.Deadline, server.CancellationToken, server.WriteOptions);
34+
_metadataContext = null;
35+
}
36+
37+
public CallContext(in CallOptions client, CallContextFlags flags = CallContextFlags.None)
38+
{
39+
Client = client;
40+
Server = default;
41+
_metadataContext = (flags & CallContextFlags.CaptureMetadata) == 0 ? null : new MetadataContext();
42+
}
43+
44+
private readonly MetadataContext? _metadataContext;
45+
46+
public Metadata ResponseHeaders() => _metadataContext?.Headers ?? ThrowNoContext<Metadata>();
47+
48+
public Metadata ResponseTrailers() => _metadataContext?.Trailers ?? ThrowNoContext<Metadata>();
49+
50+
public Status ResponseStatus() => _metadataContext?.Status ?? ThrowNoContext<Status>();
51+
52+
[MethodImpl]
53+
private T ThrowNoContext<T>()
54+
{
55+
if (Server != null) throw new InvalidOperationException("Response metadata is not available for server contexts");
56+
throw new InvalidOperationException("The CaptureMetadata flag must be specified when creating the CallContext to enable response metadata");
57+
}
58+
}
59+
60+
[Flags]
61+
public enum CallContextFlags
62+
{
63+
None = 0,
64+
CaptureMetadata = 1,
65+
}
66+
}

0 commit comments

Comments
 (0)