Skip to content

Commit

Permalink
feat: Add a Protobuf event formatter
Browse files Browse the repository at this point in the history
Further features may be added later, e.g. convenience methods.

Signed-off-by: Jon Skeet <jonskeet@google.com>
  • Loading branch information
jskeet committed Feb 1, 2022
1 parent bf27ac4 commit 0349eeb
Show file tree
Hide file tree
Showing 10 changed files with 2,682 additions and 1 deletion.
16 changes: 15 additions & 1 deletion CloudEvents.sln
Expand Up @@ -33,7 +33,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudNative.CloudEvents.Avr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudNative.CloudEvents.NewtonsoftJson", "src\CloudNative.CloudEvents.NewtonsoftJson\CloudNative.CloudEvents.NewtonsoftJson.csproj", "{9DC17081-21D8-4123-8650-D97C2153DB8C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudNative.CloudEvents.SystemTextJson", "src\CloudNative.CloudEvents.SystemTextJson\CloudNative.CloudEvents.SystemTextJson.csproj", "{FACB3EF2-F078-479A-A91C-719894CB66BF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudNative.CloudEvents.SystemTextJson", "src\CloudNative.CloudEvents.SystemTextJson\CloudNative.CloudEvents.SystemTextJson.csproj", "{FACB3EF2-F078-479A-A91C-719894CB66BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudNative.CloudEvents.Protobuf", "src\CloudNative.CloudEvents.Protobuf\CloudNative.CloudEvents.Protobuf.csproj", "{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -189,6 +191,18 @@ Global
{FACB3EF2-F078-479A-A91C-719894CB66BF}.Release|x64.Build.0 = Release|Any CPU
{FACB3EF2-F078-479A-A91C-719894CB66BF}.Release|x86.ActiveCfg = Release|Any CPU
{FACB3EF2-F078-479A-A91C-719894CB66BF}.Release|x86.Build.0 = Release|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|x64.ActiveCfg = Debug|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|x64.Build.0 = Debug|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|x86.ActiveCfg = Debug|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Debug|x86.Build.0 = Debug|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|Any CPU.Build.0 = Release|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|x64.ActiveCfg = Release|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|x64.Build.0 = Release|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|x86.ActiveCfg = Release|Any CPU
{9D82AC2B-0075-4161-AE0E-4A6629C9FF2A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
67 changes: 67 additions & 0 deletions generate_protos.sh
@@ -0,0 +1,67 @@
#!/bin/bash
# Copyright 2021 Cloud Native Foundation.
# Licensed under the Apache 2.0 license.
# See LICENSE file in the project root for full license information.

set -e
PROTOBUF_VERSION=3.19.3

# Generates the classes for the protobuf event format

case "$OSTYPE" in
linux*)
PROTOBUF_PLATFORM=linux-x86_64
PROTOC=tmp/bin/protoc
;;
win* | msys* | cygwin*)
PROTOBUF_PLATFORM=win64
PROTOC=tmp/bin/protoc.exe
;;
darwin*)
PROTOBUF_PLATFORM=osx-x86_64
PROTOC=tmp/bin/protoc
;;
*)
echo "Unknown OSTYPE: $OSTYPE"
exit 1
esac

# Clean up previous generation results
rm -f src/CloudNative.CloudEvents.Protobuf/*.g.cs
rm -f test/CloudNative.CloudEvents.UnitTests/Protobuf/*.g.cs

rm -rf tmp
mkdir tmp
cd tmp

echo "- Downloading protobuf@$PROTOBUF_VERSION"
curl -sSL \
https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protoc-$PROTOBUF_VERSION-$PROTOBUF_PLATFORM.zip \
--output protobuf.zip
unzip -q protobuf.zip

echo "- Downloading schema"
# TODO: Use the 1.0.2 branch when it exists.
mkdir cloudevents
curl -sSL https://raw.githubusercontent.com/cloudevents/spec/main/cloudevents/formats/cloudevents.proto -o cloudevents/ProtoSchema.proto

cd ..

# Schema proto
$PROTOC \
-I tmp/include \
-I tmp/cloudevents \
--csharp_out=src/CloudNative.CloudEvents.Protobuf \
--csharp_opt=file_extension=.g.cs \
tmp/cloudevents/ProtoSchema.proto

# Test protos
$PROTOC \
-I tmp/include \
-I test/CloudNative.CloudEvents.UnitTests/Protobuf \
--csharp_out=test/CloudNative.CloudEvents.UnitTests/Protobuf \
--csharp_opt=file_extension=.g.cs \
test/CloudNative.CloudEvents.UnitTests/Protobuf/*.proto

echo "Generated code."
rm -rf tmp
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<Description>Support for the Protobuf event format in for CloudNative.CloudEvents</Description>
<PackageTags>cncf;cloudnative;cloudevents;events;protobuf</PackageTags>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<Version>2.0.0-local.1</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.19.3" />

<!-- Be explicit about not including these files in the package. -->
<None Include="README.md" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CloudNative.CloudEvents\CloudNative.CloudEvents.csproj" />
</ItemGroup>

</Project>

0 comments on commit 0349eeb

Please sign in to comment.