Skip to content

Commit b188ee8

Browse files
committed
Regenerate protobuf with the right filename
For some reason we were renaming cloudevents.proto as ProtoSchema.proto, which breaks compatibility with anyone using the original file. Renaming the reflection class is a breaking change, so I've added an obsolete compatibility class to keep compatibility. Also updated to Google.Protobuf 3.22.0 (of the general protobuf 22.0 release; protobuf versioning is complex). Fixes #256 Signed-off-by: Jon Skeet <[email protected]>
1 parent 8999fce commit b188ee8

File tree

6 files changed

+58
-16
lines changed

6 files changed

+58
-16
lines changed

generate_protos.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# See LICENSE file in the project root for full license information.
55

66
set -e
7-
PROTOBUF_VERSION=3.19.3
7+
PROTOBUF_VERSION=22.0
88

99
# Generates the classes for the protobuf event format
1010

@@ -43,7 +43,7 @@ unzip -q protobuf.zip
4343
echo "- Downloading schema"
4444
# TODO: Use the 1.0.2 branch when it exists.
4545
mkdir cloudevents
46-
curl -sSL https://raw.githubusercontent.com/cloudevents/spec/main/cloudevents/formats/cloudevents.proto -o cloudevents/ProtoSchema.proto
46+
curl -sSL https://raw.githubusercontent.com/cloudevents/spec/main/cloudevents/formats/cloudevents.proto -o cloudevents/cloudevents.proto
4747

4848
cd ..
4949

@@ -53,7 +53,7 @@ $PROTOC \
5353
-I tmp/cloudevents \
5454
--csharp_out=src/CloudNative.CloudEvents.Protobuf \
5555
--csharp_opt=file_extension=.g.cs \
56-
tmp/cloudevents/ProtoSchema.proto
56+
tmp/cloudevents/cloudevents.proto
5757

5858
# Test protos
5959
$PROTOC \

src/CloudNative.CloudEvents.Protobuf/CloudNative.CloudEvents.Protobuf.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
55
<Description>Support for the Protobuf event format in for CloudNative.CloudEvents</Description>
66
<PackageTags>cncf;cloudnative;cloudevents;events;protobuf</PackageTags>
7-
<LangVersion>8.0</LangVersion>
7+
<LangVersion>10.0</LangVersion>
88
<Nullable>enable</Nullable>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Google.Protobuf" Version="3.19.3" />
12+
<PackageReference Include="Google.Protobuf" Version="3.22.0" />
1313

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

src/CloudNative.CloudEvents.Protobuf/ProtoSchema.g.cs renamed to src/CloudNative.CloudEvents.Protobuf/Cloudevents.g.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// <auto-generated>
22
// Generated by the protocol buffer compiler. DO NOT EDIT!
3-
// source: ProtoSchema.proto
3+
// source: cloudevents.proto
44
// </auto-generated>
5-
#pragma warning disable 1591, 0612, 3021
5+
#pragma warning disable 1591, 0612, 3021, 8981
66
#region Designer generated code
77

88
using pb = global::Google.Protobuf;
@@ -11,20 +11,20 @@
1111
using scg = global::System.Collections.Generic;
1212
namespace CloudNative.CloudEvents.V1 {
1313

14-
/// <summary>Holder for reflection information generated from ProtoSchema.proto</summary>
15-
public static partial class ProtoSchemaReflection {
14+
/// <summary>Holder for reflection information generated from cloudevents.proto</summary>
15+
public static partial class CloudeventsReflection {
1616

1717
#region Descriptor
18-
/// <summary>File descriptor for ProtoSchema.proto</summary>
18+
/// <summary>File descriptor for cloudevents.proto</summary>
1919
public static pbr::FileDescriptor Descriptor {
2020
get { return descriptor; }
2121
}
2222
private static pbr::FileDescriptor descriptor;
2323

24-
static ProtoSchemaReflection() {
24+
static CloudeventsReflection() {
2525
byte[] descriptorData = global::System.Convert.FromBase64String(
2626
string.Concat(
27-
"ChFQcm90b1NjaGVtYS5wcm90bxIRaW8uY2xvdWRldmVudHMudjEaGWdvb2ds",
27+
"ChFjbG91ZGV2ZW50cy5wcm90bxIRaW8uY2xvdWRldmVudHMudjEaGWdvb2ds",
2828
"ZS9wcm90b2J1Zi9hbnkucHJvdG8aH2dvb2dsZS9wcm90b2J1Zi90aW1lc3Rh",
2929
"bXAucHJvdG8isAQKCkNsb3VkRXZlbnQSCgoCaWQYASABKAkSDgoGc291cmNl",
3030
"GAIgASgJEhQKDHNwZWNfdmVyc2lvbhgDIAEoCRIMCgR0eXBlGAQgASgJEkEK",
@@ -69,7 +69,7 @@ public sealed partial class CloudEvent : pb::IMessage<CloudEvent>
6969
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
7070
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
7171
public static pbr::MessageDescriptor Descriptor {
72-
get { return global::CloudNative.CloudEvents.V1.ProtoSchemaReflection.Descriptor.MessageTypes[0]; }
72+
get { return global::CloudNative.CloudEvents.V1.CloudeventsReflection.Descriptor.MessageTypes[0]; }
7373
}
7474

7575
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -423,7 +423,7 @@ public void MergeFrom(CloudEvent other) {
423423
if (other.Type.Length != 0) {
424424
Type = other.Type;
425425
}
426-
attributes_.Add(other.attributes_);
426+
attributes_.MergeFrom(other.attributes_);
427427
switch (other.DataCase) {
428428
case DataOneofCase.BinaryData:
429429
BinaryData = other.BinaryData;
@@ -1044,7 +1044,7 @@ public sealed partial class CloudEventBatch : pb::IMessage<CloudEventBatch>
10441044
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
10451045
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
10461046
public static pbr::MessageDescriptor Descriptor {
1047-
get { return global::CloudNative.CloudEvents.V1.ProtoSchemaReflection.Descriptor.MessageTypes[1]; }
1047+
get { return global::CloudNative.CloudEvents.V1.CloudeventsReflection.Descriptor.MessageTypes[1]; }
10481048
}
10491049

10501050
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2023 Cloud Native Foundation.
2+
// Licensed under the Apache 2.0 license.
3+
// See LICENSE file in the project root for full license information.
4+
5+
using CloudNative.CloudEvents.V1;
6+
using Google.Protobuf.Reflection;
7+
using System;
8+
9+
namespace CloudNative.CloudEvents.V1;
10+
11+
/// <summary>
12+
/// Access to reflection information for the CloudEvents protobuf schema.
13+
/// </summary>
14+
/// <remarks>
15+
/// This class exists for backward-compatibility, when the protobuf messages
16+
/// were generated with a file named ProtoSchema.proto instead of cloudevents.proto.
17+
/// </remarks>
18+
[Obsolete($"Use {nameof(CloudeventsReflection)} instead.")]
19+
public class ProtoSchemaReflection
20+
{
21+
/// <summary>File descriptor for cloudevents.proto</summary>
22+
public static FileDescriptor Descriptor => CloudeventsReflection.Descriptor;
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2023 Cloud Native Foundation.
2+
// Licensed under the Apache 2.0 license.
3+
// See LICENSE file in the project root for full license information.
4+
5+
using CloudNative.CloudEvents.V1;
6+
using Xunit;
7+
8+
namespace CloudNative.CloudEvents.UnitTests.Protobuf;
9+
10+
public class CompatibilityTest
11+
{
12+
[Fact]
13+
public void ProtoSchemaReflectionEquivalence()
14+
{
15+
#pragma warning disable CS0618 // Type or member is obsolete
16+
Assert.Same(CloudeventsReflection.Descriptor, ProtoSchemaReflection.Descriptor);
17+
#pragma warning restore CS0618 // Type or member is obsolete
18+
}
19+
}

test/CloudNative.CloudEvents.UnitTests/Protobuf/TestMessages.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Generated by the protocol buffer compiler. DO NOT EDIT!
33
// source: test_messages.proto
44
// </auto-generated>
5-
#pragma warning disable 1591, 0612, 3021
5+
#pragma warning disable 1591, 0612, 3021, 8981
66
#region Designer generated code
77

88
using pb = global::Google.Protobuf;

0 commit comments

Comments
 (0)