Skip to content

Commit 0349eeb

Browse files
committed
feat: Add a Protobuf event formatter
Further features may be added later, e.g. convenience methods. Signed-off-by: Jon Skeet <[email protected]>
1 parent bf27ac4 commit 0349eeb

File tree

10 files changed

+2682
-1
lines changed

10 files changed

+2682
-1
lines changed

CloudEvents.sln

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudNative.CloudEvents.Avr
3333
EndProject
3434
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudNative.CloudEvents.NewtonsoftJson", "src\CloudNative.CloudEvents.NewtonsoftJson\CloudNative.CloudEvents.NewtonsoftJson.csproj", "{9DC17081-21D8-4123-8650-D97C2153DB8C}"
3535
EndProject
36-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudNative.CloudEvents.SystemTextJson", "src\CloudNative.CloudEvents.SystemTextJson\CloudNative.CloudEvents.SystemTextJson.csproj", "{FACB3EF2-F078-479A-A91C-719894CB66BF}"
36+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudNative.CloudEvents.SystemTextJson", "src\CloudNative.CloudEvents.SystemTextJson\CloudNative.CloudEvents.SystemTextJson.csproj", "{FACB3EF2-F078-479A-A91C-719894CB66BF}"
37+
EndProject
38+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudNative.CloudEvents.Protobuf", "src\CloudNative.CloudEvents.Protobuf\CloudNative.CloudEvents.Protobuf.csproj", "{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}"
3739
EndProject
3840
Global
3941
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -189,6 +191,18 @@ Global
189191
{FACB3EF2-F078-479A-A91C-719894CB66BF}.Release|x64.Build.0 = Release|Any CPU
190192
{FACB3EF2-F078-479A-A91C-719894CB66BF}.Release|x86.ActiveCfg = Release|Any CPU
191193
{FACB3EF2-F078-479A-A91C-719894CB66BF}.Release|x86.Build.0 = Release|Any CPU
194+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
195+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
196+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|x64.ActiveCfg = Debug|Any CPU
197+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|x64.Build.0 = Debug|Any CPU
198+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|x86.ActiveCfg = Debug|Any CPU
199+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|x86.Build.0 = Debug|Any CPU
200+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
201+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|Any CPU.Build.0 = Release|Any CPU
202+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|x64.ActiveCfg = Release|Any CPU
203+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|x64.Build.0 = Release|Any CPU
204+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|x86.ActiveCfg = Release|Any CPU
205+
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|x86.Build.0 = Release|Any CPU
192206
EndGlobalSection
193207
GlobalSection(SolutionProperties) = preSolution
194208
HideSolutionNode = FALSE

generate_protos.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
# Copyright 2021 Cloud Native Foundation.
3+
# Licensed under the Apache 2.0 license.
4+
# See LICENSE file in the project root for full license information.
5+
6+
set -e
7+
PROTOBUF_VERSION=3.19.3
8+
9+
# Generates the classes for the protobuf event format
10+
11+
case "$OSTYPE" in
12+
linux*)
13+
PROTOBUF_PLATFORM=linux-x86_64
14+
PROTOC=tmp/bin/protoc
15+
;;
16+
win* | msys* | cygwin*)
17+
PROTOBUF_PLATFORM=win64
18+
PROTOC=tmp/bin/protoc.exe
19+
;;
20+
darwin*)
21+
PROTOBUF_PLATFORM=osx-x86_64
22+
PROTOC=tmp/bin/protoc
23+
;;
24+
*)
25+
echo "Unknown OSTYPE: $OSTYPE"
26+
exit 1
27+
esac
28+
29+
# Clean up previous generation results
30+
rm -f src/CloudNative.CloudEvents.Protobuf/*.g.cs
31+
rm -f test/CloudNative.CloudEvents.UnitTests/Protobuf/*.g.cs
32+
33+
rm -rf tmp
34+
mkdir tmp
35+
cd tmp
36+
37+
echo "- Downloading protobuf@$PROTOBUF_VERSION"
38+
curl -sSL \
39+
https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-$PROTOBUF_PLATFORM.zip \
40+
--output protobuf.zip
41+
unzip -q protobuf.zip
42+
43+
echo "- Downloading schema"
44+
# TODO: Use the 1.0.2 branch when it exists.
45+
mkdir cloudevents
46+
curl -sSL https://raw.githubusercontent.com/cloudevents/spec/main/cloudevents/formats/cloudevents.proto -o cloudevents/ProtoSchema.proto
47+
48+
cd ..
49+
50+
# Schema proto
51+
$PROTOC \
52+
-I tmp/include \
53+
-I tmp/cloudevents \
54+
--csharp_out=src/CloudNative.CloudEvents.Protobuf \
55+
--csharp_opt=file_extension=.g.cs \
56+
tmp/cloudevents/ProtoSchema.proto
57+
58+
# Test protos
59+
$PROTOC \
60+
-I tmp/include \
61+
-I test/CloudNative.CloudEvents.UnitTests/Protobuf \
62+
--csharp_out=test/CloudNative.CloudEvents.UnitTests/Protobuf \
63+
--csharp_opt=file_extension=.g.cs \
64+
test/CloudNative.CloudEvents.UnitTests/Protobuf/*.proto
65+
66+
echo "Generated code."
67+
rm -rf tmp
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<Description>Support for the Protobuf event format in for CloudNative.CloudEvents</Description>
6+
<PackageTags>cncf;cloudnative;cloudevents;events;protobuf</PackageTags>
7+
<LangVersion>8.0</LangVersion>
8+
<Nullable>enable</Nullable>
9+
<Version>2.0.0-local.1</Version>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Google.Protobuf" Version="3.19.3" />
14+
15+
<!-- Be explicit about not including these files in the package. -->
16+
<None Include="README.md" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\CloudNative.CloudEvents\CloudNative.CloudEvents.csproj" />
21+
</ItemGroup>
22+
23+
</Project>

0 commit comments

Comments
 (0)