diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2f0e379 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "examples/transcoding/best-practice/bp-api/third_party/protovalidate"] + path = examples/transcoding/best-practice/bp-api/third_party/protovalidate + url = https://github.com/bufbuild/protovalidate +[submodule "examples/transcoding/best-practice/bp-api/third_party/googleapis"] + path = examples/transcoding/best-practice/bp-api/third_party/googleapis + url = https://github.com/googleapis/googleapis diff --git a/build.gradle b/build.gradle index 30825eb..dee4c79 100644 --- a/build.gradle +++ b/build.gradle @@ -77,7 +77,7 @@ allprojects { endWithNewline() palantirJavaFormat() - targetExclude "build/generated/**" + targetExclude "**/generated/**" custom("Refuse wildcard imports", { if (it =~ /\nimport .*\*;/) { diff --git a/examples/transcoding/best-practice/bp-api/README.md b/examples/transcoding/best-practice/bp-api/README.md new file mode 100644 index 0000000..219fdea --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/README.md @@ -0,0 +1,32 @@ +## Project Configuration + +Using [buf](https://buf.build/) to manage proto files. + +[protoc-gen-openapi](https://github.com/google/gnostic/blob/main/cmd/protoc-gen-openapi/README.md) is not in the [Buf Schema Registry](https://buf.build/plugins), +so it can't use it directly with buf [remote plugin](https://buf.build/docs/generate/overview#generating-with-remote-plugins). + +Refer to [issues#821](https://github.com/bufbuild/plugins/issues/821). + +To use `protoc-gen-openapi` with buf, you can use the following steps: + +1. Install `protoc-gen-openapi` + + ```bash + go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest + ``` + +2. Use as local plugin in buf.gen.yaml + + ```yaml + plugins: + - local: protoc-gen-openapi + out: gen/openapi + ``` + + Make sure $GOPATH/bin is in your PATH: `export PATH="PATH:$(go env GOPATH)/bin"` + +## Generate Code + +```bash +cd examples/transcoding/best-practice/bp-api && buf generate +``` \ No newline at end of file diff --git a/examples/transcoding/best-practice/bp-api/api/user/v1/user.proto b/examples/transcoding/best-practice/bp-api/api/user/v1/user.proto new file mode 100644 index 0000000..bd51275 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/api/user/v1/user.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; + +package user.v1; + +import "google/api/annotations.proto"; +import "buf/validate/validate.proto"; + +option java_multiple_files = true; +option go_package = "github.com/your/repo/user/v1;user_v1"; + +message User { + int64 id = 1; + string name = 2; +} + +message GetUserRequest { + int64 id = 1 [(buf.validate.field).int64 = { + gte: 0 + }]; +} + +message GetUserResponse { + User user = 1; +} + +message DeleteUserRequest { + int64 id = 1 [(buf.validate.field).int64 = { + gte: 0 + }]; +} + +message DeleteUserResponse { + +} + +service UserService { + // Get a user by ID. + rpc GetUser(GetUserRequest) returns (GetUserResponse) { + option (google.api.http) = { + get: "/v1/users/{id}" + }; + } + + // Delete a user by ID. + rpc DeleteUser(DeleteUserRequest) returns (DeleteUserResponse) { + option (google.api.http) = { + delete: "/v1/users/{id}" + }; + } +} diff --git a/examples/transcoding/best-practice/bp-api/buf.gen.yaml b/examples/transcoding/best-practice/bp-api/buf.gen.yaml new file mode 100644 index 0000000..64c22d9 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/buf.gen.yaml @@ -0,0 +1,16 @@ +version: v2 +plugins: + # Java + - remote: buf.build/grpc/java:v1.64.0 + out: generated/java + - remote: buf.build/protocolbuffers/java:v25.1 + out: generated/java + + # OpenAPI + - local: protoc-gen-openapi + out: generated/openapi + opt: + - fq_schema_naming=true + - enum_type=string + + # Other languages ... diff --git a/examples/transcoding/best-practice/bp-api/buf.lock b/examples/transcoding/best-practice/bp-api/buf.lock new file mode 100644 index 0000000..335020d --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/buf.lock @@ -0,0 +1,9 @@ +# Generated by buf. DO NOT EDIT. +version: v2 +deps: + - name: buf.build/bufbuild/protovalidate + commit: 46a4cf4ba1094a34bcd89a6c67163b4b + digest: b5:2076a950fdf4a8047064d55fd1d20ef21e6d745bf56e3edf557071abd4488ed48c9466d60831d8a03489dc1fcc8ceaa073d197411b59ecd873e28b1328034e0b + - name: buf.build/googleapis/googleapis + commit: f0e53af8f2fc4556b94f482688b57223 + digest: b5:24e758f963ee1bb3b5218eb452e0bdfb7a5449d9a77d174b8284b6368ccc1884213689381cdcd79e4231796c281c128ac1ae50825237b1774deb542bdc704b32 diff --git a/examples/transcoding/best-practice/bp-api/buf.yaml b/examples/transcoding/best-practice/bp-api/buf.yaml new file mode 100644 index 0000000..cd77bed --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/buf.yaml @@ -0,0 +1,11 @@ +# https://buf.build/docs/configuration/v2/buf-yaml + +version: v2 +modules: + - path: api +deps: + - buf.build/googleapis/googleapis + - buf.build/bufbuild/protovalidate +lint: + use: + - DEFAULT \ No newline at end of file diff --git a/examples/transcoding/best-practice/bp-api/build.gradle b/examples/transcoding/best-practice/bp-api/build.gradle new file mode 100644 index 0000000..483245c --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/build.gradle @@ -0,0 +1,12 @@ +dependencies { + api("io.grpc:grpc-protobuf") + api(project(":grpc-starters:grpc-starter-protovalidate")) +} + +sourceSets { + main { + java { + srcDirs "generated/java" + } + } +} diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserRequest.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserRequest.java new file mode 100644 index 0000000..4b87644 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserRequest.java @@ -0,0 +1,473 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +/** + * Protobuf type {@code user.v1.DeleteUserRequest} + */ +public final class DeleteUserRequest extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:user.v1.DeleteUserRequest) + DeleteUserRequestOrBuilder { +private static final long serialVersionUID = 0L; + // Use DeleteUserRequest.newBuilder() to construct. + private DeleteUserRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private DeleteUserRequest() { + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new DeleteUserRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.DeleteUserRequest.class, user.v1.DeleteUserRequest.Builder.class); + } + + public static final int ID_FIELD_NUMBER = 1; + private long id_ = 0L; + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @return The id. + */ + @java.lang.Override + public long getId() { + return id_; + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (id_ != 0L) { + output.writeInt64(1, id_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (id_ != 0L) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(1, id_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof user.v1.DeleteUserRequest)) { + return super.equals(obj); + } + user.v1.DeleteUserRequest other = (user.v1.DeleteUserRequest) obj; + + if (getId() + != other.getId()) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + ID_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getId()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static user.v1.DeleteUserRequest parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.DeleteUserRequest parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.DeleteUserRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.DeleteUserRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.DeleteUserRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.DeleteUserRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.DeleteUserRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.DeleteUserRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static user.v1.DeleteUserRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + + public static user.v1.DeleteUserRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static user.v1.DeleteUserRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.DeleteUserRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(user.v1.DeleteUserRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code user.v1.DeleteUserRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:user.v1.DeleteUserRequest) + user.v1.DeleteUserRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.DeleteUserRequest.class, user.v1.DeleteUserRequest.Builder.class); + } + + // Construct using user.v1.DeleteUserRequest.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + id_ = 0L; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserRequest_descriptor; + } + + @java.lang.Override + public user.v1.DeleteUserRequest getDefaultInstanceForType() { + return user.v1.DeleteUserRequest.getDefaultInstance(); + } + + @java.lang.Override + public user.v1.DeleteUserRequest build() { + user.v1.DeleteUserRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public user.v1.DeleteUserRequest buildPartial() { + user.v1.DeleteUserRequest result = new user.v1.DeleteUserRequest(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(user.v1.DeleteUserRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.id_ = id_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof user.v1.DeleteUserRequest) { + return mergeFrom((user.v1.DeleteUserRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(user.v1.DeleteUserRequest other) { + if (other == user.v1.DeleteUserRequest.getDefaultInstance()) return this; + if (other.getId() != 0L) { + setId(other.getId()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: { + id_ = input.readInt64(); + bitField0_ |= 0x00000001; + break; + } // case 8 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + private int bitField0_; + + private long id_ ; + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @return The id. + */ + @java.lang.Override + public long getId() { + return id_; + } + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @param value The id to set. + * @return This builder for chaining. + */ + public Builder setId(long value) { + + id_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @return This builder for chaining. + */ + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000001); + id_ = 0L; + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:user.v1.DeleteUserRequest) + } + + // @@protoc_insertion_point(class_scope:user.v1.DeleteUserRequest) + private static final user.v1.DeleteUserRequest DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new user.v1.DeleteUserRequest(); + } + + public static user.v1.DeleteUserRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public DeleteUserRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public user.v1.DeleteUserRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserRequestOrBuilder.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserRequestOrBuilder.java new file mode 100644 index 0000000..32e39b1 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserRequestOrBuilder.java @@ -0,0 +1,16 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +public interface DeleteUserRequestOrBuilder extends + // @@protoc_insertion_point(interface_extends:user.v1.DeleteUserRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @return The id. + */ + long getId(); +} diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserResponse.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserResponse.java new file mode 100644 index 0000000..21f8ff1 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserResponse.java @@ -0,0 +1,399 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +/** + * Protobuf type {@code user.v1.DeleteUserResponse} + */ +public final class DeleteUserResponse extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:user.v1.DeleteUserResponse) + DeleteUserResponseOrBuilder { +private static final long serialVersionUID = 0L; + // Use DeleteUserResponse.newBuilder() to construct. + private DeleteUserResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private DeleteUserResponse() { + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new DeleteUserResponse(); + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.DeleteUserResponse.class, user.v1.DeleteUserResponse.Builder.class); + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof user.v1.DeleteUserResponse)) { + return super.equals(obj); + } + user.v1.DeleteUserResponse other = (user.v1.DeleteUserResponse) obj; + + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static user.v1.DeleteUserResponse parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.DeleteUserResponse parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.DeleteUserResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.DeleteUserResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.DeleteUserResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.DeleteUserResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.DeleteUserResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.DeleteUserResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static user.v1.DeleteUserResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + + public static user.v1.DeleteUserResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static user.v1.DeleteUserResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.DeleteUserResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(user.v1.DeleteUserResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code user.v1.DeleteUserResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:user.v1.DeleteUserResponse) + user.v1.DeleteUserResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.DeleteUserResponse.class, user.v1.DeleteUserResponse.Builder.class); + } + + // Construct using user.v1.DeleteUserResponse.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return user.v1.UserOuterClass.internal_static_user_v1_DeleteUserResponse_descriptor; + } + + @java.lang.Override + public user.v1.DeleteUserResponse getDefaultInstanceForType() { + return user.v1.DeleteUserResponse.getDefaultInstance(); + } + + @java.lang.Override + public user.v1.DeleteUserResponse build() { + user.v1.DeleteUserResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public user.v1.DeleteUserResponse buildPartial() { + user.v1.DeleteUserResponse result = new user.v1.DeleteUserResponse(this); + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof user.v1.DeleteUserResponse) { + return mergeFrom((user.v1.DeleteUserResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(user.v1.DeleteUserResponse other) { + if (other == user.v1.DeleteUserResponse.getDefaultInstance()) return this; + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:user.v1.DeleteUserResponse) + } + + // @@protoc_insertion_point(class_scope:user.v1.DeleteUserResponse) + private static final user.v1.DeleteUserResponse DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new user.v1.DeleteUserResponse(); + } + + public static user.v1.DeleteUserResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public DeleteUserResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public user.v1.DeleteUserResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserResponseOrBuilder.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserResponseOrBuilder.java new file mode 100644 index 0000000..f4a6744 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/DeleteUserResponseOrBuilder.java @@ -0,0 +1,10 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +public interface DeleteUserResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:user.v1.DeleteUserResponse) + com.google.protobuf.MessageOrBuilder { +} diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserRequest.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserRequest.java new file mode 100644 index 0000000..e771652 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserRequest.java @@ -0,0 +1,473 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +/** + * Protobuf type {@code user.v1.GetUserRequest} + */ +public final class GetUserRequest extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:user.v1.GetUserRequest) + GetUserRequestOrBuilder { +private static final long serialVersionUID = 0L; + // Use GetUserRequest.newBuilder() to construct. + private GetUserRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private GetUserRequest() { + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new GetUserRequest(); + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.GetUserRequest.class, user.v1.GetUserRequest.Builder.class); + } + + public static final int ID_FIELD_NUMBER = 1; + private long id_ = 0L; + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @return The id. + */ + @java.lang.Override + public long getId() { + return id_; + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (id_ != 0L) { + output.writeInt64(1, id_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (id_ != 0L) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(1, id_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof user.v1.GetUserRequest)) { + return super.equals(obj); + } + user.v1.GetUserRequest other = (user.v1.GetUserRequest) obj; + + if (getId() + != other.getId()) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + ID_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getId()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static user.v1.GetUserRequest parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.GetUserRequest parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.GetUserRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.GetUserRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.GetUserRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.GetUserRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.GetUserRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.GetUserRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static user.v1.GetUserRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + + public static user.v1.GetUserRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static user.v1.GetUserRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.GetUserRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(user.v1.GetUserRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code user.v1.GetUserRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:user.v1.GetUserRequest) + user.v1.GetUserRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.GetUserRequest.class, user.v1.GetUserRequest.Builder.class); + } + + // Construct using user.v1.GetUserRequest.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + id_ = 0L; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserRequest_descriptor; + } + + @java.lang.Override + public user.v1.GetUserRequest getDefaultInstanceForType() { + return user.v1.GetUserRequest.getDefaultInstance(); + } + + @java.lang.Override + public user.v1.GetUserRequest build() { + user.v1.GetUserRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public user.v1.GetUserRequest buildPartial() { + user.v1.GetUserRequest result = new user.v1.GetUserRequest(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(user.v1.GetUserRequest result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.id_ = id_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof user.v1.GetUserRequest) { + return mergeFrom((user.v1.GetUserRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(user.v1.GetUserRequest other) { + if (other == user.v1.GetUserRequest.getDefaultInstance()) return this; + if (other.getId() != 0L) { + setId(other.getId()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: { + id_ = input.readInt64(); + bitField0_ |= 0x00000001; + break; + } // case 8 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + private int bitField0_; + + private long id_ ; + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @return The id. + */ + @java.lang.Override + public long getId() { + return id_; + } + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @param value The id to set. + * @return This builder for chaining. + */ + public Builder setId(long value) { + + id_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @return This builder for chaining. + */ + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000001); + id_ = 0L; + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:user.v1.GetUserRequest) + } + + // @@protoc_insertion_point(class_scope:user.v1.GetUserRequest) + private static final user.v1.GetUserRequest DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new user.v1.GetUserRequest(); + } + + public static user.v1.GetUserRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public GetUserRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public user.v1.GetUserRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserRequestOrBuilder.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserRequestOrBuilder.java new file mode 100644 index 0000000..af928a3 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserRequestOrBuilder.java @@ -0,0 +1,16 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +public interface GetUserRequestOrBuilder extends + // @@protoc_insertion_point(interface_extends:user.v1.GetUserRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * int64 id = 1 [json_name = "id", (.buf.validate.field) = { ... } + * @return The id. + */ + long getId(); +} diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserResponse.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserResponse.java new file mode 100644 index 0000000..68f9cab --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserResponse.java @@ -0,0 +1,599 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +/** + * Protobuf type {@code user.v1.GetUserResponse} + */ +public final class GetUserResponse extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:user.v1.GetUserResponse) + GetUserResponseOrBuilder { +private static final long serialVersionUID = 0L; + // Use GetUserResponse.newBuilder() to construct. + private GetUserResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private GetUserResponse() { + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new GetUserResponse(); + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.GetUserResponse.class, user.v1.GetUserResponse.Builder.class); + } + + private int bitField0_; + public static final int USER_FIELD_NUMBER = 1; + private user.v1.User user_; + /** + * .user.v1.User user = 1 [json_name = "user"]; + * @return Whether the user field is set. + */ + @java.lang.Override + public boolean hasUser() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + * @return The user. + */ + @java.lang.Override + public user.v1.User getUser() { + return user_ == null ? user.v1.User.getDefaultInstance() : user_; + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + @java.lang.Override + public user.v1.UserOrBuilder getUserOrBuilder() { + return user_ == null ? user.v1.User.getDefaultInstance() : user_; + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (((bitField0_ & 0x00000001) != 0)) { + output.writeMessage(1, getUser()); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(1, getUser()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof user.v1.GetUserResponse)) { + return super.equals(obj); + } + user.v1.GetUserResponse other = (user.v1.GetUserResponse) obj; + + if (hasUser() != other.hasUser()) return false; + if (hasUser()) { + if (!getUser() + .equals(other.getUser())) return false; + } + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasUser()) { + hash = (37 * hash) + USER_FIELD_NUMBER; + hash = (53 * hash) + getUser().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static user.v1.GetUserResponse parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.GetUserResponse parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.GetUserResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.GetUserResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.GetUserResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.GetUserResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.GetUserResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.GetUserResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static user.v1.GetUserResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + + public static user.v1.GetUserResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static user.v1.GetUserResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.GetUserResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(user.v1.GetUserResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code user.v1.GetUserResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:user.v1.GetUserResponse) + user.v1.GetUserResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.GetUserResponse.class, user.v1.GetUserResponse.Builder.class); + } + + // Construct using user.v1.GetUserResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + getUserFieldBuilder(); + } + } + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + user_ = null; + if (userBuilder_ != null) { + userBuilder_.dispose(); + userBuilder_ = null; + } + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return user.v1.UserOuterClass.internal_static_user_v1_GetUserResponse_descriptor; + } + + @java.lang.Override + public user.v1.GetUserResponse getDefaultInstanceForType() { + return user.v1.GetUserResponse.getDefaultInstance(); + } + + @java.lang.Override + public user.v1.GetUserResponse build() { + user.v1.GetUserResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public user.v1.GetUserResponse buildPartial() { + user.v1.GetUserResponse result = new user.v1.GetUserResponse(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(user.v1.GetUserResponse result) { + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.user_ = userBuilder_ == null + ? user_ + : userBuilder_.build(); + to_bitField0_ |= 0x00000001; + } + result.bitField0_ |= to_bitField0_; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof user.v1.GetUserResponse) { + return mergeFrom((user.v1.GetUserResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(user.v1.GetUserResponse other) { + if (other == user.v1.GetUserResponse.getDefaultInstance()) return this; + if (other.hasUser()) { + mergeUser(other.getUser()); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + input.readMessage( + getUserFieldBuilder().getBuilder(), + extensionRegistry); + bitField0_ |= 0x00000001; + break; + } // case 10 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + private int bitField0_; + + private user.v1.User user_; + private com.google.protobuf.SingleFieldBuilderV3< + user.v1.User, user.v1.User.Builder, user.v1.UserOrBuilder> userBuilder_; + /** + * .user.v1.User user = 1 [json_name = "user"]; + * @return Whether the user field is set. + */ + public boolean hasUser() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + * @return The user. + */ + public user.v1.User getUser() { + if (userBuilder_ == null) { + return user_ == null ? user.v1.User.getDefaultInstance() : user_; + } else { + return userBuilder_.getMessage(); + } + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + public Builder setUser(user.v1.User value) { + if (userBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + user_ = value; + } else { + userBuilder_.setMessage(value); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + public Builder setUser( + user.v1.User.Builder builderForValue) { + if (userBuilder_ == null) { + user_ = builderForValue.build(); + } else { + userBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + public Builder mergeUser(user.v1.User value) { + if (userBuilder_ == null) { + if (((bitField0_ & 0x00000001) != 0) && + user_ != null && + user_ != user.v1.User.getDefaultInstance()) { + getUserBuilder().mergeFrom(value); + } else { + user_ = value; + } + } else { + userBuilder_.mergeFrom(value); + } + if (user_ != null) { + bitField0_ |= 0x00000001; + onChanged(); + } + return this; + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + public Builder clearUser() { + bitField0_ = (bitField0_ & ~0x00000001); + user_ = null; + if (userBuilder_ != null) { + userBuilder_.dispose(); + userBuilder_ = null; + } + onChanged(); + return this; + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + public user.v1.User.Builder getUserBuilder() { + bitField0_ |= 0x00000001; + onChanged(); + return getUserFieldBuilder().getBuilder(); + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + public user.v1.UserOrBuilder getUserOrBuilder() { + if (userBuilder_ != null) { + return userBuilder_.getMessageOrBuilder(); + } else { + return user_ == null ? + user.v1.User.getDefaultInstance() : user_; + } + } + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + private com.google.protobuf.SingleFieldBuilderV3< + user.v1.User, user.v1.User.Builder, user.v1.UserOrBuilder> + getUserFieldBuilder() { + if (userBuilder_ == null) { + userBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< + user.v1.User, user.v1.User.Builder, user.v1.UserOrBuilder>( + getUser(), + getParentForChildren(), + isClean()); + user_ = null; + } + return userBuilder_; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:user.v1.GetUserResponse) + } + + // @@protoc_insertion_point(class_scope:user.v1.GetUserResponse) + private static final user.v1.GetUserResponse DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new user.v1.GetUserResponse(); + } + + public static user.v1.GetUserResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public GetUserResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public user.v1.GetUserResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserResponseOrBuilder.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserResponseOrBuilder.java new file mode 100644 index 0000000..c67eca0 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/GetUserResponseOrBuilder.java @@ -0,0 +1,25 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +public interface GetUserResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:user.v1.GetUserResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * .user.v1.User user = 1 [json_name = "user"]; + * @return Whether the user field is set. + */ + boolean hasUser(); + /** + * .user.v1.User user = 1 [json_name = "user"]; + * @return The user. + */ + user.v1.User getUser(); + /** + * .user.v1.User user = 1 [json_name = "user"]; + */ + user.v1.UserOrBuilder getUserOrBuilder(); +} diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/User.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/User.java new file mode 100644 index 0000000..93b374a --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/User.java @@ -0,0 +1,609 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +/** + * Protobuf type {@code user.v1.User} + */ +public final class User extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:user.v1.User) + UserOrBuilder { +private static final long serialVersionUID = 0L; + // Use User.newBuilder() to construct. + private User(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private User() { + name_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new User(); + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_User_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_User_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.User.class, user.v1.User.Builder.class); + } + + public static final int ID_FIELD_NUMBER = 1; + private long id_ = 0L; + /** + * int64 id = 1 [json_name = "id"]; + * @return The id. + */ + @java.lang.Override + public long getId() { + return id_; + } + + public static final int NAME_FIELD_NUMBER = 2; + @SuppressWarnings("serial") + private volatile java.lang.Object name_ = ""; + /** + * string name = 2 [json_name = "name"]; + * @return The name. + */ + @java.lang.Override + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } + } + /** + * string name = 2 [json_name = "name"]; + * @return The bytes for name. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (id_ != 0L) { + output.writeInt64(1, id_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, name_); + } + getUnknownFields().writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (id_ != 0L) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(1, id_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, name_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof user.v1.User)) { + return super.equals(obj); + } + user.v1.User other = (user.v1.User) obj; + + if (getId() + != other.getId()) return false; + if (!getName() + .equals(other.getName())) return false; + if (!getUnknownFields().equals(other.getUnknownFields())) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + ID_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getId()); + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static user.v1.User parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.User parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.User parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.User parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.User parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static user.v1.User parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static user.v1.User parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.User parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public static user.v1.User parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + + public static user.v1.User parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static user.v1.User parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static user.v1.User parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(user.v1.User prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code user.v1.User} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:user.v1.User) + user.v1.UserOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return user.v1.UserOuterClass.internal_static_user_v1_User_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return user.v1.UserOuterClass.internal_static_user_v1_User_fieldAccessorTable + .ensureFieldAccessorsInitialized( + user.v1.User.class, user.v1.User.Builder.class); + } + + // Construct using user.v1.User.newBuilder() + private Builder() { + + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + + } + @java.lang.Override + public Builder clear() { + super.clear(); + bitField0_ = 0; + id_ = 0L; + name_ = ""; + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return user.v1.UserOuterClass.internal_static_user_v1_User_descriptor; + } + + @java.lang.Override + public user.v1.User getDefaultInstanceForType() { + return user.v1.User.getDefaultInstance(); + } + + @java.lang.Override + public user.v1.User build() { + user.v1.User result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public user.v1.User buildPartial() { + user.v1.User result = new user.v1.User(this); + if (bitField0_ != 0) { buildPartial0(result); } + onBuilt(); + return result; + } + + private void buildPartial0(user.v1.User result) { + int from_bitField0_ = bitField0_; + if (((from_bitField0_ & 0x00000001) != 0)) { + result.id_ = id_; + } + if (((from_bitField0_ & 0x00000002) != 0)) { + result.name_ = name_; + } + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof user.v1.User) { + return mergeFrom((user.v1.User)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(user.v1.User other) { + if (other == user.v1.User.getDefaultInstance()) return this; + if (other.getId() != 0L) { + setId(other.getId()); + } + if (!other.getName().isEmpty()) { + name_ = other.name_; + bitField0_ |= 0x00000002; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: { + id_ = input.readInt64(); + bitField0_ |= 0x00000001; + break; + } // case 8 + case 18: { + name_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000002; + break; + } // case 18 + default: { + if (!super.parseUnknownField(input, extensionRegistry, tag)) { + done = true; // was an endgroup tag + } + break; + } // default: + } // switch (tag) + } // while (!done) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.unwrapIOException(); + } finally { + onChanged(); + } // finally + return this; + } + private int bitField0_; + + private long id_ ; + /** + * int64 id = 1 [json_name = "id"]; + * @return The id. + */ + @java.lang.Override + public long getId() { + return id_; + } + /** + * int64 id = 1 [json_name = "id"]; + * @param value The id to set. + * @return This builder for chaining. + */ + public Builder setId(long value) { + + id_ = value; + bitField0_ |= 0x00000001; + onChanged(); + return this; + } + /** + * int64 id = 1 [json_name = "id"]; + * @return This builder for chaining. + */ + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000001); + id_ = 0L; + onChanged(); + return this; + } + + private java.lang.Object name_ = ""; + /** + * string name = 2 [json_name = "name"]; + * @return The name. + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string name = 2 [json_name = "name"]; + * @return The bytes for name. + */ + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string name = 2 [json_name = "name"]; + * @param value The name to set. + * @return This builder for chaining. + */ + public Builder setName( + java.lang.String value) { + if (value == null) { throw new NullPointerException(); } + name_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + /** + * string name = 2 [json_name = "name"]; + * @return This builder for chaining. + */ + public Builder clearName() { + name_ = getDefaultInstance().getName(); + bitField0_ = (bitField0_ & ~0x00000002); + onChanged(); + return this; + } + /** + * string name = 2 [json_name = "name"]; + * @param value The bytes for name to set. + * @return This builder for chaining. + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { throw new NullPointerException(); } + checkByteStringIsUtf8(value); + name_ = value; + bitField0_ |= 0x00000002; + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:user.v1.User) + } + + // @@protoc_insertion_point(class_scope:user.v1.User) + private static final user.v1.User DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new user.v1.User(); + } + + public static user.v1.User getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public User parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + Builder builder = newBuilder(); + try { + builder.mergeFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(builder.buildPartial()); + } catch (com.google.protobuf.UninitializedMessageException e) { + throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException(e) + .setUnfinishedMessage(builder.buildPartial()); + } + return builder.buildPartial(); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public user.v1.User getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserOrBuilder.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserOrBuilder.java new file mode 100644 index 0000000..ecdedaf --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserOrBuilder.java @@ -0,0 +1,28 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +public interface UserOrBuilder extends + // @@protoc_insertion_point(interface_extends:user.v1.User) + com.google.protobuf.MessageOrBuilder { + + /** + * int64 id = 1 [json_name = "id"]; + * @return The id. + */ + long getId(); + + /** + * string name = 2 [json_name = "name"]; + * @return The name. + */ + java.lang.String getName(); + /** + * string name = 2 [json_name = "name"]; + * @return The bytes for name. + */ + com.google.protobuf.ByteString + getNameBytes(); +} diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserOuterClass.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserOuterClass.java new file mode 100644 index 0000000..9e5de7e --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserOuterClass.java @@ -0,0 +1,114 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: user/v1/user.proto + +// Protobuf Java Version: 3.25.1 +package user.v1; + +public final class UserOuterClass { + private UserOuterClass() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + static final com.google.protobuf.Descriptors.Descriptor + internal_static_user_v1_User_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_user_v1_User_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_user_v1_GetUserRequest_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_user_v1_GetUserRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_user_v1_GetUserResponse_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_user_v1_GetUserResponse_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_user_v1_DeleteUserRequest_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_user_v1_DeleteUserRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_user_v1_DeleteUserResponse_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_user_v1_DeleteUserResponse_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\022user/v1/user.proto\022\007user.v1\032\034google/ap" + + "i/annotations.proto\032\033buf/validate/valida" + + "te.proto\"*\n\004User\022\016\n\002id\030\001 \001(\003R\002id\022\022\n\004name" + + "\030\002 \001(\tR\004name\")\n\016GetUserRequest\022\027\n\002id\030\001 \001" + + "(\003B\007\272H\004\"\002(\000R\002id\"4\n\017GetUserResponse\022!\n\004us" + + "er\030\001 \001(\0132\r.user.v1.UserR\004user\",\n\021DeleteU" + + "serRequest\022\027\n\002id\030\001 \001(\003B\007\272H\004\"\002(\000R\002id\"\024\n\022D" + + "eleteUserResponse2\302\001\n\013UserService\022T\n\007Get" + + "User\022\027.user.v1.GetUserRequest\032\030.user.v1." + + "GetUserResponse\"\026\202\323\344\223\002\020\022\016/v1/users/{id}\022" + + "]\n\nDeleteUser\022\032.user.v1.DeleteUserReques" + + "t\032\033.user.v1.DeleteUserResponse\"\026\202\323\344\223\002\020*\016" + + "/v1/users/{id}B(P\001Z$github.com/your/repo" + + "/user/v1;user_v1b\006proto3" + }; + descriptor = com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + com.google.api.AnnotationsProto.getDescriptor(), + build.buf.validate.ValidateProto.getDescriptor(), + }); + internal_static_user_v1_User_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_user_v1_User_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_user_v1_User_descriptor, + new java.lang.String[] { "Id", "Name", }); + internal_static_user_v1_GetUserRequest_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_user_v1_GetUserRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_user_v1_GetUserRequest_descriptor, + new java.lang.String[] { "Id", }); + internal_static_user_v1_GetUserResponse_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_user_v1_GetUserResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_user_v1_GetUserResponse_descriptor, + new java.lang.String[] { "User", }); + internal_static_user_v1_DeleteUserRequest_descriptor = + getDescriptor().getMessageTypes().get(3); + internal_static_user_v1_DeleteUserRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_user_v1_DeleteUserRequest_descriptor, + new java.lang.String[] { "Id", }); + internal_static_user_v1_DeleteUserResponse_descriptor = + getDescriptor().getMessageTypes().get(4); + internal_static_user_v1_DeleteUserResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_user_v1_DeleteUserResponse_descriptor, + new java.lang.String[] { }); + com.google.protobuf.ExtensionRegistry registry = + com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(build.buf.validate.ValidateProto.field); + registry.add(com.google.api.AnnotationsProto.http); + com.google.protobuf.Descriptors.FileDescriptor + .internalUpdateFileDescriptor(descriptor, registry); + com.google.api.AnnotationsProto.getDescriptor(); + build.buf.validate.ValidateProto.getDescriptor(); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserServiceGrpc.java b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserServiceGrpc.java new file mode 100644 index 0000000..72ed925 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/java/user/v1/UserServiceGrpc.java @@ -0,0 +1,391 @@ +package user.v1; + +import static io.grpc.MethodDescriptor.generateFullMethodName; + +/** + */ +@javax.annotation.Generated( + value = "by gRPC proto compiler (version 1.64.0)", + comments = "Source: user/v1/user.proto") +@io.grpc.stub.annotations.GrpcGenerated +public final class UserServiceGrpc { + + private UserServiceGrpc() {} + + public static final java.lang.String SERVICE_NAME = "user.v1.UserService"; + + // Static method descriptors that strictly reflect the proto. + private static volatile io.grpc.MethodDescriptor getGetUserMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "GetUser", + requestType = user.v1.GetUserRequest.class, + responseType = user.v1.GetUserResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor getGetUserMethod() { + io.grpc.MethodDescriptor getGetUserMethod; + if ((getGetUserMethod = UserServiceGrpc.getGetUserMethod) == null) { + synchronized (UserServiceGrpc.class) { + if ((getGetUserMethod = UserServiceGrpc.getGetUserMethod) == null) { + UserServiceGrpc.getGetUserMethod = getGetUserMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "GetUser")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + user.v1.GetUserRequest.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + user.v1.GetUserResponse.getDefaultInstance())) + .setSchemaDescriptor(new UserServiceMethodDescriptorSupplier("GetUser")) + .build(); + } + } + } + return getGetUserMethod; + } + + private static volatile io.grpc.MethodDescriptor getDeleteUserMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "DeleteUser", + requestType = user.v1.DeleteUserRequest.class, + responseType = user.v1.DeleteUserResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor getDeleteUserMethod() { + io.grpc.MethodDescriptor getDeleteUserMethod; + if ((getDeleteUserMethod = UserServiceGrpc.getDeleteUserMethod) == null) { + synchronized (UserServiceGrpc.class) { + if ((getDeleteUserMethod = UserServiceGrpc.getDeleteUserMethod) == null) { + UserServiceGrpc.getDeleteUserMethod = getDeleteUserMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "DeleteUser")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + user.v1.DeleteUserRequest.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + user.v1.DeleteUserResponse.getDefaultInstance())) + .setSchemaDescriptor(new UserServiceMethodDescriptorSupplier("DeleteUser")) + .build(); + } + } + } + return getDeleteUserMethod; + } + + /** + * Creates a new async stub that supports all call types for the service + */ + public static UserServiceStub newStub(io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public UserServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new UserServiceStub(channel, callOptions); + } + }; + return UserServiceStub.newStub(factory, channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static UserServiceBlockingStub newBlockingStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public UserServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new UserServiceBlockingStub(channel, callOptions); + } + }; + return UserServiceBlockingStub.newStub(factory, channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary calls on the service + */ + public static UserServiceFutureStub newFutureStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public UserServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new UserServiceFutureStub(channel, callOptions); + } + }; + return UserServiceFutureStub.newStub(factory, channel); + } + + /** + */ + public interface AsyncService { + + /** + *
+     * Get a user by ID.
+     * 
+ */ + default void getUser(user.v1.GetUserRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getGetUserMethod(), responseObserver); + } + + /** + *
+     * Delete a user by ID.
+     * 
+ */ + default void deleteUser(user.v1.DeleteUserRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getDeleteUserMethod(), responseObserver); + } + } + + /** + * Base class for the server implementation of the service UserService. + */ + public static abstract class UserServiceImplBase + implements io.grpc.BindableService, AsyncService { + + @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { + return UserServiceGrpc.bindService(this); + } + } + + /** + * A stub to allow clients to do asynchronous rpc calls to service UserService. + */ + public static final class UserServiceStub + extends io.grpc.stub.AbstractAsyncStub { + private UserServiceStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected UserServiceStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new UserServiceStub(channel, callOptions); + } + + /** + *
+     * Get a user by ID.
+     * 
+ */ + public void getUser(user.v1.GetUserRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getGetUserMethod(), getCallOptions()), request, responseObserver); + } + + /** + *
+     * Delete a user by ID.
+     * 
+ */ + public void deleteUser(user.v1.DeleteUserRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getDeleteUserMethod(), getCallOptions()), request, responseObserver); + } + } + + /** + * A stub to allow clients to do synchronous rpc calls to service UserService. + */ + public static final class UserServiceBlockingStub + extends io.grpc.stub.AbstractBlockingStub { + private UserServiceBlockingStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected UserServiceBlockingStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new UserServiceBlockingStub(channel, callOptions); + } + + /** + *
+     * Get a user by ID.
+     * 
+ */ + public user.v1.GetUserResponse getUser(user.v1.GetUserRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getGetUserMethod(), getCallOptions(), request); + } + + /** + *
+     * Delete a user by ID.
+     * 
+ */ + public user.v1.DeleteUserResponse deleteUser(user.v1.DeleteUserRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getDeleteUserMethod(), getCallOptions(), request); + } + } + + /** + * A stub to allow clients to do ListenableFuture-style rpc calls to service UserService. + */ + public static final class UserServiceFutureStub + extends io.grpc.stub.AbstractFutureStub { + private UserServiceFutureStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected UserServiceFutureStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new UserServiceFutureStub(channel, callOptions); + } + + /** + *
+     * Get a user by ID.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture getUser( + user.v1.GetUserRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getGetUserMethod(), getCallOptions()), request); + } + + /** + *
+     * Delete a user by ID.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture deleteUser( + user.v1.DeleteUserRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getDeleteUserMethod(), getCallOptions()), request); + } + } + + private static final int METHODID_GET_USER = 0; + private static final int METHODID_DELETE_USER = 1; + + private static final class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final AsyncService serviceImpl; + private final int methodId; + + MethodHandlers(AsyncService serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_GET_USER: + serviceImpl.getUser((user.v1.GetUserRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + case METHODID_DELETE_USER: + serviceImpl.deleteUser((user.v1.DeleteUserRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + default: + throw new AssertionError(); + } + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + } + + public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + getGetUserMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + user.v1.GetUserRequest, + user.v1.GetUserResponse>( + service, METHODID_GET_USER))) + .addMethod( + getDeleteUserMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + user.v1.DeleteUserRequest, + user.v1.DeleteUserResponse>( + service, METHODID_DELETE_USER))) + .build(); + } + + private static abstract class UserServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { + UserServiceBaseDescriptorSupplier() {} + + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return user.v1.UserOuterClass.getDescriptor(); + } + + @java.lang.Override + public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { + return getFileDescriptor().findServiceByName("UserService"); + } + } + + private static final class UserServiceFileDescriptorSupplier + extends UserServiceBaseDescriptorSupplier { + UserServiceFileDescriptorSupplier() {} + } + + private static final class UserServiceMethodDescriptorSupplier + extends UserServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { + private final java.lang.String methodName; + + UserServiceMethodDescriptorSupplier(java.lang.String methodName) { + this.methodName = methodName; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { + return getServiceDescriptor().findMethodByName(methodName); + } + } + + private static volatile io.grpc.ServiceDescriptor serviceDescriptor; + + public static io.grpc.ServiceDescriptor getServiceDescriptor() { + io.grpc.ServiceDescriptor result = serviceDescriptor; + if (result == null) { + synchronized (UserServiceGrpc.class) { + result = serviceDescriptor; + if (result == null) { + serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) + .setSchemaDescriptor(new UserServiceFileDescriptorSupplier()) + .addMethod(getGetUserMethod()) + .addMethod(getDeleteUserMethod()) + .build(); + } + } + } + return result; + } +} diff --git a/examples/transcoding/best-practice/bp-api/generated/openapi/openapi.yaml b/examples/transcoding/best-practice/bp-api/generated/openapi/openapi.yaml new file mode 100644 index 0000000..4db9d5c --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/generated/openapi/openapi.yaml @@ -0,0 +1,100 @@ +# Generated with protoc-gen-openapi +# https://github.com/google/gnostic/tree/master/cmd/protoc-gen-openapi + +openapi: 3.0.3 +info: + title: UserService API + version: 0.0.1 +paths: + /v1/users/{id}: + get: + tags: + - UserService + description: Get a user by ID. + operationId: UserService_GetUser + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/user.v1.GetUserResponse' + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/google.rpc.Status' + delete: + tags: + - UserService + description: Delete a user by ID. + operationId: UserService_DeleteUser + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/user.v1.DeleteUserResponse' + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/google.rpc.Status' +components: + schemas: + google.protobuf.Any: + type: object + properties: + '@type': + type: string + description: The type of the serialized message. + additionalProperties: true + description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message. + google.rpc.Status: + type: object + properties: + code: + type: integer + description: The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. + format: int32 + message: + type: string + description: A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. + details: + type: array + items: + $ref: '#/components/schemas/google.protobuf.Any' + description: A list of messages that carry the error details. There is a common set of message types for APIs to use. + description: 'The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).' + user.v1.DeleteUserResponse: + type: object + properties: {} + user.v1.GetUserResponse: + type: object + properties: + user: + $ref: '#/components/schemas/user.v1.User' + user.v1.User: + type: object + properties: + id: + type: string + name: + type: string +tags: + - name: UserService diff --git a/examples/transcoding/best-practice/bp-api/third_party/googleapis b/examples/transcoding/best-practice/bp-api/third_party/googleapis new file mode 160000 index 0000000..9861d15 --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/third_party/googleapis @@ -0,0 +1 @@ +Subproject commit 9861d15d7d6e035445538958b1a5283260f7ebd3 diff --git a/examples/transcoding/best-practice/bp-api/third_party/protovalidate b/examples/transcoding/best-practice/bp-api/third_party/protovalidate new file mode 160000 index 0000000..919cc2f --- /dev/null +++ b/examples/transcoding/best-practice/bp-api/third_party/protovalidate @@ -0,0 +1 @@ +Subproject commit 919cc2f85a77a0e0128cc2f273416ac5df0d4a78 diff --git a/examples/transcoding/best-practice/bp-server/build.gradle b/examples/transcoding/best-practice/bp-server/build.gradle new file mode 100644 index 0000000..3d95c94 --- /dev/null +++ b/examples/transcoding/best-practice/bp-server/build.gradle @@ -0,0 +1,13 @@ +plugins { + id 'org.springframework.boot' +} + +dependencies { + implementation(project(":examples:transcoding:best-practice:bp-api")) + + implementation(project(":grpc-starters:grpc-server-boot-starter")) + implementation(project(":grpc-starters:grpc-starter-transcoding")) + implementation("org.springframework.boot:spring-boot-starter-web") + + testImplementation(project(":grpc-starters:grpc-starter-test")) +} diff --git a/examples/transcoding/best-practice/bp-server/src/main/java/grpcstarter/example/BestPracticeApp.java b/examples/transcoding/best-practice/bp-server/src/main/java/grpcstarter/example/BestPracticeApp.java new file mode 100644 index 0000000..6b58307 --- /dev/null +++ b/examples/transcoding/best-practice/bp-server/src/main/java/grpcstarter/example/BestPracticeApp.java @@ -0,0 +1,48 @@ +package grpcstarter.example; + +import io.grpc.stub.StreamObserver; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import user.v1.DeleteUserRequest; +import user.v1.DeleteUserResponse; +import user.v1.GetUserRequest; +import user.v1.GetUserResponse; +import user.v1.User; +import user.v1.UserServiceGrpc; + +@SpringBootApplication +public class BestPracticeApp { + + public static void main(String[] args) { + SpringApplication.run(BestPracticeApp.class, args); + } + + @Bean + UserServiceGrpc.UserServiceImplBase userServiceImpl() { + return new UserServiceGrpc.UserServiceImplBase() { + @Override + public void getUser(GetUserRequest request, StreamObserver responseObserver) { + if (request.getId() < 10) { + responseObserver.onNext(GetUserResponse.getDefaultInstance()); + responseObserver.onCompleted(); + return; + } + + responseObserver.onNext(GetUserResponse.newBuilder() + .setUser(User.newBuilder() + .setId(request.getId()) + .setName("user-" + request.getId()) + .build()) + .build()); + responseObserver.onCompleted(); + } + + @Override + public void deleteUser(DeleteUserRequest request, StreamObserver responseObserver) { + responseObserver.onNext(DeleteUserResponse.getDefaultInstance()); + responseObserver.onCompleted(); + } + }; + } +} diff --git a/settings.gradle b/settings.gradle index 32e6f29..2510ca0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -43,6 +43,8 @@ include(":examples:refresh") include(":examples:tls") include(":examples:tracing") include(":examples:validation") +include(":examples:transcoding:best-practice:bp-api") +include(":examples:transcoding:best-practice:bp-server") include(":examples:transcoding:webflux") include(":examples:transcoding:webmvc") diff --git a/website/docs/40-configuration-properties.md b/website/docs/40-configuration-properties.md index 65710a0..5ac1340 100644 --- a/website/docs/40-configuration-properties.md +++ b/website/docs/40-configuration-properties.md @@ -318,4 +318,4 @@ This page was generated by [spring-configuration-property-documenter](https://gi | enabled| java.lang.Boolean| Whether to enable validation, default is \{@code true}.| true| | | order| java.lang.Integer| Validating interceptor order, default is \{@code 0}.| 0| | -This is a generated file, generated at: **2024-06-22T00:54:07.601883** +This is a generated file, generated at: **2024-06-23T23:11:26.503617**