diff --git a/go.mod b/go.mod index 10a4e7ca..7350cbe1 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( require ( github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect + github.com/cloudwego/fastpb v0.0.4 github.com/uber/jaeger-lib v2.4.1+incompatible // indirect go.uber.org/atomic v1.10.0 // indirect ) diff --git a/kitex_gen/api/echo.go b/kitex_gen/api/echo.go index 3cc1d26c..f6700317 100644 --- a/kitex_gen/api/echo.go +++ b/kitex_gen/api/echo.go @@ -1,4 +1,4 @@ -// Code generated by thriftgo (0.1.2). DO NOT EDIT. +// Code generated by thriftgo (0.3.1). DO NOT EDIT. package api @@ -10,14 +10,18 @@ import ( ) type Request struct { - Message string `thrift:"message,1" json:"message"` + Message string `thrift:"message,1" frugal:"1,default,string" json:"message"` } func NewRequest() *Request { return &Request{} } -func (p *Request) GetMessage() string { +func (p *Request) InitDefault() { + *p = Request{} +} + +func (p *Request) GetMessage() (v string) { return p.Message } func (p *Request) SetMessage(val string) { @@ -170,14 +174,18 @@ func (p *Request) Field1DeepEqual(src string) bool { } type Response struct { - Message string `thrift:"message,1" json:"message"` + Message string `thrift:"message,1" frugal:"1,default,string" json:"message"` } func NewResponse() *Response { return &Response{} } -func (p *Response) GetMessage() string { +func (p *Response) InitDefault() { + *p = Response{} +} + +func (p *Response) GetMessage() (v string) { return p.Message } func (p *Response) SetMessage(val string) { @@ -459,16 +467,20 @@ func (p *echoProcessorEcho) Process(ctx context.Context, seqId int32, iprot, opr } type EchoEchoArgs struct { - Req *Request `thrift:"req,1" json:"req"` + Req *Request `thrift:"req,1" frugal:"1,default,Request" json:"req"` } func NewEchoEchoArgs() *EchoEchoArgs { return &EchoEchoArgs{} } +func (p *EchoEchoArgs) InitDefault() { + *p = EchoEchoArgs{} +} + var EchoEchoArgs_Req_DEFAULT *Request -func (p *EchoEchoArgs) GetReq() *Request { +func (p *EchoEchoArgs) GetReq() (v *Request) { if !p.IsSetReq() { return EchoEchoArgs_Req_DEFAULT } @@ -627,16 +639,20 @@ func (p *EchoEchoArgs) Field1DeepEqual(src *Request) bool { } type EchoEchoResult struct { - Success *Response `thrift:"success,0" json:"success,omitempty"` + Success *Response `thrift:"success,0,optional" frugal:"0,optional,Response" json:"success,omitempty"` } func NewEchoEchoResult() *EchoEchoResult { return &EchoEchoResult{} } +func (p *EchoEchoResult) InitDefault() { + *p = EchoEchoResult{} +} + var EchoEchoResult_Success_DEFAULT *Response -func (p *EchoEchoResult) GetSuccess() *Response { +func (p *EchoEchoResult) GetSuccess() (v *Response) { if !p.IsSetSuccess() { return EchoEchoResult_Success_DEFAULT } diff --git a/kitex_gen/api/echo/client.go b/kitex_gen/api/echo/client.go index 806fa68c..f2c5e894 100644 --- a/kitex_gen/api/echo/client.go +++ b/kitex_gen/api/echo/client.go @@ -1,12 +1,12 @@ -// Code generated by Kitex v0.1.4. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package echo import ( "context" - "github.com/cloudwego/kitex-examples/kitex_gen/api" - "github.com/cloudwego/kitex/client" - "github.com/cloudwego/kitex/client/callopt" + api "github.com/cloudwego/kitex-examples/kitex_gen/api" + client "github.com/cloudwego/kitex/client" + callopt "github.com/cloudwego/kitex/client/callopt" ) // Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. diff --git a/kitex_gen/api/echo/echo.go b/kitex_gen/api/echo/echo.go index 99355b2e..aa12cba7 100644 --- a/kitex_gen/api/echo/echo.go +++ b/kitex_gen/api/echo/echo.go @@ -1,11 +1,11 @@ -// Code generated by Kitex v0.1.4. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package echo import ( "context" - "github.com/cloudwego/kitex-examples/kitex_gen/api" - "github.com/cloudwego/kitex/client" + api "github.com/cloudwego/kitex-examples/kitex_gen/api" + client "github.com/cloudwego/kitex/client" kitex "github.com/cloudwego/kitex/pkg/serviceinfo" ) @@ -22,14 +22,15 @@ func NewServiceInfo() *kitex.ServiceInfo { "echo": kitex.NewMethodInfo(echoHandler, newEchoEchoArgs, newEchoEchoResult, false), } extra := map[string]interface{}{ - "PackageName": "api", + "PackageName": "api", + "ServiceFilePath": "echo.thrift", } svcInfo := &kitex.ServiceInfo{ ServiceName: serviceName, HandlerType: handlerType, Methods: methods, PayloadCodec: kitex.Thrift, - KiteXGenVersion: "v0.1.4", + KiteXGenVersion: "v0.7.1", Extra: extra, } return svcInfo diff --git a/kitex_gen/api/echo/invoker.go b/kitex_gen/api/echo/invoker.go index 94620eab..2961dcc4 100644 --- a/kitex_gen/api/echo/invoker.go +++ b/kitex_gen/api/echo/invoker.go @@ -1,10 +1,10 @@ -// Code generated by Kitex v0.1.4. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package echo import ( - "github.com/cloudwego/kitex-examples/kitex_gen/api" - "github.com/cloudwego/kitex/server" + api "github.com/cloudwego/kitex-examples/kitex_gen/api" + server "github.com/cloudwego/kitex/server" ) // NewInvoker creates a server.Invoker with the given handler and options. diff --git a/kitex_gen/api/echo/server.go b/kitex_gen/api/echo/server.go index 83f21838..214d49f2 100644 --- a/kitex_gen/api/echo/server.go +++ b/kitex_gen/api/echo/server.go @@ -1,9 +1,9 @@ -// Code generated by Kitex v0.1.4. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package echo import ( - "github.com/cloudwego/kitex-examples/kitex_gen/api" - "github.com/cloudwego/kitex/server" + api "github.com/cloudwego/kitex-examples/kitex_gen/api" + server "github.com/cloudwego/kitex/server" ) // NewServer creates a server.Server with the given handler and options. diff --git a/kitex_gen/api/k-echo.go b/kitex_gen/api/k-echo.go index dfb8435d..7c064ccf 100644 --- a/kitex_gen/api/k-echo.go +++ b/kitex_gen/api/k-echo.go @@ -1,4 +1,4 @@ -// Code generated by Kitex v0.1.4. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package api @@ -356,12 +356,14 @@ ReadStructEndError: func (p *EchoEchoArgs) FastReadField1(buf []byte) (int, error) { offset := 0 - p.Req = NewRequest() - if l, err := p.Req.FastRead(buf[offset:]); err != nil { + + tmp := NewRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { return offset, err } else { offset += l } + p.Req = tmp return offset, nil } @@ -481,12 +483,14 @@ ReadStructEndError: func (p *EchoEchoResult) FastReadField0(buf []byte) (int, error) { offset := 0 - p.Success = NewResponse() - if l, err := p.Success.FastRead(buf[offset:]); err != nil { + + tmp := NewResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { return offset, err } else { offset += l } + p.Success = tmp return offset, nil } diff --git a/kitex_gen/pbapi/echo.pb.fast.go b/kitex_gen/pbapi/echo.pb.fast.go new file mode 100644 index 00000000..ec34c28b --- /dev/null +++ b/kitex_gen/pbapi/echo.pb.fast.go @@ -0,0 +1,135 @@ +// Code generated by Fastpb v0.0.2. DO NOT EDIT. + +package pbapi + +import ( + fmt "fmt" + fastpb "github.com/cloudwego/fastpb" +) + +var ( + _ = fmt.Errorf + _ = fastpb.Skip +) + +func (x *Request) FastRead(buf []byte, _type int8, number int32) (offset int, err error) { + switch number { + case 1: + offset, err = x.fastReadField1(buf, _type) + if err != nil { + goto ReadFieldError + } + default: + offset, err = fastpb.Skip(buf, _type, number) + if err != nil { + goto SkipFieldError + } + } + return offset, nil +SkipFieldError: + return offset, fmt.Errorf("%T cannot parse invalid wire-format data, error: %s", x, err) +ReadFieldError: + return offset, fmt.Errorf("%T read field %d '%s' error: %s", x, number, fieldIDToName_Request[number], err) +} + +func (x *Request) fastReadField1(buf []byte, _type int8) (offset int, err error) { + x.Message, offset, err = fastpb.ReadString(buf, _type) + return offset, err +} + +func (x *Response) FastRead(buf []byte, _type int8, number int32) (offset int, err error) { + switch number { + case 1: + offset, err = x.fastReadField1(buf, _type) + if err != nil { + goto ReadFieldError + } + default: + offset, err = fastpb.Skip(buf, _type, number) + if err != nil { + goto SkipFieldError + } + } + return offset, nil +SkipFieldError: + return offset, fmt.Errorf("%T cannot parse invalid wire-format data, error: %s", x, err) +ReadFieldError: + return offset, fmt.Errorf("%T read field %d '%s' error: %s", x, number, fieldIDToName_Response[number], err) +} + +func (x *Response) fastReadField1(buf []byte, _type int8) (offset int, err error) { + x.Message, offset, err = fastpb.ReadString(buf, _type) + return offset, err +} + +func (x *Request) FastWrite(buf []byte) (offset int) { + if x == nil { + return offset + } + offset += x.fastWriteField1(buf[offset:]) + return offset +} + +func (x *Request) fastWriteField1(buf []byte) (offset int) { + if x.Message == "" { + return offset + } + offset += fastpb.WriteString(buf[offset:], 1, x.GetMessage()) + return offset +} + +func (x *Response) FastWrite(buf []byte) (offset int) { + if x == nil { + return offset + } + offset += x.fastWriteField1(buf[offset:]) + return offset +} + +func (x *Response) fastWriteField1(buf []byte) (offset int) { + if x.Message == "" { + return offset + } + offset += fastpb.WriteString(buf[offset:], 1, x.GetMessage()) + return offset +} + +func (x *Request) Size() (n int) { + if x == nil { + return n + } + n += x.sizeField1() + return n +} + +func (x *Request) sizeField1() (n int) { + if x.Message == "" { + return n + } + n += fastpb.SizeString(1, x.GetMessage()) + return n +} + +func (x *Response) Size() (n int) { + if x == nil { + return n + } + n += x.sizeField1() + return n +} + +func (x *Response) sizeField1() (n int) { + if x.Message == "" { + return n + } + n += fastpb.SizeString(1, x.GetMessage()) + return n +} + +var fieldIDToName_Request = map[int32]string{ + 1: "Message", +} + +var fieldIDToName_Response = map[int32]string{ + 1: "Message", +} diff --git a/kitex_gen/pbapi/echo.pb.go b/kitex_gen/pbapi/echo.pb.go index c5a10676..1d950584 100644 --- a/kitex_gen/pbapi/echo.pb.go +++ b/kitex_gen/pbapi/echo.pb.go @@ -1,18 +1,32 @@ +// Copyright 2021 CloudWeGo Authors +// +// 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. +// + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.12.4 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: echo.proto package pbapi import ( context "context" - reflect "reflect" - sync "sync" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) const ( @@ -146,14 +160,11 @@ func file_echo_proto_rawDescGZIP() []byte { return file_echo_proto_rawDescData } -var ( - file_echo_proto_msgTypes = make([]protoimpl.MessageInfo, 2) - file_echo_proto_goTypes = []interface{}{ - (*Request)(nil), // 0: pbapi.Request - (*Response)(nil), // 1: pbapi.Response - } -) - +var file_echo_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_echo_proto_goTypes = []interface{}{ + (*Request)(nil), // 0: pbapi.Request + (*Response)(nil), // 1: pbapi.Response +} var file_echo_proto_depIdxs = []int32{ 0, // 0: pbapi.Echo.Echo:input_type -> pbapi.Request 1, // 1: pbapi.Echo.Echo:output_type -> pbapi.Response @@ -217,7 +228,7 @@ func file_echo_proto_init() { var _ context.Context -// Code generated by Kitex v0.0.6. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. type Echo interface { Echo(ctx context.Context, req *Request) (res *Response, err error) diff --git a/kitex_gen/pbapi/echo/client.go b/kitex_gen/pbapi/echo/client.go index 1afbba99..4192e98b 100644 --- a/kitex_gen/pbapi/echo/client.go +++ b/kitex_gen/pbapi/echo/client.go @@ -1,12 +1,12 @@ -// Code generated by Kitex v0.0.6. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package echo import ( "context" - "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" - "github.com/cloudwego/kitex/client" - "github.com/cloudwego/kitex/client/callopt" + pbapi "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" + client "github.com/cloudwego/kitex/client" + callopt "github.com/cloudwego/kitex/client/callopt" ) // Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. diff --git a/kitex_gen/pbapi/echo/echo.go b/kitex_gen/pbapi/echo/echo.go index 408fafee..3f5417cf 100644 --- a/kitex_gen/pbapi/echo/echo.go +++ b/kitex_gen/pbapi/echo/echo.go @@ -1,38 +1,38 @@ -// Code generated by Kitex v0.0.6. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package echo import ( "context" - "fmt" - "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" - "github.com/cloudwego/kitex/client" + pbapi "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" + client "github.com/cloudwego/kitex/client" kitex "github.com/cloudwego/kitex/pkg/serviceinfo" - "github.com/cloudwego/kitex/pkg/streaming" - "google.golang.org/protobuf/proto" + streaming "github.com/cloudwego/kitex/pkg/streaming" + proto "google.golang.org/protobuf/proto" ) func serviceInfo() *kitex.ServiceInfo { return echoServiceInfo } -var echoServiceInfo = newServiceInfo() +var echoServiceInfo = NewServiceInfo() -func newServiceInfo() *kitex.ServiceInfo { +func NewServiceInfo() *kitex.ServiceInfo { serviceName := "Echo" handlerType := (*pbapi.Echo)(nil) methods := map[string]kitex.MethodInfo{ "Echo": kitex.NewMethodInfo(echoHandler, newEchoArgs, newEchoResult, false), } extra := map[string]interface{}{ - "PackageName": "pbapi", + "PackageName": "pbapi", + "ServiceFilePath": "", } svcInfo := &kitex.ServiceInfo{ ServiceName: serviceName, HandlerType: handlerType, Methods: methods, PayloadCodec: kitex.Protobuf, - KiteXGenVersion: "v0.0.6", + KiteXGenVersion: "v0.7.1", Extra: extra, } return svcInfo @@ -75,9 +75,30 @@ type EchoArgs struct { Req *pbapi.Request } +func (p *EchoArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetReq() { + p.Req = new(pbapi.Request) + } + return p.Req.FastRead(buf, _type, number) +} + +func (p *EchoArgs) FastWrite(buf []byte) (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.FastWrite(buf) +} + +func (p *EchoArgs) Size() (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.Size() +} + func (p *EchoArgs) Marshal(out []byte) ([]byte, error) { if !p.IsSetReq() { - return out, fmt.Errorf("No req in EchoArgs") + return out, nil } return proto.Marshal(p.Req) } @@ -104,15 +125,40 @@ func (p *EchoArgs) IsSetReq() bool { return p.Req != nil } +func (p *EchoArgs) GetFirstArgument() interface{} { + return p.Req +} + type EchoResult struct { Success *pbapi.Response } var EchoResult_Success_DEFAULT *pbapi.Response +func (p *EchoResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetSuccess() { + p.Success = new(pbapi.Response) + } + return p.Success.FastRead(buf, _type, number) +} + +func (p *EchoResult) FastWrite(buf []byte) (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.FastWrite(buf) +} + +func (p *EchoResult) Size() (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.Size() +} + func (p *EchoResult) Marshal(out []byte) ([]byte, error) { if !p.IsSetSuccess() { - return out, fmt.Errorf("No req in EchoResult") + return out, nil } return proto.Marshal(p.Success) } @@ -141,6 +187,10 @@ func (p *EchoResult) IsSetSuccess() bool { return p.Success != nil } +func (p *EchoResult) GetResult() interface{} { + return p.Success +} + type kClient struct { c client.Client } diff --git a/kitex_gen/pbapi/echo/invoker.go b/kitex_gen/pbapi/echo/invoker.go index 0f2edba3..a2a61e83 100644 --- a/kitex_gen/pbapi/echo/invoker.go +++ b/kitex_gen/pbapi/echo/invoker.go @@ -1,10 +1,10 @@ -// Code generated by Kitex v0.0.6. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package echo import ( - "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" - "github.com/cloudwego/kitex/server" + pbapi "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" + server "github.com/cloudwego/kitex/server" ) // NewInvoker creates a server.Invoker with the given handler and options. diff --git a/kitex_gen/pbapi/echo/server.go b/kitex_gen/pbapi/echo/server.go index 216995a8..cfa0adbc 100644 --- a/kitex_gen/pbapi/echo/server.go +++ b/kitex_gen/pbapi/echo/server.go @@ -1,9 +1,9 @@ -// Code generated by Kitex v0.0.6. DO NOT EDIT. +// Code generated by Kitex v0.7.1. DO NOT EDIT. package echo import ( - "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" - "github.com/cloudwego/kitex/server" + pbapi "github.com/cloudwego/kitex-examples/kitex_gen/pbapi" + server "github.com/cloudwego/kitex/server" ) // NewServer creates a server.Server with the given handler and options. diff --git a/regenerate-idl.sh b/regenerate-idl.sh new file mode 100755 index 00000000..600c3031 --- /dev/null +++ b/regenerate-idl.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +kitex=${1:-kitex} + +function gen_thrift() { + frugal_tag='-thrift frugal_tag' + module='-module github.com/cloudwego/kitex-examples' + idl=echo.thrift + + $kitex $frugal_tag $module $idl +} + +function gen_protobuf() { + module='-module github.com/cloudwego/kitex-examples' + idl=echo.proto + $kitex $module $idl +} + +gen_thrift +gen_protobuf