From f2628f4a66bd6d20897d4bc092a45d087bb1014c Mon Sep 17 00:00:00 2001 From: Yuuki <928196210@qq.com> Date: Tue, 9 Jul 2024 17:06:02 +0800 Subject: [PATCH 1/2] init project --- .gitignore | 34 + LICENSE | 202 ++++++ README.md | 2 +- generator/gen_dubbo.go | 136 ++++ generator/generator.go | 272 ++++++++ go.mod | 10 + go.sum | 6 + internal/version/version.go | 20 + main.go | 69 +++ proto/java8_time/java8_time.proto | 48 ++ proto/java_exception/java_exception.proto | 196 ++++++ proto/java_math/java_math.proto | 26 + proto/java_sql_time/java_sql_time.proto | 26 + proto/java_util/java_util.proto | 26 + .../unified_idl_extend.pb.go | 585 ++++++++++++++++++ .../unified_idl_extend.proto | 67 ++ util/strings.go | 38 ++ util/type.go | 128 ++++ 18 files changed, 1890 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 generator/gen_dubbo.go create mode 100644 generator/generator.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/version/version.go create mode 100644 main.go create mode 100644 proto/java8_time/java8_time.proto create mode 100644 proto/java_exception/java_exception.proto create mode 100644 proto/java_math/java_math.proto create mode 100644 proto/java_sql_time/java_sql_time.proto create mode 100644 proto/java_util/java_util.proto create mode 100644 proto/unified_idl_extend/unified_idl_extend.pb.go create mode 100644 proto/unified_idl_extend/unified_idl_extend.proto create mode 100644 util/strings.go create mode 100644 util/type.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2e43b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +*.jar +*.log + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out +coverage.txt + +*.idea +*.iml +target/ +classes + +# go mod, go test +.go-version +vendor/ +logs/ +.vscode/ +cache +log/ + +# vim stuff +*~ +.*.sw? +/license-header-checker-linux/ +/license-header-checker-linux.zip + +# macOS +.DS_Store diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 8917453..2a78368 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# protoc-gen-go-dubbo \ No newline at end of file +# [WIP] protoc-gen-go-dubbo diff --git a/generator/gen_dubbo.go b/generator/gen_dubbo.go new file mode 100644 index 0000000..d246f4a --- /dev/null +++ b/generator/gen_dubbo.go @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package generator + +import ( + "fmt" +) + +import ( + "github.com/pkg/errors" + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/proto" +) + +import ( + "github.com/dubbogo/protoc-gen-go-dubbo/proto/unified_idl_extend" + "github.com/dubbogo/protoc-gen-go-dubbo/util" +) + +var ( + ErrStreamMethod = errors.New("dubbo doesn't support stream method") + ErrMoreExtendArgsRespFieldNum = errors.New("extend args for response message should only has 1 field") + ErrNoExtendArgsRespFieldNum = errors.New("extend args for response message should has a field") +) + +type Dubbogo struct { + *protogen.File + + Source string + ProtoPackage string + Services []*Service +} + +type Service struct { + ServiceName string + InterfaceName string + Methods []*Method +} + +type Method struct { + MethodName string + InvokeName string + + // empty when RequestExtendArgs is true + RequestType string + RequestExtendArgs bool + ArgsType []string + ArgsName []string + + ResponseExtendArgs bool + ReturnType string +} + +func ProcessProtoFile(g *protogen.GeneratedFile, file *protogen.File) (*Dubbogo, error) { + desc := file.Proto + dubboGo := &Dubbogo{ + File: file, + Source: desc.GetName(), + ProtoPackage: desc.GetPackage(), + Services: make([]*Service, 0), + } + + for _, service := range file.Services { + serviceMethods := make([]*Method, 0) + for _, method := range service.Methods { + if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() { + return nil, ErrStreamMethod + } + m := &Method{ + MethodName: method.GoName, + RequestType: g.QualifiedGoIdent(method.Input.GoIdent), + ReturnType: g.QualifiedGoIdent(method.Output.GoIdent), + } + + methodOpt, ok := proto.GetExtension(method.Desc.Options(), unified_idl_extend.E_MethodExtend).(*unified_idl_extend.Hessian2MethodOptions) + invokeName := util.ToLower(method.GoName) + if ok && methodOpt != nil { + invokeName = methodOpt.MethodName + } + m.InvokeName = invokeName + + inputOpt, ok := proto.GetExtension(method.Input.Desc.Options(), unified_idl_extend.E_MessageExtend).(*unified_idl_extend.Hessian2MessageOptions) + if ok && inputOpt.ExtendArgs { + m.RequestExtendArgs = true + for _, field := range method.Input.Fields { + goType, _ := util.FieldGoType(g, field) + m.ArgsType = append(m.ArgsType, goType) + m.ArgsName = append(m.ArgsName, util.ToLower(field.GoName)) + } + } + + outputOpt, ok := proto.GetExtension(method.Output.Desc.Options(), unified_idl_extend.E_MessageExtend).(*unified_idl_extend.Hessian2MessageOptions) + if ok && outputOpt != nil && outputOpt.ExtendArgs { + m.ResponseExtendArgs = true + if len(method.Output.Fields) == 0 { + return nil, ErrNoExtendArgsRespFieldNum + } + if len(method.Output.Fields) != 1 { + return nil, ErrMoreExtendArgsRespFieldNum + } + goType, _ := util.FieldGoType(g, method.Output.Fields[0]) + m.ReturnType = goType + } + + serviceMethods = append(serviceMethods, m) + } + + serviceOpt, ok := proto.GetExtension(service.Desc.Options(), unified_idl_extend.E_ServiceExtend).(*unified_idl_extend.Hessian2ServiceOptions) + interfaceName := fmt.Sprintf("%s.%s", dubboGo.ProtoPackage, service.GoName) + if ok && serviceOpt != nil { + interfaceName = serviceOpt.InterfaceName + } + dubboGo.Services = append(dubboGo.Services, &Service{ + ServiceName: service.GoName, + Methods: serviceMethods, + InterfaceName: interfaceName, + }) + } + + return dubboGo, nil +} diff --git a/generator/generator.go b/generator/generator.go new file mode 100644 index 0000000..710eb5f --- /dev/null +++ b/generator/generator.go @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package generator + +import ( + "fmt" + "strings" +) + +import ( + "google.golang.org/protobuf/compiler/protogen" +) + +import ( + "github.com/dubbogo/protoc-gen-go-dubbo/util" +) + +func GenDubbo(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + genPreamble(g, dubboGo) + genPackage(g, dubboGo) + genImports(g, dubboGo) + genConst(g, dubboGo) + genTypeCheck(g, dubboGo) + genInterface(g, dubboGo) + genInterfaceImpl(g, dubboGo) + genMethodInfo(g, dubboGo) + genHandler(g, dubboGo) + genServiceInfo(g, dubboGo) +} + +func genPreamble(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + g.P("// Code generated by protoc-gen-go-dubbo. DO NOT EDIT.") + g.P() + g.P("// Source: ", dubboGo.Source) + g.P("// Package: ", strings.ReplaceAll(dubboGo.ProtoPackage, ".", "_")) + g.P() +} + +func genPackage(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + g.P("package ", dubboGo.GoPackageName) + g.P() +} + +func genImports(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + g.P(` + import ( + "context" + + "dubbo.apache.org/dubbo-go/v3" + "dubbo.apache.org/dubbo-go/v3/client" + "dubbo.apache.org/dubbo-go/v3/common" + "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/server" + ) + `) +} + +func genConst(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + g.P("const (") + for _, s := range dubboGo.Services { + g.P(fmt.Sprintf("// %sName is the fully-qualified name of the %s service.", s.ServiceName, s.ServiceName)) + g.P(fmt.Sprintf(`%sName = "%s"`, s.ServiceName, s.InterfaceName)) + g.P() + + g.P(` +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period.`) + for _, m := range s.Methods { + g.P(fmt.Sprintf(`// %s%sProcedure is the fully-qualified name of the %s's %s RPC.'`, + s.ServiceName, m.MethodName, s.ServiceName, m.MethodName)) + g.P(fmt.Sprintf(`%s%sProcedure = "/%s/%s"`, s.ServiceName, m.MethodName, s.InterfaceName, m.InvokeName)) + } + } + + g.P(")") + g.P() +} + +func genTypeCheck(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + g.P("var (") + for _, s := range dubboGo.Services { + g.P(fmt.Sprintf(`_ %s = (*%sImpl)(nil)`, s.ServiceName, s.ServiceName)) + } + g.P(")") + g.P() +} + +func genInterface(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + for _, s := range dubboGo.Services { + g.P(fmt.Sprintf("type %s interface {", s.ServiceName)) + for _, m := range s.Methods { + g.P(fmt.Sprintf("%s(ctx context.Context, %s opts ...client.CallOption) (%s, error)", + util.ToUpper(m.MethodName), buildRequestArgs(m, true), buildReturnType(m))) + } + g.P("}") + g.P() + } +} + +func genInterfaceImpl(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + for _, s := range dubboGo.Services { + g.P(fmt.Sprintf("// New%s constructs a client for the %s service", s.ServiceName, s.InterfaceName)) + g.P(fmt.Sprintf("func New%s(cli *client.Client, opts ...client.ReferenceOption) (%s, error) {", + s.ServiceName, s.ServiceName)) + g.P(fmt.Sprintf(`conn, err := cli.DialWithInfo("%s", &%s_ClientInfo, opts...)`, + s.InterfaceName, s.ServiceName)) + g.P("if err != nil {") + g.P("return nil, err") + g.P("}") + g.P(fmt.Sprintf("return &%sImpl {", s.ServiceName)) + g.P("conn: conn,") + g.P("}, nil") + g.P("}") + g.P() + + g.P("func SetConsumerService(srv common.RPCService) {") + g.P(fmt.Sprintf("dubbo.SetConsumerServiceWithInfo(srv, &%s_ClientInfo)", s.ServiceName)) + g.P("}") + g.P() + + g.P(fmt.Sprintf("// %sImpl implements %s", s.ServiceName, s.ServiceName)) + g.P(fmt.Sprintf("type %sImpl struct {", s.ServiceName)) + g.P("conn *client.Connection") + g.P("}") + g.P() + + for _, m := range s.Methods { + g.P(fmt.Sprintf("func (c *%sImpl) %s(ctx context.Context, %s opts ...client.CallOption) (%s, error) {", + s.ServiceName, util.ToUpper(m.MethodName), buildRequestArgs(m, true), buildReturnType(m))) + g.P(fmt.Sprintf("resp := new(%s)", m.ReturnType)) + g.P(fmt.Sprintf(`if err := c.conn.CallUnary(ctx, []interface{}{%s}, resp, "%s", opts...); err != nil {`, + buildRequestInvokeArgs(m), m.InvokeName)) + g.P(fmt.Sprintf("return %s, err", util.DefaultValue(m.ReturnType))) + g.P("}") + if util.IsBasicType(m.ReturnType) { + g.P("return *resp, nil") + } else { + g.P("return resp, nil") + } + g.P("}") + g.P() + } + } +} + +func genMethodInfo(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + for _, s := range dubboGo.Services { + g.P(fmt.Sprintf("var %s_ClientInfo = client.ClientInfo {", s.ServiceName)) + g.P(fmt.Sprintf(`InterfaceName: "%s",`, s.InterfaceName)) + g.P("MethodNames: []string {") + for _, m := range s.Methods { + g.P(fmt.Sprintf(`"%s",`, m.InvokeName)) + } + g.P("},") + g.P("ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) {") + g.P(fmt.Sprintf("dubboCli := dubboCliRaw.(*%sImpl)", s.ServiceName)) + g.P("dubboCli.conn = conn") + g.P("},") + g.P("}") + g.P() + } +} + +func genHandler(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + for _, s := range dubboGo.Services { + g.P(fmt.Sprintf("// %sHandler is an implementation of the %s service.", s.ServiceName, s.InterfaceName)) + g.P(fmt.Sprintf("type %sHandler interface {", s.ServiceName)) + for _, m := range s.Methods { + g.P(fmt.Sprintf("%s(ctx context.Context, %s) (%s, error)", util.ToUpper(m.MethodName), buildRequestArgs(m, false), buildReturnType(m))) + } + g.P("}") + g.P() + + g.P(fmt.Sprintf("func Register%sHandler(srv *server.Server, hdlr %sHandler, opts ...server.ServiceOption) error {", s.ServiceName, s.ServiceName)) + g.P(fmt.Sprintf("return srv.Register(hdlr, &%s_ServiceInfo, opts...)", s.ServiceName)) + g.P("}") + g.P() + + g.P("func SetProviderService(srv common.RPCService) {") + g.P(fmt.Sprintf("dubbo.SetProviderServiceWithInfo(srv, &%s_ServiceInfo)", s.ServiceName)) + g.P("}") + g.P() + } +} + +func genServiceInfo(g *protogen.GeneratedFile, dubboGo *Dubbogo) { + for _, s := range dubboGo.Services { + g.P(fmt.Sprintf("var %s_ServiceInfo = server.ServiceInfo {", s.ServiceName)) + g.P(fmt.Sprintf(`InterfaceName: "%s",`, s.InterfaceName)) + g.P(fmt.Sprintf("ServiceType: (*%sHandler)(nil),", s.ServiceName)) + g.P("Methods: []server.MethodInfo {") + for _, m := range s.Methods { + g.P("{") + g.P(fmt.Sprintf(`Name: "%s",`, m.InvokeName)) + g.P("Type: constant.CallUnary,") + g.P("ReqInitFunc: func() interface{} {") + g.P(fmt.Sprintf("return new(%s)", m.ReturnType)) + g.P("},") + g.P("MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) {") + if m.RequestExtendArgs { + for i := range m.ArgsType { + g.P(fmt.Sprintf("%s := args[%d].(%s)", m.ArgsName[i], i, m.ArgsType[i])) + } + } else { + g.P(fmt.Sprintf("req := args[0].(*%s)", m.RequestType)) + } + g.P(fmt.Sprintf("res, err := handler.(%sHandler).%s(ctx, %s)", s.ServiceName, util.ToUpper(m.MethodName), buildRequestInvokeArgs(m))) + g.P("return res, err") + g.P("},") + g.P("},") + } + g.P("},") + g.P("}") + } +} + +func buildRequestInvokeArgs(m *Method) string { + if m.RequestExtendArgs { + var res string + for i, name := range m.ArgsName { + if i == len(m.ArgsName)-1 { + res += name + } else { + res += name + ", " + } + } + return res + } + return "req" +} + +func buildRequestArgs(m *Method, trailingComma bool) string { + if m.RequestExtendArgs { + var res string + for i := range m.ArgsType { + res += fmt.Sprintf("%s %s", m.ArgsName[i], m.ArgsType[i]) + if i == len(m.ArgsType)-1 && !trailingComma { + break + } + res += ", " + } + return res + } + return fmt.Sprintf("req *%s,", m.RequestType) +} + +func buildReturnType(m *Method) string { + if m.ResponseExtendArgs { + return m.ReturnType + } + return "*" + m.ReturnType +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..87fb676 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/dubbogo/protoc-gen-go-dubbo + +go 1.20 + +require ( + github.com/pkg/errors v0.9.1 + google.golang.org/protobuf v1.33.0 +) + +require github.com/google/go-cmp v0.5.9 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f7de446 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..97ca704 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package version + +const Version = "1.0.0" diff --git a/main.go b/main.go new file mode 100644 index 0000000..6583c97 --- /dev/null +++ b/main.go @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "fmt" + "os" +) + +import ( + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/types/pluginpb" +) + +import ( + "github.com/dubbogo/protoc-gen-go-dubbo/generator" + "github.com/dubbogo/protoc-gen-go-dubbo/internal/version" +) + +const ( + usage = "Flags:\n -h, --help\tPrint this help and exit.\n --version\tPrint the version and exit." +) + +func main() { + if len(os.Args) == 2 && os.Args[1] == "--version" { + fmt.Fprintln(os.Stdout, version.Version) + os.Exit(0) + } + if len(os.Args) == 2 && (os.Args[1] == "-h" || os.Args[1] == "--help") { + fmt.Fprintln(os.Stdout, usage) + os.Exit(0) + } + if len(os.Args) != 1 { + fmt.Fprintln(os.Stderr, usage) + os.Exit(1) + } + + protogen.Options{}.Run(func(gen *protogen.Plugin) error { + gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) + for _, file := range gen.Files { + if file.Generate { + filename := file.GeneratedFilenamePrefix + ".dubbo.go" + g := gen.NewGeneratedFile(filename, file.GoImportPath) + + dubboGo, err := generator.ProcessProtoFile(g, file) + if err != nil { + return err + } + generator.GenDubbo(g, dubboGo) + } + } + return nil + }) +} diff --git a/proto/java8_time/java8_time.proto b/proto/java8_time/java8_time.proto new file mode 100644 index 0000000..b911bf0 --- /dev/null +++ b/proto/java8_time/java8_time.proto @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +syntax = "proto3"; + +package java8_time; + +option go_package = "github.com/dubbogo/protoc-gen-go-dubbo/proto/java8_time;java8_time"; + +message Duration {} + +message Instant {} + +message LocalDate {} + +message LocalDateTime {} + +message LocalTime {} + +message MonthDay {} + +message OffsetDateTime {} + +message OffsetTime {} + +message Period {} + +message Year{} + +message YearMonth{} + +message ZoneOffSet{} + +message ZonedDateTime{} \ No newline at end of file diff --git a/proto/java_exception/java_exception.proto b/proto/java_exception/java_exception.proto new file mode 100644 index 0000000..bbea05b --- /dev/null +++ b/proto/java_exception/java_exception.proto @@ -0,0 +1,196 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +syntax = "proto3"; + +package java_exception; + +option go_package = "github.com/dubbogo/protoc-gen-go-dubbo/proto/java_exception;java_exception"; + +message Exception {} + +message AnnotationTypeMismatchException {} + +message ArithmeticException {} + +message ArrayIndexOutOfBoundsException {} + +message ArrayStoreException {} + +message BackingStoreException {} + +message BrokenBarrierException {} + +message CancellationException {} + +message ClassNotFoundException {} + +message ClassCastException {} + +message CloneNotSupportedException {} + +message CompletionException {} + +message ConcurrentModificationException {} + +message DataFormatException {} + +message DateTimeException {} + +message DateTimeParseException {} + +message DubboGenericException {} + +message DuplicateFormatFlagsException {} + +message EmptyStackException {} + +message EnumConstantNotPresentException {} + +message EOFException {} + +message ExecutionException {} + +message FileNotFoundException {} + +message FormatterClosedException {} + +message IllegalAccessException {} + +message IllegalArgumentException {} + +message IllegalClassFormatException {} + +message IllegalFormatCodePointException {} + +message IllegalFormatConversionException {} + +message IllegalFormatFlagsException {} + +message IllegalFormatPrecisionException {} + +message IllegalFormatWidthException {} + +message IllegalMonitorStateException {} + +message IllegalStateException {} + +message IllegalThreadStateException {} + +message IllformedLocaleException {} + +message IncompleteAnnotationException {} + +message IndexOutOfBoundsException {} + +message InputMismatchException {} + +message InstantiationException {} + +message InterruptedException {} + +message InterruptedIOException {} + +message InvalidClassException {} + +message InvalidObjectException {} + +message InvalidPreferencesFormatException {} + +message InvalidPropertiesFormatException {} + +message InvocationTargetException {} + +message IOException {} + +message JarException {} + +message LambdaConversionException {} + +message MalformedParameterizedTypeException {} + +message MalformedParametersException {} + +message MissingFormatArgumentException {} + +message MissingFormatWidthException {} + +message MissingResourceException {} + +message NegativeArraySizeException {} + +message NoSuchElementException {} + +message NoSuchFieldException {} + +message NoSuchMethodException {} + +message NotActiveException {} + +message NotSerializableException {} + +message NullPointerException {} + +message NumberFormatException {} + +message ObjectStreamException {} + +message OptionalDataException {} + +message ReflectiveOperationException {} + +message RejectedExecutionException {} + +message RuntimeException {} + +message SecurityException {} + +message StreamCorruptedException {} + +message StringIndexOutOfBoundsException {} + +message SyncFailedException {} + +message TimeoutException {} + +message TooManyListenersException {} + +message TypeNotPresentException {} + +message UncheckedIOException {} + +message UndeclaredThrowableException {} + +message UnknownFormatConversionException {} + +message UnknownFormatFlagsException {} + +message UnmodifiableClassException {} + +message UnsupportedOperationException {} + +message UnsupportedTemporalTypeException {} + +message UTFDataFormatException {} + +message WriteAbortedException {} + +message WrongMethodTypeException {} + +message ZipException {} + +message ZoneRulesException{} diff --git a/proto/java_math/java_math.proto b/proto/java_math/java_math.proto new file mode 100644 index 0000000..53c4149 --- /dev/null +++ b/proto/java_math/java_math.proto @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto3"; + +package java_math; + +option go_package = "github.com/dubbogo/protoc-gen-go-dubbo/proto/java_math;java_math"; + +message Decimal {} + +message Integer {} diff --git a/proto/java_sql_time/java_sql_time.proto b/proto/java_sql_time/java_sql_time.proto new file mode 100644 index 0000000..8141710 --- /dev/null +++ b/proto/java_sql_time/java_sql_time.proto @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto3"; + +package java_sql_time; + +option go_package = "github.com/dubbogo/protoc-gen-go-dubbo/proto/java_sql_time;java_sql_time"; + +message Time {} + +message Date {} \ No newline at end of file diff --git a/proto/java_util/java_util.proto b/proto/java_util/java_util.proto new file mode 100644 index 0000000..56e6065 --- /dev/null +++ b/proto/java_util/java_util.proto @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +syntax = "proto3"; + +package java_util; + +option go_package = "github.com/dubbogo/protoc-gen-go-dubbo/proto/java_util;java_util"; + +message Locale {} + +message UUID {} \ No newline at end of file diff --git a/proto/unified_idl_extend/unified_idl_extend.pb.go b/proto/unified_idl_extend/unified_idl_extend.pb.go new file mode 100644 index 0000000..093603c --- /dev/null +++ b/proto/unified_idl_extend/unified_idl_extend.pb.go @@ -0,0 +1,585 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.33.0 +// protoc v5.26.1 +// source: unified_idl_extend.proto + +package unified_idl_extend + +import ( + reflect "reflect" + sync "sync" +) + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + + descriptorpb "google.golang.org/protobuf/types/descriptorpb" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Hessian2MessageOptions struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + JavaClassName string `protobuf:"bytes,1,opt,name=java_class_name,json=javaClassName,proto3" json:"java_class_name,omitempty"` + ReferencePath string `protobuf:"bytes,2,opt,name=reference_path,json=referencePath,proto3" json:"reference_path,omitempty"` + IsInheritance bool `protobuf:"varint,3,opt,name=is_inheritance,json=isInheritance,proto3" json:"is_inheritance,omitempty"` + ExtendArgs bool `protobuf:"varint,4,opt,name=extend_args,json=extendArgs,proto3" json:"extend_args,omitempty"` +} + +func (x *Hessian2MessageOptions) Reset() { + *x = Hessian2MessageOptions{} + if protoimpl.UnsafeEnabled { + mi := &file_unified_idl_extend_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Hessian2MessageOptions) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Hessian2MessageOptions) ProtoMessage() {} + +func (x *Hessian2MessageOptions) ProtoReflect() protoreflect.Message { + mi := &file_unified_idl_extend_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Hessian2MessageOptions.ProtoReflect.Descriptor instead. +func (*Hessian2MessageOptions) Descriptor() ([]byte, []int) { + return file_unified_idl_extend_proto_rawDescGZIP(), []int{0} +} + +func (x *Hessian2MessageOptions) GetJavaClassName() string { + if x != nil { + return x.JavaClassName + } + return "" +} + +func (x *Hessian2MessageOptions) GetReferencePath() string { + if x != nil { + return x.ReferencePath + } + return "" +} + +func (x *Hessian2MessageOptions) GetIsInheritance() bool { + if x != nil { + return x.IsInheritance + } + return false +} + +func (x *Hessian2MessageOptions) GetExtendArgs() bool { + if x != nil { + return x.ExtendArgs + } + return false +} + +type Hessian2MethodOptions struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + MethodName string `protobuf:"bytes,1,opt,name=method_name,json=methodName,proto3" json:"method_name,omitempty"` +} + +func (x *Hessian2MethodOptions) Reset() { + *x = Hessian2MethodOptions{} + if protoimpl.UnsafeEnabled { + mi := &file_unified_idl_extend_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Hessian2MethodOptions) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Hessian2MethodOptions) ProtoMessage() {} + +func (x *Hessian2MethodOptions) ProtoReflect() protoreflect.Message { + mi := &file_unified_idl_extend_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Hessian2MethodOptions.ProtoReflect.Descriptor instead. +func (*Hessian2MethodOptions) Descriptor() ([]byte, []int) { + return file_unified_idl_extend_proto_rawDescGZIP(), []int{1} +} + +func (x *Hessian2MethodOptions) GetMethodName() string { + if x != nil { + return x.MethodName + } + return "" +} + +type Hessian2ServiceOptions struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + InterfaceName string `protobuf:"bytes,1,opt,name=interface_name,json=interfaceName,proto3" json:"interface_name,omitempty"` +} + +func (x *Hessian2ServiceOptions) Reset() { + *x = Hessian2ServiceOptions{} + if protoimpl.UnsafeEnabled { + mi := &file_unified_idl_extend_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Hessian2ServiceOptions) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Hessian2ServiceOptions) ProtoMessage() {} + +func (x *Hessian2ServiceOptions) ProtoReflect() protoreflect.Message { + mi := &file_unified_idl_extend_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Hessian2ServiceOptions.ProtoReflect.Descriptor instead. +func (*Hessian2ServiceOptions) Descriptor() ([]byte, []int) { + return file_unified_idl_extend_proto_rawDescGZIP(), []int{2} +} + +func (x *Hessian2ServiceOptions) GetInterfaceName() string { + if x != nil { + return x.InterfaceName + } + return "" +} + +type Hessian2EnumOptions struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + JavaClassName string `protobuf:"bytes,1,opt,name=java_class_name,json=javaClassName,proto3" json:"java_class_name,omitempty"` +} + +func (x *Hessian2EnumOptions) Reset() { + *x = Hessian2EnumOptions{} + if protoimpl.UnsafeEnabled { + mi := &file_unified_idl_extend_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Hessian2EnumOptions) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Hessian2EnumOptions) ProtoMessage() {} + +func (x *Hessian2EnumOptions) ProtoReflect() protoreflect.Message { + mi := &file_unified_idl_extend_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Hessian2EnumOptions.ProtoReflect.Descriptor instead. +func (*Hessian2EnumOptions) Descriptor() ([]byte, []int) { + return file_unified_idl_extend_proto_rawDescGZIP(), []int{3} +} + +func (x *Hessian2EnumOptions) GetJavaClassName() string { + if x != nil { + return x.JavaClassName + } + return "" +} + +type Hessian2FieldOptions struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IsWrapper bool `protobuf:"varint,1,opt,name=is_wrapper,json=isWrapper,proto3" json:"is_wrapper,omitempty"` +} + +func (x *Hessian2FieldOptions) Reset() { + *x = Hessian2FieldOptions{} + if protoimpl.UnsafeEnabled { + mi := &file_unified_idl_extend_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Hessian2FieldOptions) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Hessian2FieldOptions) ProtoMessage() {} + +func (x *Hessian2FieldOptions) ProtoReflect() protoreflect.Message { + mi := &file_unified_idl_extend_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Hessian2FieldOptions.ProtoReflect.Descriptor instead. +func (*Hessian2FieldOptions) Descriptor() ([]byte, []int) { + return file_unified_idl_extend_proto_rawDescGZIP(), []int{4} +} + +func (x *Hessian2FieldOptions) GetIsWrapper() bool { + if x != nil { + return x.IsWrapper + } + return false +} + +var file_unified_idl_extend_proto_extTypes = []protoimpl.ExtensionInfo{ + { + ExtendedType: (*descriptorpb.MessageOptions)(nil), + ExtensionType: (*Hessian2MessageOptions)(nil), + Field: 12345, + Name: "unified_idl_extend.message_extend", + Tag: "bytes,12345,opt,name=message_extend", + Filename: "unified_idl_extend.proto", + }, + { + ExtendedType: (*descriptorpb.MethodOptions)(nil), + ExtensionType: (*Hessian2MethodOptions)(nil), + Field: 12345, + Name: "unified_idl_extend.method_extend", + Tag: "bytes,12345,opt,name=method_extend", + Filename: "unified_idl_extend.proto", + }, + { + ExtendedType: (*descriptorpb.ServiceOptions)(nil), + ExtensionType: (*Hessian2ServiceOptions)(nil), + Field: 12345, + Name: "unified_idl_extend.service_extend", + Tag: "bytes,12345,opt,name=service_extend", + Filename: "unified_idl_extend.proto", + }, + { + ExtendedType: (*descriptorpb.EnumOptions)(nil), + ExtensionType: (*Hessian2EnumOptions)(nil), + Field: 12345, + Name: "unified_idl_extend.enum_extend", + Tag: "bytes,12345,opt,name=enum_extend", + Filename: "unified_idl_extend.proto", + }, + { + ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtensionType: (*Hessian2FieldOptions)(nil), + Field: 12345, + Name: "unified_idl_extend.field_extend", + Tag: "bytes,12345,opt,name=field_extend", + Filename: "unified_idl_extend.proto", + }, +} + +// Extension fields to descriptorpb.MessageOptions. +var ( + // optional unified_idl_extend.Hessian2MessageOptions message_extend = 12345; + E_MessageExtend = &file_unified_idl_extend_proto_extTypes[0] +) + +// Extension fields to descriptorpb.MethodOptions. +var ( + // optional unified_idl_extend.Hessian2MethodOptions method_extend = 12345; + E_MethodExtend = &file_unified_idl_extend_proto_extTypes[1] +) + +// Extension fields to descriptorpb.ServiceOptions. +var ( + // optional unified_idl_extend.Hessian2ServiceOptions service_extend = 12345; + E_ServiceExtend = &file_unified_idl_extend_proto_extTypes[2] +) + +// Extension fields to descriptorpb.EnumOptions. +var ( + // optional unified_idl_extend.Hessian2EnumOptions enum_extend = 12345; + E_EnumExtend = &file_unified_idl_extend_proto_extTypes[3] +) + +// Extension fields to descriptorpb.FieldOptions. +var ( + // optional unified_idl_extend.Hessian2FieldOptions field_extend = 12345; + E_FieldExtend = &file_unified_idl_extend_proto_extTypes[4] +) + +var File_unified_idl_extend_proto protoreflect.FileDescriptor + +var file_unified_idl_extend_proto_rawDesc = []byte{ + 0x0a, 0x18, 0x75, 0x6e, 0x69, 0x66, 0x69, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x6c, 0x5f, 0x65, 0x78, + 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x75, 0x6e, 0x69, 0x66, + 0x69, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x6c, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x1a, 0x20, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, + 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x22, 0xaf, 0x01, 0x0a, 0x16, 0x48, 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x6a, + 0x61, 0x76, 0x61, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6a, 0x61, 0x76, 0x61, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x4e, + 0x61, 0x6d, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, + 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x72, 0x65, 0x66, + 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x25, 0x0a, 0x0e, 0x69, 0x73, + 0x5f, 0x69, 0x6e, 0x68, 0x65, 0x72, 0x69, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x0d, 0x69, 0x73, 0x49, 0x6e, 0x68, 0x65, 0x72, 0x69, 0x74, 0x61, 0x6e, 0x63, + 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x61, 0x72, 0x67, 0x73, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x41, 0x72, + 0x67, 0x73, 0x22, 0x38, 0x0a, 0x15, 0x48, 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x4d, 0x65, + 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, + 0x65, 0x74, 0x68, 0x6f, 0x64, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x3f, 0x0a, 0x16, + 0x48, 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, + 0x61, 0x63, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x3d, 0x0a, + 0x13, 0x48, 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x6a, 0x61, 0x76, 0x61, 0x5f, 0x63, 0x6c, 0x61, + 0x73, 0x73, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6a, + 0x61, 0x76, 0x61, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x35, 0x0a, 0x14, + 0x48, 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x77, 0x72, 0x61, 0x70, 0x70, + 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x57, 0x72, 0x61, 0x70, + 0x70, 0x65, 0x72, 0x3a, 0x76, 0x0a, 0x0e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x65, + 0x78, 0x74, 0x65, 0x6e, 0x64, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb9, 0x60, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 0x2e, + 0x75, 0x6e, 0x69, 0x66, 0x69, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x6c, 0x5f, 0x65, 0x78, 0x74, 0x65, + 0x6e, 0x64, 0x2e, 0x48, 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x88, 0x01, 0x01, 0x3a, 0x72, 0x0a, 0x0d, 0x6d, + 0x65, 0x74, 0x68, 0x6f, 0x64, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x12, 0x1e, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, + 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb9, 0x60, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x75, 0x6e, 0x69, 0x66, 0x69, 0x65, 0x64, 0x5f, 0x69, 0x64, + 0x6c, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x48, 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, + 0x32, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x0c, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x88, 0x01, 0x01, 0x3a, + 0x76, 0x0a, 0x0e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, + 0x64, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x18, 0xb9, 0x60, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x75, 0x6e, 0x69, 0x66, + 0x69, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x6c, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x48, + 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x45, 0x78, + 0x74, 0x65, 0x6e, 0x64, 0x88, 0x01, 0x01, 0x3a, 0x6a, 0x0a, 0x0b, 0x65, 0x6e, 0x75, 0x6d, 0x5f, + 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xb9, 0x60, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x75, 0x6e, + 0x69, 0x66, 0x69, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x6c, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, + 0x2e, 0x48, 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x0a, 0x65, 0x6e, 0x75, 0x6d, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, + 0x88, 0x01, 0x01, 0x3a, 0x6e, 0x0a, 0x0c, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x65, 0x78, 0x74, + 0x65, 0x6e, 0x64, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x18, 0xb9, 0x60, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x75, 0x6e, 0x69, 0x66, + 0x69, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x6c, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x48, + 0x65, 0x73, 0x73, 0x69, 0x61, 0x6e, 0x32, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x52, 0x0b, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, + 0x88, 0x01, 0x01, 0x42, 0x54, 0x5a, 0x52, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x64, 0x75, 0x62, 0x62, 0x6f, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, + 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x67, 0x6f, 0x2d, 0x64, 0x75, 0x62, 0x62, 0x6f, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2f, 0x75, 0x6e, 0x69, 0x66, 0x69, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x6c, 0x5f, + 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x3b, 0x75, 0x6e, 0x69, 0x66, 0x69, 0x65, 0x64, 0x5f, 0x69, + 0x64, 0x6c, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, +} + +var ( + file_unified_idl_extend_proto_rawDescOnce sync.Once + file_unified_idl_extend_proto_rawDescData = file_unified_idl_extend_proto_rawDesc +) + +func file_unified_idl_extend_proto_rawDescGZIP() []byte { + file_unified_idl_extend_proto_rawDescOnce.Do(func() { + file_unified_idl_extend_proto_rawDescData = protoimpl.X.CompressGZIP(file_unified_idl_extend_proto_rawDescData) + }) + return file_unified_idl_extend_proto_rawDescData +} + +var file_unified_idl_extend_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_unified_idl_extend_proto_goTypes = []interface{}{ + (*Hessian2MessageOptions)(nil), // 0: unified_idl_extend.Hessian2MessageOptions + (*Hessian2MethodOptions)(nil), // 1: unified_idl_extend.Hessian2MethodOptions + (*Hessian2ServiceOptions)(nil), // 2: unified_idl_extend.Hessian2ServiceOptions + (*Hessian2EnumOptions)(nil), // 3: unified_idl_extend.Hessian2EnumOptions + (*Hessian2FieldOptions)(nil), // 4: unified_idl_extend.Hessian2FieldOptions + (*descriptorpb.MessageOptions)(nil), // 5: google.protobuf.MessageOptions + (*descriptorpb.MethodOptions)(nil), // 6: google.protobuf.MethodOptions + (*descriptorpb.ServiceOptions)(nil), // 7: google.protobuf.ServiceOptions + (*descriptorpb.EnumOptions)(nil), // 8: google.protobuf.EnumOptions + (*descriptorpb.FieldOptions)(nil), // 9: google.protobuf.FieldOptions +} +var file_unified_idl_extend_proto_depIdxs = []int32{ + 5, // 0: unified_idl_extend.message_extend:extendee -> google.protobuf.MessageOptions + 6, // 1: unified_idl_extend.method_extend:extendee -> google.protobuf.MethodOptions + 7, // 2: unified_idl_extend.service_extend:extendee -> google.protobuf.ServiceOptions + 8, // 3: unified_idl_extend.enum_extend:extendee -> google.protobuf.EnumOptions + 9, // 4: unified_idl_extend.field_extend:extendee -> google.protobuf.FieldOptions + 0, // 5: unified_idl_extend.message_extend:type_name -> unified_idl_extend.Hessian2MessageOptions + 1, // 6: unified_idl_extend.method_extend:type_name -> unified_idl_extend.Hessian2MethodOptions + 2, // 7: unified_idl_extend.service_extend:type_name -> unified_idl_extend.Hessian2ServiceOptions + 3, // 8: unified_idl_extend.enum_extend:type_name -> unified_idl_extend.Hessian2EnumOptions + 4, // 9: unified_idl_extend.field_extend:type_name -> unified_idl_extend.Hessian2FieldOptions + 10, // [10:10] is the sub-list for method output_type + 10, // [10:10] is the sub-list for method input_type + 5, // [5:10] is the sub-list for extension type_name + 0, // [0:5] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_unified_idl_extend_proto_init() } +func file_unified_idl_extend_proto_init() { + if File_unified_idl_extend_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_unified_idl_extend_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Hessian2MessageOptions); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_unified_idl_extend_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Hessian2MethodOptions); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_unified_idl_extend_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Hessian2ServiceOptions); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_unified_idl_extend_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Hessian2EnumOptions); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_unified_idl_extend_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Hessian2FieldOptions); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_unified_idl_extend_proto_rawDesc, + NumEnums: 0, + NumMessages: 5, + NumExtensions: 5, + NumServices: 0, + }, + GoTypes: file_unified_idl_extend_proto_goTypes, + DependencyIndexes: file_unified_idl_extend_proto_depIdxs, + MessageInfos: file_unified_idl_extend_proto_msgTypes, + ExtensionInfos: file_unified_idl_extend_proto_extTypes, + }.Build() + File_unified_idl_extend_proto = out.File + file_unified_idl_extend_proto_rawDesc = nil + file_unified_idl_extend_proto_goTypes = nil + file_unified_idl_extend_proto_depIdxs = nil +} diff --git a/proto/unified_idl_extend/unified_idl_extend.proto b/proto/unified_idl_extend/unified_idl_extend.proto new file mode 100644 index 0000000..240bd0d --- /dev/null +++ b/proto/unified_idl_extend/unified_idl_extend.proto @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto3"; + +package unified_idl_extend; + +option go_package = "github.com/dubbogo/protoc-gen-go-dubbo/proto/unified_idl_extend;unified_idl_extend"; + +import "google/protobuf/descriptor.proto"; + +message Hessian2MessageOptions { + string java_class_name = 1; + string reference_path = 2; + bool is_inheritance = 3; + bool extend_args = 4; +} + +extend google.protobuf.MessageOptions { + optional Hessian2MessageOptions message_extend = 12345; +} + +message Hessian2MethodOptions { + string method_name = 1; +} + +extend google.protobuf.MethodOptions { + optional Hessian2MethodOptions method_extend = 12345; +} + +message Hessian2ServiceOptions { + string interface_name = 1; +} + +extend google.protobuf.ServiceOptions { + optional Hessian2ServiceOptions service_extend = 12345; +} + +message Hessian2EnumOptions { + string java_class_name = 1; +} + +extend google.protobuf.EnumOptions { + optional Hessian2EnumOptions enum_extend = 12345; +} + +message Hessian2FieldOptions { + bool is_wrapper = 1; +} + +extend google.protobuf.FieldOptions { + optional Hessian2FieldOptions field_extend = 12345; +} \ No newline at end of file diff --git a/util/strings.go b/util/strings.go new file mode 100644 index 0000000..59fee2e --- /dev/null +++ b/util/strings.go @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package util + +import ( + "strings" +) + +// ToUpper will capitalize the first character +func ToUpper(s string) string { + if s == "" { + return "" + } + return strings.ToUpper(s[:1]) + s[1:] +} + +// ToLower will lowercase the first character +func ToLower(s string) string { + if s == "" { + return "" + } + return strings.ToLower(s[:1]) + s[1:] +} diff --git a/util/type.go b/util/type.go new file mode 100644 index 0000000..f6eb184 --- /dev/null +++ b/util/type.go @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package util + +import ( + "fmt" +) + +import ( + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" +) + +import ( + "github.com/dubbogo/protoc-gen-go-dubbo/proto/unified_idl_extend" +) + +// below is helper func that copy from protobuf-gen-go +// FieldGoType returns the Go type used for a field. +// +// If it returns pointer=true, the struct field is a pointer to the type. +func FieldGoType(g *protogen.GeneratedFile, field *protogen.Field) (goType string, pointer bool) { + if field.Desc.IsWeak() { + return "struct{}", false + } + + var isWrapper bool + opt, ok := proto.GetExtension(field.Desc.Options(), unified_idl_extend.E_FieldExtend).(*unified_idl_extend.Hessian2FieldOptions) + if ok && opt != nil { + isWrapper = opt.IsWrapper + } + + pointer = field.Desc.HasPresence() + switch field.Desc.Kind() { + case protoreflect.BoolKind: + goType = "bool" + if isWrapper { + goType = "*" + goType + } + case protoreflect.EnumKind: + goType = g.QualifiedGoIdent(field.Enum.GoIdent) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + goType = "int32" + if isWrapper { + goType = "*" + goType + } + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: + goType = "uint32" + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + goType = "int64" + if isWrapper { + goType = "*" + goType + } + case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + goType = "uint64" + case protoreflect.FloatKind: + goType = "float32" + if isWrapper { + goType = "*" + goType + } + case protoreflect.DoubleKind: + goType = "float64" + if isWrapper { + goType = "*" + goType + } + case protoreflect.StringKind: + goType = "string" + case protoreflect.BytesKind: + goType = "[]byte" + pointer = false // rely on nullability of slices for presence + case protoreflect.MessageKind, protoreflect.GroupKind: + goType = "*" + g.QualifiedGoIdent(field.Message.GoIdent) + pointer = false // pointer captured as part of the type + } + switch { + case field.Desc.IsList(): + return "[]" + goType, false + case field.Desc.IsMap(): + keyType, _ := FieldGoType(g, field.Message.Fields[0]) + valType, _ := FieldGoType(g, field.Message.Fields[1]) + return fmt.Sprintf("map[%v]%v", keyType, valType), false + } + return goType, pointer +} + +func DefaultValue(typeStr string) string { + switch typeStr { + case "int", "int8", "int16", "int32", "int64", + "uint", "uint8", "uint16", "uint32", "uint64", + "float32", "float64", "byte", "rune", + "complex64", "complex128": + return "0" + case "bool": + return "false" + case "string": + return `""` + default: + return "nil" + } +} + +func IsBasicType(typeStr string) bool { + switch typeStr { + case "int", "int8", "int16", "int32", "int64", + "uint", "uint8", "uint16", "uint32", "uint64", + "float32", "float64", "byte", "rune", + "complex64", "complex128", "bool", "string": + return true + default: + return false + } +} From 90ea9d477b39625764c3a65d4f11e1771f5bd901 Mon Sep 17 00:00:00 2001 From: Yuuki <928196210@qq.com> Date: Tue, 9 Jul 2024 17:53:55 +0800 Subject: [PATCH 2/2] update README.md --- README.md | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 200 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a78368..61f0d8d 100644 --- a/README.md +++ b/README.md @@ -1 +1,200 @@ -# [WIP] protoc-gen-go-dubbo +# protoc-gen-go-dubbo + +## Prerequisites +Before using `protoc-gen-go-dubbo`, make sure you have the following prerequisites installed on your system: +- Go (version 1.17 or higher) +- Protocol Buffers (version 3.0 or higher) + +## Installation +To install `protoc-gen-go-dubbo`, you can use `go install`: +```shell +go install github.com/dubbogo/protoc-gen-go-dubbo +``` + +Or you can clone this repository and build it manually: +```shell +git clone github.com/dubbogo/protoc-gen-go-dubbo +cd protoc-gen-go-dubbo +go build +``` + +## Usage +To generate dubbo code using `protoc-gen-go-dubbo`, you can use the following command: +```shell +protoc -I ./ \ + --go-dubbo_out=./ --go-dubbo_opt=paths=source_relative \ + ./greet.proto +``` +The `--go-dubbo_out` option specifies the output directory for the generated code, +and `--go-dubbo_opt=paths=source_relative` sets the output path to be relative to the source file. + +## Example +To generate Dubbo code, you can create a `.proto` file with the following content: +```protobuf +syntax = "proto3"; + +package greet; + +option go_package = "some_path/greet;greet"; + +import "unified_idl_extend/unified_idl_extend.proto"; + +message GreetRequest { + string name = 1; + + option (unified_idl_extend.message_extend) = { + java_class_name: "org.apache.greet.GreetRequest"; + }; +} + +message GreetResponse { + string greeting = 1; + + option (unified_idl_extend.message_extend) = { + java_class_name: "org.apache.greet.GreetResponse"; + }; +} + +service GreetService { + rpc Greet(GreetRequest) returns (GreetResponse) { + option (unified_idl_extend.method_extend) = { + method_name: "greet"; + }; + } +} +``` +Note that you need to import the `unified_idl_extend` package to use the `method_extend` options to extend the service. +And Dubbo protocol must be used with Hessian2 serialization, so you need to use the `message_extend` options to extend +the message. + +Then, you can run the following command to generate the Dubbo and Hessian2 code: +```shell +protoc -I ./ \ + --go-hessian2_out=./ --go-hessian2_opt=paths=source_relative \ + --go-dubbo_out=./ --go-dubbo_opt=paths=source_relative \ + ./greet.proto +``` +This will generate the `greet.dubbo.go` and `greet.hessian2.go` file in the same directory as your `greet.proto` file: +```shell +. +├── greet.hessian2.go +├── greet.dubbo.go +├── greet.proto +└── unified_idl_extend + ├── unified_idl_extend.pb.go + └── unified_idl_extend.proto +``` + +The content of the `greet.hessian2.go` file will be: +```go +// Code generated by protoc-gen-go-dubbo. DO NOT EDIT. + +// Source: greet.proto +// Package: greet + +package greet + +import ( + "context" + + "dubbo.apache.org/dubbo-go/v3" + "dubbo.apache.org/dubbo-go/v3/client" + "dubbo.apache.org/dubbo-go/v3/common" + "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/server" +) + +const ( + // GreetServiceName is the fully-qualified name of the GreetService service. + GreetServiceName = "greet.GreetService" + + // These constants are the fully-qualified names of the RPCs defined in this package. They're + // exposed at runtime as procedure and as the final two segments of the HTTP route. + // + // Note that these are different from the fully-qualified method names used by + // google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to + // reflection-formatted method names, remove the leading slash and convert the remaining slash to a + // period. + // GreetServiceGreetProcedure is the fully-qualified name of the GreetService's Greet RPC.' + GreetServiceGreetProcedure = "/greet.GreetService/greet" +) + +var ( + _ GreetService = (*GreetServiceImpl)(nil) +) + +type GreetService interface { + Greet(ctx context.Context, req *GreetRequest, opts ...client.CallOption) (*GreetResponse, error) +} + +// NewGreetService constructs a client for the greet.GreetService service +func NewGreetService(cli *client.Client, opts ...client.ReferenceOption) (GreetService, error) { + conn, err := cli.DialWithInfo("greet.GreetService", &GreetService_ClientInfo, opts...) + if err != nil { + return nil, err + } + return &GreetServiceImpl{ + conn: conn, + }, nil +} + +func SetConsumerService(srv common.RPCService) { + dubbo.SetConsumerServiceWithInfo(srv, &GreetService_ClientInfo) +} + +// GreetServiceImpl implements GreetService +type GreetServiceImpl struct { + conn *client.Connection +} + +func (c *GreetServiceImpl) Greet(ctx context.Context, req *GreetRequest, opts ...client.CallOption) (*GreetResponse, error) { + resp := new(GreetResponse) + if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, "greet", opts...); err != nil { + return nil, err + } + return resp, nil +} + +var GreetService_ClientInfo = client.ClientInfo{ + InterfaceName: "greet.GreetService", + MethodNames: []string{ + "greet", + }, + ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) { + dubboCli := dubboCliRaw.(*GreetServiceImpl) + dubboCli.conn = conn + }, +} + +// GreetServiceHandler is an implementation of the greet.GreetService service. +type GreetServiceHandler interface { + Greet(ctx context.Context, req *GreetRequest) (*GreetResponse, error) +} + +func RegisterGreetServiceHandler(srv *server.Server, hdlr GreetServiceHandler, opts ...server.ServiceOption) error { + return srv.Register(hdlr, &GreetService_ServiceInfo, opts...) +} + +func SetProviderService(srv common.RPCService) { + dubbo.SetProviderServiceWithInfo(srv, &GreetService_ServiceInfo) +} + +var GreetService_ServiceInfo = server.ServiceInfo{ + InterfaceName: "greet.GreetService", + ServiceType: (*GreetServiceHandler)(nil), + Methods: []server.MethodInfo{ + { + Name: "greet", + Type: constant.CallUnary, + ReqInitFunc: func() interface{} { + return new(GreetResponse) + }, + MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) { + req := args[0].(*GreetRequest) + res, err := handler.(GreetServiceHandler).Greet(ctx, req) + return res, err + }, + }, + }, +} +``` \ No newline at end of file