├── .gitattributes
├── .gitignore
├── .nuget
├── NuGet.Config
├── NuGet.exe
└── NuGet.targets
├── LICENSE.txt
├── WebAPIContrib.Formatting.ProtoBuf.sln
├── build.bat
├── readme.md
├── src
└── WebApiContrib.Formatting.ProtoBuf
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ProtoBufFormatter.cs
│ ├── WebApiContrib.Formatting.ProtoBuf.csproj
│ ├── WebApiContrib.Formatting.ProtoBuf.nuspec
│ └── packages.config
├── test
└── WebApiContrib.Formatting.ProtoBuf.Test
│ ├── EvilItem.cs
│ ├── Item.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ProtoBufFormatterTest.cs
│ ├── WebApiContrib.Formatting.ProtoBuf.Test.csproj
│ └── packages.config
└── tools
├── nunit
└── SimpleSummary.xslt
└── psake
├── default.ps1
├── psake.bat
└── psake.psm1
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.doc diff=astextplain
2 | *.DOC diff=astextplain
3 | *.docx diff=astextplain
4 | *.DOCX diff=astextplain
5 | *.dot diff=astextplain
6 | *.DOT diff=astextplain
7 | *.pdf diff=astextplain
8 | *.PDF diff=astextplain
9 | *.rtf diff=astextplain
10 | *.RTF diff=astextplain
11 |
12 | *.jpg binary
13 | *.png binary
14 | *.gif binary
15 |
16 | *.cs text diff=csharp
17 | *.vb text
18 | *.c text
19 | *.cpp text
20 | *.cxx text
21 | *.h text
22 | *.hxx text
23 | *.py text
24 | *.rb text
25 | *.java text
26 | *.html text
27 | *.htm text
28 | *.css text
29 | *.scss text
30 | *.sass text
31 | *.less text
32 | *.js text
33 | *.lisp text
34 | *.clj text
35 | *.sql text
36 | *.php text
37 | *.lua text
38 | *.m text
39 | *.asm text
40 | *.erl text
41 | *.fs text
42 | *.fsx text
43 | *.hs text
44 |
45 | *.csproj text merge=union
46 | *.vbproj text merge=union
47 | *.fsproj text merge=union
48 | *.dbproj text merge=union
49 | *.sln text eol=crlf merge=union
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | #ignore thumbnails created by windows
3 | Thumbs.db
4 | #Ignore files build by Visual Studio
5 | *.obj
6 | *.exe
7 | *.pdb
8 | *.user
9 | *.aps
10 | *.pch
11 | *.vspscc
12 | *_i.c
13 | *_p.c
14 | *.ncb
15 | *.suo
16 | *.tlb
17 | *.tlh
18 | *.bak
19 | *.cache
20 | *.ilk
21 | *.log
22 | [Bb]in
23 | [Dd]ebug*/
24 | *.lib
25 | *.sbr
26 | obj/
27 | [Rr]elease*/
28 | _ReSharper*/
29 | [Tt]est[Rr]esult*
30 | build/
31 | deploy/
32 | docs/
33 | nuget/
34 | packages/
35 | *.nupkg
36 |
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WebApiContrib/WebApiContrib.Formatting.ProtoBuf/7f24399e55761f6778a228722e2b1b314559cea0/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/.nuget/NuGet.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildProjectDirectory)\..\
5 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
6 | $(NuGetToolsPath)\nuget.exe
7 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
8 | $([System.IO.Path]::Combine($(SolutionDir), "packages"))
9 | $(TargetDir.Trim('\\'))
10 |
11 |
12 | ""
13 |
14 |
15 | false
16 |
17 |
18 | false
19 |
20 |
21 | "$(NuGetExePath)" install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"
22 | "$(NuGetExePath)" pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols
23 |
24 |
25 |
26 | RestorePackages;
27 | $(BuildDependsOn);
28 |
29 |
30 |
31 |
32 | $(BuildDependsOn);
33 | BuildPackage;
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
46 |
47 |
48 |
49 |
51 |
52 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2012 Pedro Reys, Chris Missal, Headspring and other contributors
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/WebAPIContrib.Formatting.ProtoBuf.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4C93B8FC-96F9-47BA-9380-753847F03E1C}"
7 | ProjectSection(SolutionItems) = preProject
8 | .nuget\NuGet.exe = .nuget\NuGet.exe
9 | .nuget\NuGet.targets = .nuget\NuGet.targets
10 | EndProjectSection
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiContrib.Formatting.ProtoBuf", "src\WebApiContrib.Formatting.ProtoBuf\WebApiContrib.Formatting.ProtoBuf.csproj", "{2537E1C1-0212-4595-9F73-C0DEAE31BD62}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiContrib.Formatting.ProtoBuf.Test", "test\WebApiContrib.Formatting.ProtoBuf.Test\WebApiContrib.Formatting.ProtoBuf.Test.csproj", "{29D92544-1A02-4042-9C3B-BDF6DA0325F0}"
15 | EndProject
16 | Global
17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
18 | Debug|Any CPU = Debug|Any CPU
19 | Release|Any CPU = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
22 | {2537E1C1-0212-4595-9F73-C0DEAE31BD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {2537E1C1-0212-4595-9F73-C0DEAE31BD62}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {2537E1C1-0212-4595-9F73-C0DEAE31BD62}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {2537E1C1-0212-4595-9F73-C0DEAE31BD62}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {29D92544-1A02-4042-9C3B-BDF6DA0325F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {29D92544-1A02-4042-9C3B-BDF6DA0325F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {29D92544-1A02-4042-9C3B-BDF6DA0325F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {29D92544-1A02-4042-9C3B-BDF6DA0325F0}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/build.bat:
--------------------------------------------------------------------------------
1 | echo off
2 | .\tools\psake\psake.bat %*
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | WebAPIContrib
2 | =============
3 |
4 | Community Contributions for ASP.NET Web API
5 |
6 | http://webapicontrib.github.com/
--------------------------------------------------------------------------------
/src/WebApiContrib.Formatting.ProtoBuf/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("WebApiContrib.Formatting.ProtoBuf")]
9 | [assembly: AssemblyDescription("Description")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("WebApiContrib.Formatting.ProtoBuf")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("d4d79666-983a-472d-b811-b0126601c3ca")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | [assembly: AssemblyVersion("0.9.5")]
33 | [assembly: AssemblyFileVersion("0.9.5")]
34 |
--------------------------------------------------------------------------------
/src/WebApiContrib.Formatting.ProtoBuf/ProtoBufFormatter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Net;
5 | using System.Net.Http;
6 | using System.Net.Http.Formatting;
7 | using System.Net.Http.Headers;
8 | using System.Reflection;
9 | using System.Threading.Tasks;
10 | using ProtoBuf;
11 | using ProtoBuf.Meta;
12 |
13 | namespace WebApiContrib.Formatting
14 | {
15 | public class ProtoBufFormatter : MediaTypeFormatter
16 | {
17 | private static readonly MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/x-protobuf");
18 | private static Lazy model = new Lazy(CreateTypeModel);
19 |
20 | public static RuntimeTypeModel Model
21 | {
22 | get { return model.Value; }
23 | }
24 |
25 | public ProtoBufFormatter()
26 | {
27 | SupportedMediaTypes.Add(mediaType);
28 | }
29 |
30 | public static MediaTypeHeaderValue DefaultMediaType
31 | {
32 | get { return mediaType; }
33 | }
34 |
35 | public override bool CanReadType(Type type)
36 | {
37 | return CanReadTypeCore(type);
38 | }
39 |
40 | public override bool CanWriteType(Type type)
41 | {
42 | return CanReadTypeCore(type);
43 | }
44 |
45 | public override Task