├── .github └── workflows │ └── test.yml ├── LICENSE ├── Makefile ├── README.md ├── docker-compose.yml ├── http-server ├── Dockerfile ├── go.mod ├── go.sum ├── kitex_gen │ └── rpc │ │ ├── idl_rpc.go │ │ ├── imservice │ │ ├── client.go │ │ ├── imservice.go │ │ ├── invoker.go │ │ └── server.go │ │ ├── k-consts.go │ │ └── k-idl_rpc.go ├── main.go └── proto_gen │ └── api │ └── idl_http.pb.go ├── idl_http.proto ├── idl_rpc.thrift └── rpc-server ├── Dockerfile ├── build.sh ├── go.mod ├── go.sum ├── handler.go ├── handler_test.go ├── kitex_gen └── rpc │ ├── idl_rpc.go │ ├── imservice │ ├── client.go │ ├── imservice.go │ ├── invoker.go │ └── server.go │ ├── k-consts.go │ └── k-idl_rpc.go ├── kitex_info.yaml ├── main.go └── script └── bootstrap.sh /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a golang project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go 3 | 4 | name: Tests 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | jobs: 13 | 14 | http-server: 15 | runs-on: ubuntu-latest 16 | defaults: 17 | run: 18 | working-directory: ./http-server 19 | steps: 20 | - uses: actions/checkout@v3 21 | 22 | - name: Set up Go 23 | uses: actions/setup-go@v3 24 | with: 25 | go-version: 1.18 26 | 27 | - name: Build 28 | run: go build -v ./... 29 | 30 | - name: Test 31 | run: go test -race -cover -coverprofile=coverage.out $(go list ./... | grep -Ev "_gen") -coverpkg $(go list ./... | grep -Ev "_gen" | tr "\n" "," | sed 's/.$//') 32 | 33 | - name: Show coverage 34 | run: go tool cover -func=coverage.out | awk 'END {print $NF}' 35 | 36 | rpc-server: 37 | runs-on: ubuntu-latest 38 | defaults: 39 | run: 40 | working-directory: ./rpc-server 41 | steps: 42 | - uses: actions/checkout@v3 43 | 44 | - name: Set up Go 45 | uses: actions/setup-go@v3 46 | with: 47 | go-version: 1.18 48 | 49 | - name: Build 50 | run: go build -v ./... 51 | 52 | - name: Test 53 | run: go test -race -cover -coverprofile=coverage.out $(go list ./... | grep -Ev "_gen") -coverpkg $(go list ./... | grep -Ev "_gen" | tr "\n" "," | sed 's/.$//') 54 | 55 | - name: Show coverage 56 | run: go tool cover -func=coverage.out | awk 'END {print $NF}' 57 | 58 | docker-compose: 59 | runs-on: ubuntu-latest 60 | steps: 61 | - uses: actions/checkout@v3 62 | 63 | - name: Run Docker Compose 64 | run: docker-compose up -d 65 | 66 | - name: Check service status 67 | run: | 68 | if docker-compose ps | grep -q 'Exit'; then 69 | echo "Some services exited unexpectedly" 70 | exit 1 71 | else 72 | echo "All services are running" 73 | fi 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 TikTokTechImmersion 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | pre: 2 | go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 3 | go install github.com/cloudwego/kitex/tool/cmd/kitex@latest 4 | go install github.com/cloudwego/thriftgo@latest 5 | 6 | generate: 7 | mkdir -p ./http-server/proto_gen 8 | protoc -I=. --go_out=./http-server/proto_gen ./idl_http.proto 9 | cd http-server && kitex -module github.com/TikTokTechImmersion/assignment_demo_2023/http-server ../idl_rpc.thrift 10 | cd rpc-server && kitex -module github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server ../idl_rpc.thrift 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # assignment_demo_2023 2 | 3 | ![Tests](https://github.com/TikTokTechImmersion/assignment_demo_2023/actions/workflows/test.yml/badge.svg) 4 | 5 | This is a demo and template for backend assignment of 2023 TikTok Tech Immersion. 6 | 7 | ## Installation 8 | 9 | Requirement: 10 | 11 | - golang 1.18+ 12 | - docker 13 | 14 | To install dependency tools: 15 | 16 | ```bash 17 | make pre 18 | ``` 19 | 20 | ## Run 21 | 22 | ```bash 23 | docker-compose up -d 24 | ``` 25 | 26 | Check if it's running: 27 | 28 | ```bash 29 | curl localhost:8080/ping 30 | ``` 31 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | services: 3 | rpc-server: 4 | build: rpc-server 5 | ports: 6 | - "8888:8888" 7 | environment: 8 | - SERVICE_NAME=rpc-server 9 | - SERVICE_TAGS=rpc 10 | depends_on: 11 | - etcd 12 | http-server: 13 | build: http-server 14 | ports: 15 | - "8080:8080" 16 | environment: 17 | - SERVICE_NAME=http-server 18 | - SERVICE_TAGS=http 19 | depends_on: 20 | - etcd 21 | - rpc-server 22 | etcd: 23 | image: quay.io/coreos/etcd:v3.5.0 24 | command: ["etcd", "--advertise-client-urls", "http://etcd:2379", "--listen-client-urls", "http://0.0.0.0:2379"] 25 | ports: 26 | - "2379:2379" 27 | -------------------------------------------------------------------------------- /http-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.18 2 | WORKDIR /app 3 | COPY . . 4 | RUN go build -o main 5 | EXPOSE 8080 6 | CMD ["./main"] 7 | -------------------------------------------------------------------------------- /http-server/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/TikTokTechImmersion/assignment_demo_2023/http-server 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/apache/thrift v0.13.0 7 | github.com/cloudwego/hertz v0.6.1 8 | github.com/cloudwego/kitex v0.5.2 9 | github.com/kitex-contrib/registry-etcd v0.1.0 10 | google.golang.org/protobuf v1.28.1 11 | ) 12 | 13 | require ( 14 | github.com/bytedance/go-tagexpr/v2 v2.9.2 // indirect 15 | github.com/bytedance/gopkg v0.0.0-20220817015305-b879a72dc90f // indirect 16 | github.com/bytedance/sonic v1.8.1 // indirect 17 | github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect 18 | github.com/chenzhuoyu/iasm v0.0.0-20230222070914-0b1b64b0e762 // indirect 19 | github.com/choleraehyq/pid v0.0.16 // indirect 20 | github.com/cloudwego/fastpb v0.0.4 // indirect 21 | github.com/cloudwego/frugal v0.1.6 // indirect 22 | github.com/cloudwego/netpoll v0.3.2 // indirect 23 | github.com/cloudwego/thriftgo v0.2.9 // indirect 24 | github.com/coreos/go-semver v0.3.0 // indirect 25 | github.com/coreos/go-systemd/v22 v22.3.2 // indirect 26 | github.com/fsnotify/fsnotify v1.5.4 // indirect 27 | github.com/gogo/protobuf v1.3.2 // indirect 28 | github.com/golang/protobuf v1.5.2 // indirect 29 | github.com/google/pprof v0.0.0-20220608213341-c488b8fa1db3 // indirect 30 | github.com/henrylee2cn/ameda v1.4.10 // indirect 31 | github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect 32 | github.com/jhump/protoreflect v1.8.2 // indirect 33 | github.com/json-iterator/go v1.1.12 // indirect 34 | github.com/klauspost/cpuid/v2 v2.2.4 // indirect 35 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 36 | github.com/modern-go/reflect2 v1.0.2 // indirect 37 | github.com/nyaruka/phonenumbers v1.0.55 // indirect 38 | github.com/oleiade/lane v1.0.1 // indirect 39 | github.com/sirupsen/logrus v1.8.1 // indirect 40 | github.com/smartystreets/goconvey v1.7.2 // indirect 41 | github.com/tidwall/gjson v1.13.0 // indirect 42 | github.com/tidwall/match v1.1.1 // indirect 43 | github.com/tidwall/pretty v1.2.0 // indirect 44 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 45 | go.etcd.io/etcd/api/v3 v3.5.5 // indirect 46 | go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect 47 | go.etcd.io/etcd/client/v3 v3.5.5 // indirect 48 | go.uber.org/atomic v1.8.0 // indirect 49 | go.uber.org/multierr v1.6.0 // indirect 50 | go.uber.org/zap v1.17.0 // indirect 51 | golang.org/x/arch v0.2.0 // indirect 52 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect 53 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect 54 | golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect 55 | golang.org/x/text v0.6.0 // indirect 56 | golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect 57 | google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect 58 | google.golang.org/grpc v1.41.0 // indirect 59 | gopkg.in/yaml.v3 v3.0.1 // indirect 60 | ) 61 | 62 | replace github.com/apache/thrift => github.com/apache/thrift v0.13.0 63 | -------------------------------------------------------------------------------- /http-server/kitex_gen/rpc/imservice/client.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | 3 | package imservice 4 | 5 | import ( 6 | "context" 7 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/http-server/kitex_gen/rpc" 8 | client "github.com/cloudwego/kitex/client" 9 | callopt "github.com/cloudwego/kitex/client/callopt" 10 | ) 11 | 12 | // Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. 13 | type Client interface { 14 | Send(ctx context.Context, req *rpc.SendRequest, callOptions ...callopt.Option) (r *rpc.SendResponse, err error) 15 | Pull(ctx context.Context, req *rpc.PullRequest, callOptions ...callopt.Option) (r *rpc.PullResponse, err error) 16 | } 17 | 18 | // NewClient creates a client for the service defined in IDL. 19 | func NewClient(destService string, opts ...client.Option) (Client, error) { 20 | var options []client.Option 21 | options = append(options, client.WithDestService(destService)) 22 | 23 | options = append(options, opts...) 24 | 25 | kc, err := client.NewClient(serviceInfo(), options...) 26 | if err != nil { 27 | return nil, err 28 | } 29 | return &kIMServiceClient{ 30 | kClient: newServiceClient(kc), 31 | }, nil 32 | } 33 | 34 | // MustNewClient creates a client for the service defined in IDL. It panics if any error occurs. 35 | func MustNewClient(destService string, opts ...client.Option) Client { 36 | kc, err := NewClient(destService, opts...) 37 | if err != nil { 38 | panic(err) 39 | } 40 | return kc 41 | } 42 | 43 | type kIMServiceClient struct { 44 | *kClient 45 | } 46 | 47 | func (p *kIMServiceClient) Send(ctx context.Context, req *rpc.SendRequest, callOptions ...callopt.Option) (r *rpc.SendResponse, err error) { 48 | ctx = client.NewCtxWithCallOptions(ctx, callOptions) 49 | return p.kClient.Send(ctx, req) 50 | } 51 | 52 | func (p *kIMServiceClient) Pull(ctx context.Context, req *rpc.PullRequest, callOptions ...callopt.Option) (r *rpc.PullResponse, err error) { 53 | ctx = client.NewCtxWithCallOptions(ctx, callOptions) 54 | return p.kClient.Pull(ctx, req) 55 | } 56 | -------------------------------------------------------------------------------- /http-server/kitex_gen/rpc/imservice/imservice.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | 3 | package imservice 4 | 5 | import ( 6 | "context" 7 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/http-server/kitex_gen/rpc" 8 | client "github.com/cloudwego/kitex/client" 9 | kitex "github.com/cloudwego/kitex/pkg/serviceinfo" 10 | ) 11 | 12 | func serviceInfo() *kitex.ServiceInfo { 13 | return iMServiceServiceInfo 14 | } 15 | 16 | var iMServiceServiceInfo = NewServiceInfo() 17 | 18 | func NewServiceInfo() *kitex.ServiceInfo { 19 | serviceName := "IMService" 20 | handlerType := (*rpc.IMService)(nil) 21 | methods := map[string]kitex.MethodInfo{ 22 | "Send": kitex.NewMethodInfo(sendHandler, newIMServiceSendArgs, newIMServiceSendResult, false), 23 | "Pull": kitex.NewMethodInfo(pullHandler, newIMServicePullArgs, newIMServicePullResult, false), 24 | } 25 | extra := map[string]interface{}{ 26 | "PackageName": "rpc", 27 | } 28 | svcInfo := &kitex.ServiceInfo{ 29 | ServiceName: serviceName, 30 | HandlerType: handlerType, 31 | Methods: methods, 32 | PayloadCodec: kitex.Thrift, 33 | KiteXGenVersion: "v0.5.2", 34 | Extra: extra, 35 | } 36 | return svcInfo 37 | } 38 | 39 | func sendHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { 40 | realArg := arg.(*rpc.IMServiceSendArgs) 41 | realResult := result.(*rpc.IMServiceSendResult) 42 | success, err := handler.(rpc.IMService).Send(ctx, realArg.Req) 43 | if err != nil { 44 | return err 45 | } 46 | realResult.Success = success 47 | return nil 48 | } 49 | func newIMServiceSendArgs() interface{} { 50 | return rpc.NewIMServiceSendArgs() 51 | } 52 | 53 | func newIMServiceSendResult() interface{} { 54 | return rpc.NewIMServiceSendResult() 55 | } 56 | 57 | func pullHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { 58 | realArg := arg.(*rpc.IMServicePullArgs) 59 | realResult := result.(*rpc.IMServicePullResult) 60 | success, err := handler.(rpc.IMService).Pull(ctx, realArg.Req) 61 | if err != nil { 62 | return err 63 | } 64 | realResult.Success = success 65 | return nil 66 | } 67 | func newIMServicePullArgs() interface{} { 68 | return rpc.NewIMServicePullArgs() 69 | } 70 | 71 | func newIMServicePullResult() interface{} { 72 | return rpc.NewIMServicePullResult() 73 | } 74 | 75 | type kClient struct { 76 | c client.Client 77 | } 78 | 79 | func newServiceClient(c client.Client) *kClient { 80 | return &kClient{ 81 | c: c, 82 | } 83 | } 84 | 85 | func (p *kClient) Send(ctx context.Context, req *rpc.SendRequest) (r *rpc.SendResponse, err error) { 86 | var _args rpc.IMServiceSendArgs 87 | _args.Req = req 88 | var _result rpc.IMServiceSendResult 89 | if err = p.c.Call(ctx, "Send", &_args, &_result); err != nil { 90 | return 91 | } 92 | return _result.GetSuccess(), nil 93 | } 94 | 95 | func (p *kClient) Pull(ctx context.Context, req *rpc.PullRequest) (r *rpc.PullResponse, err error) { 96 | var _args rpc.IMServicePullArgs 97 | _args.Req = req 98 | var _result rpc.IMServicePullResult 99 | if err = p.c.Call(ctx, "Pull", &_args, &_result); err != nil { 100 | return 101 | } 102 | return _result.GetSuccess(), nil 103 | } 104 | -------------------------------------------------------------------------------- /http-server/kitex_gen/rpc/imservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | 3 | package imservice 4 | 5 | import ( 6 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/http-server/kitex_gen/rpc" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler rpc.IMService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /http-server/kitex_gen/rpc/imservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | package imservice 3 | 4 | import ( 5 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/http-server/kitex_gen/rpc" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler rpc.IMService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /http-server/kitex_gen/rpc/k-consts.go: -------------------------------------------------------------------------------- 1 | package rpc 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /http-server/kitex_gen/rpc/k-idl_rpc.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | 3 | package rpc 4 | 5 | import ( 6 | "bytes" 7 | "fmt" 8 | "reflect" 9 | "strings" 10 | 11 | "github.com/apache/thrift/lib/go/thrift" 12 | 13 | "github.com/cloudwego/kitex/pkg/protocol/bthrift" 14 | ) 15 | 16 | // unused protection 17 | var ( 18 | _ = fmt.Formatter(nil) 19 | _ = (*bytes.Buffer)(nil) 20 | _ = (*strings.Builder)(nil) 21 | _ = reflect.Type(nil) 22 | _ = thrift.TProtocol(nil) 23 | _ = bthrift.BinaryWriter(nil) 24 | ) 25 | 26 | func (p *Message) FastRead(buf []byte) (int, error) { 27 | var err error 28 | var offset int 29 | var l int 30 | var fieldTypeId thrift.TType 31 | var fieldId int16 32 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 33 | offset += l 34 | if err != nil { 35 | goto ReadStructBeginError 36 | } 37 | 38 | for { 39 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 40 | offset += l 41 | if err != nil { 42 | goto ReadFieldBeginError 43 | } 44 | if fieldTypeId == thrift.STOP { 45 | break 46 | } 47 | switch fieldId { 48 | case 1: 49 | if fieldTypeId == thrift.STRING { 50 | l, err = p.FastReadField1(buf[offset:]) 51 | offset += l 52 | if err != nil { 53 | goto ReadFieldError 54 | } 55 | } else { 56 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 57 | offset += l 58 | if err != nil { 59 | goto SkipFieldError 60 | } 61 | } 62 | case 2: 63 | if fieldTypeId == thrift.STRING { 64 | l, err = p.FastReadField2(buf[offset:]) 65 | offset += l 66 | if err != nil { 67 | goto ReadFieldError 68 | } 69 | } else { 70 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 71 | offset += l 72 | if err != nil { 73 | goto SkipFieldError 74 | } 75 | } 76 | case 3: 77 | if fieldTypeId == thrift.STRING { 78 | l, err = p.FastReadField3(buf[offset:]) 79 | offset += l 80 | if err != nil { 81 | goto ReadFieldError 82 | } 83 | } else { 84 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 85 | offset += l 86 | if err != nil { 87 | goto SkipFieldError 88 | } 89 | } 90 | case 4: 91 | if fieldTypeId == thrift.I64 { 92 | l, err = p.FastReadField4(buf[offset:]) 93 | offset += l 94 | if err != nil { 95 | goto ReadFieldError 96 | } 97 | } else { 98 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 99 | offset += l 100 | if err != nil { 101 | goto SkipFieldError 102 | } 103 | } 104 | default: 105 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 106 | offset += l 107 | if err != nil { 108 | goto SkipFieldError 109 | } 110 | } 111 | 112 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 113 | offset += l 114 | if err != nil { 115 | goto ReadFieldEndError 116 | } 117 | } 118 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 119 | offset += l 120 | if err != nil { 121 | goto ReadStructEndError 122 | } 123 | 124 | return offset, nil 125 | ReadStructBeginError: 126 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 127 | ReadFieldBeginError: 128 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 129 | ReadFieldError: 130 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_Message[fieldId]), err) 131 | SkipFieldError: 132 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 133 | ReadFieldEndError: 134 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 135 | ReadStructEndError: 136 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 137 | } 138 | 139 | func (p *Message) FastReadField1(buf []byte) (int, error) { 140 | offset := 0 141 | 142 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 143 | return offset, err 144 | } else { 145 | offset += l 146 | 147 | p.Chat = v 148 | 149 | } 150 | return offset, nil 151 | } 152 | 153 | func (p *Message) FastReadField2(buf []byte) (int, error) { 154 | offset := 0 155 | 156 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 157 | return offset, err 158 | } else { 159 | offset += l 160 | 161 | p.Text = v 162 | 163 | } 164 | return offset, nil 165 | } 166 | 167 | func (p *Message) FastReadField3(buf []byte) (int, error) { 168 | offset := 0 169 | 170 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 171 | return offset, err 172 | } else { 173 | offset += l 174 | 175 | p.Sender = v 176 | 177 | } 178 | return offset, nil 179 | } 180 | 181 | func (p *Message) FastReadField4(buf []byte) (int, error) { 182 | offset := 0 183 | 184 | if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { 185 | return offset, err 186 | } else { 187 | offset += l 188 | 189 | p.SendTime = v 190 | 191 | } 192 | return offset, nil 193 | } 194 | 195 | // for compatibility 196 | func (p *Message) FastWrite(buf []byte) int { 197 | return 0 198 | } 199 | 200 | func (p *Message) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 201 | offset := 0 202 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Message") 203 | if p != nil { 204 | offset += p.fastWriteField4(buf[offset:], binaryWriter) 205 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 206 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 207 | offset += p.fastWriteField3(buf[offset:], binaryWriter) 208 | } 209 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 210 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 211 | return offset 212 | } 213 | 214 | func (p *Message) BLength() int { 215 | l := 0 216 | l += bthrift.Binary.StructBeginLength("Message") 217 | if p != nil { 218 | l += p.field1Length() 219 | l += p.field2Length() 220 | l += p.field3Length() 221 | l += p.field4Length() 222 | } 223 | l += bthrift.Binary.FieldStopLength() 224 | l += bthrift.Binary.StructEndLength() 225 | return l 226 | } 227 | 228 | func (p *Message) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 229 | offset := 0 230 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Chat", thrift.STRING, 1) 231 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Chat) 232 | 233 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 234 | return offset 235 | } 236 | 237 | func (p *Message) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 238 | offset := 0 239 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Text", thrift.STRING, 2) 240 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Text) 241 | 242 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 243 | return offset 244 | } 245 | 246 | func (p *Message) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { 247 | offset := 0 248 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Sender", thrift.STRING, 3) 249 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Sender) 250 | 251 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 252 | return offset 253 | } 254 | 255 | func (p *Message) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { 256 | offset := 0 257 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "SendTime", thrift.I64, 4) 258 | offset += bthrift.Binary.WriteI64(buf[offset:], p.SendTime) 259 | 260 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 261 | return offset 262 | } 263 | 264 | func (p *Message) field1Length() int { 265 | l := 0 266 | l += bthrift.Binary.FieldBeginLength("Chat", thrift.STRING, 1) 267 | l += bthrift.Binary.StringLengthNocopy(p.Chat) 268 | 269 | l += bthrift.Binary.FieldEndLength() 270 | return l 271 | } 272 | 273 | func (p *Message) field2Length() int { 274 | l := 0 275 | l += bthrift.Binary.FieldBeginLength("Text", thrift.STRING, 2) 276 | l += bthrift.Binary.StringLengthNocopy(p.Text) 277 | 278 | l += bthrift.Binary.FieldEndLength() 279 | return l 280 | } 281 | 282 | func (p *Message) field3Length() int { 283 | l := 0 284 | l += bthrift.Binary.FieldBeginLength("Sender", thrift.STRING, 3) 285 | l += bthrift.Binary.StringLengthNocopy(p.Sender) 286 | 287 | l += bthrift.Binary.FieldEndLength() 288 | return l 289 | } 290 | 291 | func (p *Message) field4Length() int { 292 | l := 0 293 | l += bthrift.Binary.FieldBeginLength("SendTime", thrift.I64, 4) 294 | l += bthrift.Binary.I64Length(p.SendTime) 295 | 296 | l += bthrift.Binary.FieldEndLength() 297 | return l 298 | } 299 | 300 | func (p *SendRequest) FastRead(buf []byte) (int, error) { 301 | var err error 302 | var offset int 303 | var l int 304 | var fieldTypeId thrift.TType 305 | var fieldId int16 306 | var issetMessage bool = false 307 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 308 | offset += l 309 | if err != nil { 310 | goto ReadStructBeginError 311 | } 312 | 313 | for { 314 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 315 | offset += l 316 | if err != nil { 317 | goto ReadFieldBeginError 318 | } 319 | if fieldTypeId == thrift.STOP { 320 | break 321 | } 322 | switch fieldId { 323 | case 1: 324 | if fieldTypeId == thrift.STRUCT { 325 | l, err = p.FastReadField1(buf[offset:]) 326 | offset += l 327 | if err != nil { 328 | goto ReadFieldError 329 | } 330 | issetMessage = true 331 | } else { 332 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 333 | offset += l 334 | if err != nil { 335 | goto SkipFieldError 336 | } 337 | } 338 | default: 339 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 340 | offset += l 341 | if err != nil { 342 | goto SkipFieldError 343 | } 344 | } 345 | 346 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 347 | offset += l 348 | if err != nil { 349 | goto ReadFieldEndError 350 | } 351 | } 352 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 353 | offset += l 354 | if err != nil { 355 | goto ReadStructEndError 356 | } 357 | 358 | if !issetMessage { 359 | fieldId = 1 360 | goto RequiredFieldNotSetError 361 | } 362 | return offset, nil 363 | ReadStructBeginError: 364 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 365 | ReadFieldBeginError: 366 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 367 | ReadFieldError: 368 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_SendRequest[fieldId]), err) 369 | SkipFieldError: 370 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 371 | ReadFieldEndError: 372 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 373 | ReadStructEndError: 374 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 375 | RequiredFieldNotSetError: 376 | return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_SendRequest[fieldId])) 377 | } 378 | 379 | func (p *SendRequest) FastReadField1(buf []byte) (int, error) { 380 | offset := 0 381 | 382 | tmp := NewMessage() 383 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 384 | return offset, err 385 | } else { 386 | offset += l 387 | } 388 | p.Message = tmp 389 | return offset, nil 390 | } 391 | 392 | // for compatibility 393 | func (p *SendRequest) FastWrite(buf []byte) int { 394 | return 0 395 | } 396 | 397 | func (p *SendRequest) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 398 | offset := 0 399 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "SendRequest") 400 | if p != nil { 401 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 402 | } 403 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 404 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 405 | return offset 406 | } 407 | 408 | func (p *SendRequest) BLength() int { 409 | l := 0 410 | l += bthrift.Binary.StructBeginLength("SendRequest") 411 | if p != nil { 412 | l += p.field1Length() 413 | } 414 | l += bthrift.Binary.FieldStopLength() 415 | l += bthrift.Binary.StructEndLength() 416 | return l 417 | } 418 | 419 | func (p *SendRequest) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 420 | offset := 0 421 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRUCT, 1) 422 | offset += p.Message.FastWriteNocopy(buf[offset:], binaryWriter) 423 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 424 | return offset 425 | } 426 | 427 | func (p *SendRequest) field1Length() int { 428 | l := 0 429 | l += bthrift.Binary.FieldBeginLength("message", thrift.STRUCT, 1) 430 | l += p.Message.BLength() 431 | l += bthrift.Binary.FieldEndLength() 432 | return l 433 | } 434 | 435 | func (p *SendResponse) FastRead(buf []byte) (int, error) { 436 | var err error 437 | var offset int 438 | var l int 439 | var fieldTypeId thrift.TType 440 | var fieldId int16 441 | var issetCode bool = false 442 | var issetMsg bool = false 443 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 444 | offset += l 445 | if err != nil { 446 | goto ReadStructBeginError 447 | } 448 | 449 | for { 450 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 451 | offset += l 452 | if err != nil { 453 | goto ReadFieldBeginError 454 | } 455 | if fieldTypeId == thrift.STOP { 456 | break 457 | } 458 | switch fieldId { 459 | case 1: 460 | if fieldTypeId == thrift.I32 { 461 | l, err = p.FastReadField1(buf[offset:]) 462 | offset += l 463 | if err != nil { 464 | goto ReadFieldError 465 | } 466 | issetCode = true 467 | } else { 468 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 469 | offset += l 470 | if err != nil { 471 | goto SkipFieldError 472 | } 473 | } 474 | case 2: 475 | if fieldTypeId == thrift.STRING { 476 | l, err = p.FastReadField2(buf[offset:]) 477 | offset += l 478 | if err != nil { 479 | goto ReadFieldError 480 | } 481 | issetMsg = true 482 | } else { 483 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 484 | offset += l 485 | if err != nil { 486 | goto SkipFieldError 487 | } 488 | } 489 | default: 490 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 491 | offset += l 492 | if err != nil { 493 | goto SkipFieldError 494 | } 495 | } 496 | 497 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 498 | offset += l 499 | if err != nil { 500 | goto ReadFieldEndError 501 | } 502 | } 503 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 504 | offset += l 505 | if err != nil { 506 | goto ReadStructEndError 507 | } 508 | 509 | if !issetCode { 510 | fieldId = 1 511 | goto RequiredFieldNotSetError 512 | } 513 | 514 | if !issetMsg { 515 | fieldId = 2 516 | goto RequiredFieldNotSetError 517 | } 518 | return offset, nil 519 | ReadStructBeginError: 520 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 521 | ReadFieldBeginError: 522 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 523 | ReadFieldError: 524 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_SendResponse[fieldId]), err) 525 | SkipFieldError: 526 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 527 | ReadFieldEndError: 528 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 529 | ReadStructEndError: 530 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 531 | RequiredFieldNotSetError: 532 | return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_SendResponse[fieldId])) 533 | } 534 | 535 | func (p *SendResponse) FastReadField1(buf []byte) (int, error) { 536 | offset := 0 537 | 538 | if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { 539 | return offset, err 540 | } else { 541 | offset += l 542 | 543 | p.Code = v 544 | 545 | } 546 | return offset, nil 547 | } 548 | 549 | func (p *SendResponse) FastReadField2(buf []byte) (int, error) { 550 | offset := 0 551 | 552 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 553 | return offset, err 554 | } else { 555 | offset += l 556 | 557 | p.Msg = v 558 | 559 | } 560 | return offset, nil 561 | } 562 | 563 | // for compatibility 564 | func (p *SendResponse) FastWrite(buf []byte) int { 565 | return 0 566 | } 567 | 568 | func (p *SendResponse) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 569 | offset := 0 570 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "SendResponse") 571 | if p != nil { 572 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 573 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 574 | } 575 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 576 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 577 | return offset 578 | } 579 | 580 | func (p *SendResponse) BLength() int { 581 | l := 0 582 | l += bthrift.Binary.StructBeginLength("SendResponse") 583 | if p != nil { 584 | l += p.field1Length() 585 | l += p.field2Length() 586 | } 587 | l += bthrift.Binary.FieldStopLength() 588 | l += bthrift.Binary.StructEndLength() 589 | return l 590 | } 591 | 592 | func (p *SendResponse) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 593 | offset := 0 594 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Code", thrift.I32, 1) 595 | offset += bthrift.Binary.WriteI32(buf[offset:], p.Code) 596 | 597 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 598 | return offset 599 | } 600 | 601 | func (p *SendResponse) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 602 | offset := 0 603 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Msg", thrift.STRING, 2) 604 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Msg) 605 | 606 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 607 | return offset 608 | } 609 | 610 | func (p *SendResponse) field1Length() int { 611 | l := 0 612 | l += bthrift.Binary.FieldBeginLength("Code", thrift.I32, 1) 613 | l += bthrift.Binary.I32Length(p.Code) 614 | 615 | l += bthrift.Binary.FieldEndLength() 616 | return l 617 | } 618 | 619 | func (p *SendResponse) field2Length() int { 620 | l := 0 621 | l += bthrift.Binary.FieldBeginLength("Msg", thrift.STRING, 2) 622 | l += bthrift.Binary.StringLengthNocopy(p.Msg) 623 | 624 | l += bthrift.Binary.FieldEndLength() 625 | return l 626 | } 627 | 628 | func (p *PullRequest) FastRead(buf []byte) (int, error) { 629 | var err error 630 | var offset int 631 | var l int 632 | var fieldTypeId thrift.TType 633 | var fieldId int16 634 | var issetChat bool = false 635 | var issetCursor bool = false 636 | var issetLimit bool = false 637 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 638 | offset += l 639 | if err != nil { 640 | goto ReadStructBeginError 641 | } 642 | 643 | for { 644 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 645 | offset += l 646 | if err != nil { 647 | goto ReadFieldBeginError 648 | } 649 | if fieldTypeId == thrift.STOP { 650 | break 651 | } 652 | switch fieldId { 653 | case 1: 654 | if fieldTypeId == thrift.STRING { 655 | l, err = p.FastReadField1(buf[offset:]) 656 | offset += l 657 | if err != nil { 658 | goto ReadFieldError 659 | } 660 | issetChat = true 661 | } else { 662 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 663 | offset += l 664 | if err != nil { 665 | goto SkipFieldError 666 | } 667 | } 668 | case 2: 669 | if fieldTypeId == thrift.I64 { 670 | l, err = p.FastReadField2(buf[offset:]) 671 | offset += l 672 | if err != nil { 673 | goto ReadFieldError 674 | } 675 | issetCursor = true 676 | } else { 677 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 678 | offset += l 679 | if err != nil { 680 | goto SkipFieldError 681 | } 682 | } 683 | case 3: 684 | if fieldTypeId == thrift.I32 { 685 | l, err = p.FastReadField3(buf[offset:]) 686 | offset += l 687 | if err != nil { 688 | goto ReadFieldError 689 | } 690 | issetLimit = true 691 | } else { 692 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 693 | offset += l 694 | if err != nil { 695 | goto SkipFieldError 696 | } 697 | } 698 | case 4: 699 | if fieldTypeId == thrift.BOOL { 700 | l, err = p.FastReadField4(buf[offset:]) 701 | offset += l 702 | if err != nil { 703 | goto ReadFieldError 704 | } 705 | } else { 706 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 707 | offset += l 708 | if err != nil { 709 | goto SkipFieldError 710 | } 711 | } 712 | default: 713 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 714 | offset += l 715 | if err != nil { 716 | goto SkipFieldError 717 | } 718 | } 719 | 720 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 721 | offset += l 722 | if err != nil { 723 | goto ReadFieldEndError 724 | } 725 | } 726 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 727 | offset += l 728 | if err != nil { 729 | goto ReadStructEndError 730 | } 731 | 732 | if !issetChat { 733 | fieldId = 1 734 | goto RequiredFieldNotSetError 735 | } 736 | 737 | if !issetCursor { 738 | fieldId = 2 739 | goto RequiredFieldNotSetError 740 | } 741 | 742 | if !issetLimit { 743 | fieldId = 3 744 | goto RequiredFieldNotSetError 745 | } 746 | return offset, nil 747 | ReadStructBeginError: 748 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 749 | ReadFieldBeginError: 750 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 751 | ReadFieldError: 752 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PullRequest[fieldId]), err) 753 | SkipFieldError: 754 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 755 | ReadFieldEndError: 756 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 757 | ReadStructEndError: 758 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 759 | RequiredFieldNotSetError: 760 | return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_PullRequest[fieldId])) 761 | } 762 | 763 | func (p *PullRequest) FastReadField1(buf []byte) (int, error) { 764 | offset := 0 765 | 766 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 767 | return offset, err 768 | } else { 769 | offset += l 770 | 771 | p.Chat = v 772 | 773 | } 774 | return offset, nil 775 | } 776 | 777 | func (p *PullRequest) FastReadField2(buf []byte) (int, error) { 778 | offset := 0 779 | 780 | if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { 781 | return offset, err 782 | } else { 783 | offset += l 784 | 785 | p.Cursor = v 786 | 787 | } 788 | return offset, nil 789 | } 790 | 791 | func (p *PullRequest) FastReadField3(buf []byte) (int, error) { 792 | offset := 0 793 | 794 | if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { 795 | return offset, err 796 | } else { 797 | offset += l 798 | 799 | p.Limit = v 800 | 801 | } 802 | return offset, nil 803 | } 804 | 805 | func (p *PullRequest) FastReadField4(buf []byte) (int, error) { 806 | offset := 0 807 | 808 | if v, l, err := bthrift.Binary.ReadBool(buf[offset:]); err != nil { 809 | return offset, err 810 | } else { 811 | offset += l 812 | p.Reverse = &v 813 | 814 | } 815 | return offset, nil 816 | } 817 | 818 | // for compatibility 819 | func (p *PullRequest) FastWrite(buf []byte) int { 820 | return 0 821 | } 822 | 823 | func (p *PullRequest) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 824 | offset := 0 825 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "PullRequest") 826 | if p != nil { 827 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 828 | offset += p.fastWriteField3(buf[offset:], binaryWriter) 829 | offset += p.fastWriteField4(buf[offset:], binaryWriter) 830 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 831 | } 832 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 833 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 834 | return offset 835 | } 836 | 837 | func (p *PullRequest) BLength() int { 838 | l := 0 839 | l += bthrift.Binary.StructBeginLength("PullRequest") 840 | if p != nil { 841 | l += p.field1Length() 842 | l += p.field2Length() 843 | l += p.field3Length() 844 | l += p.field4Length() 845 | } 846 | l += bthrift.Binary.FieldStopLength() 847 | l += bthrift.Binary.StructEndLength() 848 | return l 849 | } 850 | 851 | func (p *PullRequest) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 852 | offset := 0 853 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Chat", thrift.STRING, 1) 854 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Chat) 855 | 856 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 857 | return offset 858 | } 859 | 860 | func (p *PullRequest) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 861 | offset := 0 862 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Cursor", thrift.I64, 2) 863 | offset += bthrift.Binary.WriteI64(buf[offset:], p.Cursor) 864 | 865 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 866 | return offset 867 | } 868 | 869 | func (p *PullRequest) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { 870 | offset := 0 871 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Limit", thrift.I32, 3) 872 | offset += bthrift.Binary.WriteI32(buf[offset:], p.Limit) 873 | 874 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 875 | return offset 876 | } 877 | 878 | func (p *PullRequest) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { 879 | offset := 0 880 | if p.IsSetReverse() { 881 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Reverse", thrift.BOOL, 4) 882 | offset += bthrift.Binary.WriteBool(buf[offset:], *p.Reverse) 883 | 884 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 885 | } 886 | return offset 887 | } 888 | 889 | func (p *PullRequest) field1Length() int { 890 | l := 0 891 | l += bthrift.Binary.FieldBeginLength("Chat", thrift.STRING, 1) 892 | l += bthrift.Binary.StringLengthNocopy(p.Chat) 893 | 894 | l += bthrift.Binary.FieldEndLength() 895 | return l 896 | } 897 | 898 | func (p *PullRequest) field2Length() int { 899 | l := 0 900 | l += bthrift.Binary.FieldBeginLength("Cursor", thrift.I64, 2) 901 | l += bthrift.Binary.I64Length(p.Cursor) 902 | 903 | l += bthrift.Binary.FieldEndLength() 904 | return l 905 | } 906 | 907 | func (p *PullRequest) field3Length() int { 908 | l := 0 909 | l += bthrift.Binary.FieldBeginLength("Limit", thrift.I32, 3) 910 | l += bthrift.Binary.I32Length(p.Limit) 911 | 912 | l += bthrift.Binary.FieldEndLength() 913 | return l 914 | } 915 | 916 | func (p *PullRequest) field4Length() int { 917 | l := 0 918 | if p.IsSetReverse() { 919 | l += bthrift.Binary.FieldBeginLength("Reverse", thrift.BOOL, 4) 920 | l += bthrift.Binary.BoolLength(*p.Reverse) 921 | 922 | l += bthrift.Binary.FieldEndLength() 923 | } 924 | return l 925 | } 926 | 927 | func (p *PullResponse) FastRead(buf []byte) (int, error) { 928 | var err error 929 | var offset int 930 | var l int 931 | var fieldTypeId thrift.TType 932 | var fieldId int16 933 | var issetCode bool = false 934 | var issetMsg bool = false 935 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 936 | offset += l 937 | if err != nil { 938 | goto ReadStructBeginError 939 | } 940 | 941 | for { 942 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 943 | offset += l 944 | if err != nil { 945 | goto ReadFieldBeginError 946 | } 947 | if fieldTypeId == thrift.STOP { 948 | break 949 | } 950 | switch fieldId { 951 | case 1: 952 | if fieldTypeId == thrift.I32 { 953 | l, err = p.FastReadField1(buf[offset:]) 954 | offset += l 955 | if err != nil { 956 | goto ReadFieldError 957 | } 958 | issetCode = true 959 | } else { 960 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 961 | offset += l 962 | if err != nil { 963 | goto SkipFieldError 964 | } 965 | } 966 | case 2: 967 | if fieldTypeId == thrift.STRING { 968 | l, err = p.FastReadField2(buf[offset:]) 969 | offset += l 970 | if err != nil { 971 | goto ReadFieldError 972 | } 973 | issetMsg = true 974 | } else { 975 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 976 | offset += l 977 | if err != nil { 978 | goto SkipFieldError 979 | } 980 | } 981 | case 3: 982 | if fieldTypeId == thrift.LIST { 983 | l, err = p.FastReadField3(buf[offset:]) 984 | offset += l 985 | if err != nil { 986 | goto ReadFieldError 987 | } 988 | } else { 989 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 990 | offset += l 991 | if err != nil { 992 | goto SkipFieldError 993 | } 994 | } 995 | case 4: 996 | if fieldTypeId == thrift.BOOL { 997 | l, err = p.FastReadField4(buf[offset:]) 998 | offset += l 999 | if err != nil { 1000 | goto ReadFieldError 1001 | } 1002 | } else { 1003 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1004 | offset += l 1005 | if err != nil { 1006 | goto SkipFieldError 1007 | } 1008 | } 1009 | case 5: 1010 | if fieldTypeId == thrift.I64 { 1011 | l, err = p.FastReadField5(buf[offset:]) 1012 | offset += l 1013 | if err != nil { 1014 | goto ReadFieldError 1015 | } 1016 | } else { 1017 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1018 | offset += l 1019 | if err != nil { 1020 | goto SkipFieldError 1021 | } 1022 | } 1023 | default: 1024 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1025 | offset += l 1026 | if err != nil { 1027 | goto SkipFieldError 1028 | } 1029 | } 1030 | 1031 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1032 | offset += l 1033 | if err != nil { 1034 | goto ReadFieldEndError 1035 | } 1036 | } 1037 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1038 | offset += l 1039 | if err != nil { 1040 | goto ReadStructEndError 1041 | } 1042 | 1043 | if !issetCode { 1044 | fieldId = 1 1045 | goto RequiredFieldNotSetError 1046 | } 1047 | 1048 | if !issetMsg { 1049 | fieldId = 2 1050 | goto RequiredFieldNotSetError 1051 | } 1052 | return offset, nil 1053 | ReadStructBeginError: 1054 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1055 | ReadFieldBeginError: 1056 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1057 | ReadFieldError: 1058 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PullResponse[fieldId]), err) 1059 | SkipFieldError: 1060 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1061 | ReadFieldEndError: 1062 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1063 | ReadStructEndError: 1064 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1065 | RequiredFieldNotSetError: 1066 | return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_PullResponse[fieldId])) 1067 | } 1068 | 1069 | func (p *PullResponse) FastReadField1(buf []byte) (int, error) { 1070 | offset := 0 1071 | 1072 | if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { 1073 | return offset, err 1074 | } else { 1075 | offset += l 1076 | 1077 | p.Code = v 1078 | 1079 | } 1080 | return offset, nil 1081 | } 1082 | 1083 | func (p *PullResponse) FastReadField2(buf []byte) (int, error) { 1084 | offset := 0 1085 | 1086 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 1087 | return offset, err 1088 | } else { 1089 | offset += l 1090 | 1091 | p.Msg = v 1092 | 1093 | } 1094 | return offset, nil 1095 | } 1096 | 1097 | func (p *PullResponse) FastReadField3(buf []byte) (int, error) { 1098 | offset := 0 1099 | 1100 | _, size, l, err := bthrift.Binary.ReadListBegin(buf[offset:]) 1101 | offset += l 1102 | if err != nil { 1103 | return offset, err 1104 | } 1105 | p.Messages = make([]*Message, 0, size) 1106 | for i := 0; i < size; i++ { 1107 | _elem := NewMessage() 1108 | if l, err := _elem.FastRead(buf[offset:]); err != nil { 1109 | return offset, err 1110 | } else { 1111 | offset += l 1112 | } 1113 | 1114 | p.Messages = append(p.Messages, _elem) 1115 | } 1116 | if l, err := bthrift.Binary.ReadListEnd(buf[offset:]); err != nil { 1117 | return offset, err 1118 | } else { 1119 | offset += l 1120 | } 1121 | return offset, nil 1122 | } 1123 | 1124 | func (p *PullResponse) FastReadField4(buf []byte) (int, error) { 1125 | offset := 0 1126 | 1127 | if v, l, err := bthrift.Binary.ReadBool(buf[offset:]); err != nil { 1128 | return offset, err 1129 | } else { 1130 | offset += l 1131 | p.HasMore = &v 1132 | 1133 | } 1134 | return offset, nil 1135 | } 1136 | 1137 | func (p *PullResponse) FastReadField5(buf []byte) (int, error) { 1138 | offset := 0 1139 | 1140 | if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { 1141 | return offset, err 1142 | } else { 1143 | offset += l 1144 | p.NextCursor = &v 1145 | 1146 | } 1147 | return offset, nil 1148 | } 1149 | 1150 | // for compatibility 1151 | func (p *PullResponse) FastWrite(buf []byte) int { 1152 | return 0 1153 | } 1154 | 1155 | func (p *PullResponse) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1156 | offset := 0 1157 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "PullResponse") 1158 | if p != nil { 1159 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 1160 | offset += p.fastWriteField4(buf[offset:], binaryWriter) 1161 | offset += p.fastWriteField5(buf[offset:], binaryWriter) 1162 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 1163 | offset += p.fastWriteField3(buf[offset:], binaryWriter) 1164 | } 1165 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1166 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1167 | return offset 1168 | } 1169 | 1170 | func (p *PullResponse) BLength() int { 1171 | l := 0 1172 | l += bthrift.Binary.StructBeginLength("PullResponse") 1173 | if p != nil { 1174 | l += p.field1Length() 1175 | l += p.field2Length() 1176 | l += p.field3Length() 1177 | l += p.field4Length() 1178 | l += p.field5Length() 1179 | } 1180 | l += bthrift.Binary.FieldStopLength() 1181 | l += bthrift.Binary.StructEndLength() 1182 | return l 1183 | } 1184 | 1185 | func (p *PullResponse) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1186 | offset := 0 1187 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Code", thrift.I32, 1) 1188 | offset += bthrift.Binary.WriteI32(buf[offset:], p.Code) 1189 | 1190 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1191 | return offset 1192 | } 1193 | 1194 | func (p *PullResponse) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1195 | offset := 0 1196 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Msg", thrift.STRING, 2) 1197 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Msg) 1198 | 1199 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1200 | return offset 1201 | } 1202 | 1203 | func (p *PullResponse) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1204 | offset := 0 1205 | if p.IsSetMessages() { 1206 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Messages", thrift.LIST, 3) 1207 | listBeginOffset := offset 1208 | offset += bthrift.Binary.ListBeginLength(thrift.STRUCT, 0) 1209 | var length int 1210 | for _, v := range p.Messages { 1211 | length++ 1212 | offset += v.FastWriteNocopy(buf[offset:], binaryWriter) 1213 | } 1214 | bthrift.Binary.WriteListBegin(buf[listBeginOffset:], thrift.STRUCT, length) 1215 | offset += bthrift.Binary.WriteListEnd(buf[offset:]) 1216 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1217 | } 1218 | return offset 1219 | } 1220 | 1221 | func (p *PullResponse) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1222 | offset := 0 1223 | if p.IsSetHasMore() { 1224 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "HasMore", thrift.BOOL, 4) 1225 | offset += bthrift.Binary.WriteBool(buf[offset:], *p.HasMore) 1226 | 1227 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1228 | } 1229 | return offset 1230 | } 1231 | 1232 | func (p *PullResponse) fastWriteField5(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1233 | offset := 0 1234 | if p.IsSetNextCursor() { 1235 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "NextCursor", thrift.I64, 5) 1236 | offset += bthrift.Binary.WriteI64(buf[offset:], *p.NextCursor) 1237 | 1238 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1239 | } 1240 | return offset 1241 | } 1242 | 1243 | func (p *PullResponse) field1Length() int { 1244 | l := 0 1245 | l += bthrift.Binary.FieldBeginLength("Code", thrift.I32, 1) 1246 | l += bthrift.Binary.I32Length(p.Code) 1247 | 1248 | l += bthrift.Binary.FieldEndLength() 1249 | return l 1250 | } 1251 | 1252 | func (p *PullResponse) field2Length() int { 1253 | l := 0 1254 | l += bthrift.Binary.FieldBeginLength("Msg", thrift.STRING, 2) 1255 | l += bthrift.Binary.StringLengthNocopy(p.Msg) 1256 | 1257 | l += bthrift.Binary.FieldEndLength() 1258 | return l 1259 | } 1260 | 1261 | func (p *PullResponse) field3Length() int { 1262 | l := 0 1263 | if p.IsSetMessages() { 1264 | l += bthrift.Binary.FieldBeginLength("Messages", thrift.LIST, 3) 1265 | l += bthrift.Binary.ListBeginLength(thrift.STRUCT, len(p.Messages)) 1266 | for _, v := range p.Messages { 1267 | l += v.BLength() 1268 | } 1269 | l += bthrift.Binary.ListEndLength() 1270 | l += bthrift.Binary.FieldEndLength() 1271 | } 1272 | return l 1273 | } 1274 | 1275 | func (p *PullResponse) field4Length() int { 1276 | l := 0 1277 | if p.IsSetHasMore() { 1278 | l += bthrift.Binary.FieldBeginLength("HasMore", thrift.BOOL, 4) 1279 | l += bthrift.Binary.BoolLength(*p.HasMore) 1280 | 1281 | l += bthrift.Binary.FieldEndLength() 1282 | } 1283 | return l 1284 | } 1285 | 1286 | func (p *PullResponse) field5Length() int { 1287 | l := 0 1288 | if p.IsSetNextCursor() { 1289 | l += bthrift.Binary.FieldBeginLength("NextCursor", thrift.I64, 5) 1290 | l += bthrift.Binary.I64Length(*p.NextCursor) 1291 | 1292 | l += bthrift.Binary.FieldEndLength() 1293 | } 1294 | return l 1295 | } 1296 | 1297 | func (p *IMServiceSendArgs) FastRead(buf []byte) (int, error) { 1298 | var err error 1299 | var offset int 1300 | var l int 1301 | var fieldTypeId thrift.TType 1302 | var fieldId int16 1303 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 1304 | offset += l 1305 | if err != nil { 1306 | goto ReadStructBeginError 1307 | } 1308 | 1309 | for { 1310 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 1311 | offset += l 1312 | if err != nil { 1313 | goto ReadFieldBeginError 1314 | } 1315 | if fieldTypeId == thrift.STOP { 1316 | break 1317 | } 1318 | switch fieldId { 1319 | case 1: 1320 | if fieldTypeId == thrift.STRUCT { 1321 | l, err = p.FastReadField1(buf[offset:]) 1322 | offset += l 1323 | if err != nil { 1324 | goto ReadFieldError 1325 | } 1326 | } else { 1327 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1328 | offset += l 1329 | if err != nil { 1330 | goto SkipFieldError 1331 | } 1332 | } 1333 | default: 1334 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1335 | offset += l 1336 | if err != nil { 1337 | goto SkipFieldError 1338 | } 1339 | } 1340 | 1341 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1342 | offset += l 1343 | if err != nil { 1344 | goto ReadFieldEndError 1345 | } 1346 | } 1347 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1348 | offset += l 1349 | if err != nil { 1350 | goto ReadStructEndError 1351 | } 1352 | 1353 | return offset, nil 1354 | ReadStructBeginError: 1355 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1356 | ReadFieldBeginError: 1357 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1358 | ReadFieldError: 1359 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IMServiceSendArgs[fieldId]), err) 1360 | SkipFieldError: 1361 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1362 | ReadFieldEndError: 1363 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1364 | ReadStructEndError: 1365 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1366 | } 1367 | 1368 | func (p *IMServiceSendArgs) FastReadField1(buf []byte) (int, error) { 1369 | offset := 0 1370 | 1371 | tmp := NewSendRequest() 1372 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 1373 | return offset, err 1374 | } else { 1375 | offset += l 1376 | } 1377 | p.Req = tmp 1378 | return offset, nil 1379 | } 1380 | 1381 | // for compatibility 1382 | func (p *IMServiceSendArgs) FastWrite(buf []byte) int { 1383 | return 0 1384 | } 1385 | 1386 | func (p *IMServiceSendArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1387 | offset := 0 1388 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Send_args") 1389 | if p != nil { 1390 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 1391 | } 1392 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1393 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1394 | return offset 1395 | } 1396 | 1397 | func (p *IMServiceSendArgs) BLength() int { 1398 | l := 0 1399 | l += bthrift.Binary.StructBeginLength("Send_args") 1400 | if p != nil { 1401 | l += p.field1Length() 1402 | } 1403 | l += bthrift.Binary.FieldStopLength() 1404 | l += bthrift.Binary.StructEndLength() 1405 | return l 1406 | } 1407 | 1408 | func (p *IMServiceSendArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1409 | offset := 0 1410 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req", thrift.STRUCT, 1) 1411 | offset += p.Req.FastWriteNocopy(buf[offset:], binaryWriter) 1412 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1413 | return offset 1414 | } 1415 | 1416 | func (p *IMServiceSendArgs) field1Length() int { 1417 | l := 0 1418 | l += bthrift.Binary.FieldBeginLength("req", thrift.STRUCT, 1) 1419 | l += p.Req.BLength() 1420 | l += bthrift.Binary.FieldEndLength() 1421 | return l 1422 | } 1423 | 1424 | func (p *IMServiceSendResult) FastRead(buf []byte) (int, error) { 1425 | var err error 1426 | var offset int 1427 | var l int 1428 | var fieldTypeId thrift.TType 1429 | var fieldId int16 1430 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 1431 | offset += l 1432 | if err != nil { 1433 | goto ReadStructBeginError 1434 | } 1435 | 1436 | for { 1437 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 1438 | offset += l 1439 | if err != nil { 1440 | goto ReadFieldBeginError 1441 | } 1442 | if fieldTypeId == thrift.STOP { 1443 | break 1444 | } 1445 | switch fieldId { 1446 | case 0: 1447 | if fieldTypeId == thrift.STRUCT { 1448 | l, err = p.FastReadField0(buf[offset:]) 1449 | offset += l 1450 | if err != nil { 1451 | goto ReadFieldError 1452 | } 1453 | } else { 1454 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1455 | offset += l 1456 | if err != nil { 1457 | goto SkipFieldError 1458 | } 1459 | } 1460 | default: 1461 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1462 | offset += l 1463 | if err != nil { 1464 | goto SkipFieldError 1465 | } 1466 | } 1467 | 1468 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1469 | offset += l 1470 | if err != nil { 1471 | goto ReadFieldEndError 1472 | } 1473 | } 1474 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1475 | offset += l 1476 | if err != nil { 1477 | goto ReadStructEndError 1478 | } 1479 | 1480 | return offset, nil 1481 | ReadStructBeginError: 1482 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1483 | ReadFieldBeginError: 1484 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1485 | ReadFieldError: 1486 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IMServiceSendResult[fieldId]), err) 1487 | SkipFieldError: 1488 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1489 | ReadFieldEndError: 1490 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1491 | ReadStructEndError: 1492 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1493 | } 1494 | 1495 | func (p *IMServiceSendResult) FastReadField0(buf []byte) (int, error) { 1496 | offset := 0 1497 | 1498 | tmp := NewSendResponse() 1499 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 1500 | return offset, err 1501 | } else { 1502 | offset += l 1503 | } 1504 | p.Success = tmp 1505 | return offset, nil 1506 | } 1507 | 1508 | // for compatibility 1509 | func (p *IMServiceSendResult) FastWrite(buf []byte) int { 1510 | return 0 1511 | } 1512 | 1513 | func (p *IMServiceSendResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1514 | offset := 0 1515 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Send_result") 1516 | if p != nil { 1517 | offset += p.fastWriteField0(buf[offset:], binaryWriter) 1518 | } 1519 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1520 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1521 | return offset 1522 | } 1523 | 1524 | func (p *IMServiceSendResult) BLength() int { 1525 | l := 0 1526 | l += bthrift.Binary.StructBeginLength("Send_result") 1527 | if p != nil { 1528 | l += p.field0Length() 1529 | } 1530 | l += bthrift.Binary.FieldStopLength() 1531 | l += bthrift.Binary.StructEndLength() 1532 | return l 1533 | } 1534 | 1535 | func (p *IMServiceSendResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1536 | offset := 0 1537 | if p.IsSetSuccess() { 1538 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) 1539 | offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) 1540 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1541 | } 1542 | return offset 1543 | } 1544 | 1545 | func (p *IMServiceSendResult) field0Length() int { 1546 | l := 0 1547 | if p.IsSetSuccess() { 1548 | l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) 1549 | l += p.Success.BLength() 1550 | l += bthrift.Binary.FieldEndLength() 1551 | } 1552 | return l 1553 | } 1554 | 1555 | func (p *IMServicePullArgs) FastRead(buf []byte) (int, error) { 1556 | var err error 1557 | var offset int 1558 | var l int 1559 | var fieldTypeId thrift.TType 1560 | var fieldId int16 1561 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 1562 | offset += l 1563 | if err != nil { 1564 | goto ReadStructBeginError 1565 | } 1566 | 1567 | for { 1568 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 1569 | offset += l 1570 | if err != nil { 1571 | goto ReadFieldBeginError 1572 | } 1573 | if fieldTypeId == thrift.STOP { 1574 | break 1575 | } 1576 | switch fieldId { 1577 | case 2: 1578 | if fieldTypeId == thrift.STRUCT { 1579 | l, err = p.FastReadField2(buf[offset:]) 1580 | offset += l 1581 | if err != nil { 1582 | goto ReadFieldError 1583 | } 1584 | } else { 1585 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1586 | offset += l 1587 | if err != nil { 1588 | goto SkipFieldError 1589 | } 1590 | } 1591 | default: 1592 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1593 | offset += l 1594 | if err != nil { 1595 | goto SkipFieldError 1596 | } 1597 | } 1598 | 1599 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1600 | offset += l 1601 | if err != nil { 1602 | goto ReadFieldEndError 1603 | } 1604 | } 1605 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1606 | offset += l 1607 | if err != nil { 1608 | goto ReadStructEndError 1609 | } 1610 | 1611 | return offset, nil 1612 | ReadStructBeginError: 1613 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1614 | ReadFieldBeginError: 1615 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1616 | ReadFieldError: 1617 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IMServicePullArgs[fieldId]), err) 1618 | SkipFieldError: 1619 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1620 | ReadFieldEndError: 1621 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1622 | ReadStructEndError: 1623 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1624 | } 1625 | 1626 | func (p *IMServicePullArgs) FastReadField2(buf []byte) (int, error) { 1627 | offset := 0 1628 | 1629 | tmp := NewPullRequest() 1630 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 1631 | return offset, err 1632 | } else { 1633 | offset += l 1634 | } 1635 | p.Req = tmp 1636 | return offset, nil 1637 | } 1638 | 1639 | // for compatibility 1640 | func (p *IMServicePullArgs) FastWrite(buf []byte) int { 1641 | return 0 1642 | } 1643 | 1644 | func (p *IMServicePullArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1645 | offset := 0 1646 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Pull_args") 1647 | if p != nil { 1648 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 1649 | } 1650 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1651 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1652 | return offset 1653 | } 1654 | 1655 | func (p *IMServicePullArgs) BLength() int { 1656 | l := 0 1657 | l += bthrift.Binary.StructBeginLength("Pull_args") 1658 | if p != nil { 1659 | l += p.field2Length() 1660 | } 1661 | l += bthrift.Binary.FieldStopLength() 1662 | l += bthrift.Binary.StructEndLength() 1663 | return l 1664 | } 1665 | 1666 | func (p *IMServicePullArgs) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1667 | offset := 0 1668 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req", thrift.STRUCT, 2) 1669 | offset += p.Req.FastWriteNocopy(buf[offset:], binaryWriter) 1670 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1671 | return offset 1672 | } 1673 | 1674 | func (p *IMServicePullArgs) field2Length() int { 1675 | l := 0 1676 | l += bthrift.Binary.FieldBeginLength("req", thrift.STRUCT, 2) 1677 | l += p.Req.BLength() 1678 | l += bthrift.Binary.FieldEndLength() 1679 | return l 1680 | } 1681 | 1682 | func (p *IMServicePullResult) FastRead(buf []byte) (int, error) { 1683 | var err error 1684 | var offset int 1685 | var l int 1686 | var fieldTypeId thrift.TType 1687 | var fieldId int16 1688 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 1689 | offset += l 1690 | if err != nil { 1691 | goto ReadStructBeginError 1692 | } 1693 | 1694 | for { 1695 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 1696 | offset += l 1697 | if err != nil { 1698 | goto ReadFieldBeginError 1699 | } 1700 | if fieldTypeId == thrift.STOP { 1701 | break 1702 | } 1703 | switch fieldId { 1704 | case 0: 1705 | if fieldTypeId == thrift.STRUCT { 1706 | l, err = p.FastReadField0(buf[offset:]) 1707 | offset += l 1708 | if err != nil { 1709 | goto ReadFieldError 1710 | } 1711 | } else { 1712 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1713 | offset += l 1714 | if err != nil { 1715 | goto SkipFieldError 1716 | } 1717 | } 1718 | default: 1719 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1720 | offset += l 1721 | if err != nil { 1722 | goto SkipFieldError 1723 | } 1724 | } 1725 | 1726 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1727 | offset += l 1728 | if err != nil { 1729 | goto ReadFieldEndError 1730 | } 1731 | } 1732 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1733 | offset += l 1734 | if err != nil { 1735 | goto ReadStructEndError 1736 | } 1737 | 1738 | return offset, nil 1739 | ReadStructBeginError: 1740 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1741 | ReadFieldBeginError: 1742 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1743 | ReadFieldError: 1744 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IMServicePullResult[fieldId]), err) 1745 | SkipFieldError: 1746 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1747 | ReadFieldEndError: 1748 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1749 | ReadStructEndError: 1750 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1751 | } 1752 | 1753 | func (p *IMServicePullResult) FastReadField0(buf []byte) (int, error) { 1754 | offset := 0 1755 | 1756 | tmp := NewPullResponse() 1757 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 1758 | return offset, err 1759 | } else { 1760 | offset += l 1761 | } 1762 | p.Success = tmp 1763 | return offset, nil 1764 | } 1765 | 1766 | // for compatibility 1767 | func (p *IMServicePullResult) FastWrite(buf []byte) int { 1768 | return 0 1769 | } 1770 | 1771 | func (p *IMServicePullResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1772 | offset := 0 1773 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Pull_result") 1774 | if p != nil { 1775 | offset += p.fastWriteField0(buf[offset:], binaryWriter) 1776 | } 1777 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1778 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1779 | return offset 1780 | } 1781 | 1782 | func (p *IMServicePullResult) BLength() int { 1783 | l := 0 1784 | l += bthrift.Binary.StructBeginLength("Pull_result") 1785 | if p != nil { 1786 | l += p.field0Length() 1787 | } 1788 | l += bthrift.Binary.FieldStopLength() 1789 | l += bthrift.Binary.StructEndLength() 1790 | return l 1791 | } 1792 | 1793 | func (p *IMServicePullResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1794 | offset := 0 1795 | if p.IsSetSuccess() { 1796 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) 1797 | offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) 1798 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1799 | } 1800 | return offset 1801 | } 1802 | 1803 | func (p *IMServicePullResult) field0Length() int { 1804 | l := 0 1805 | if p.IsSetSuccess() { 1806 | l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) 1807 | l += p.Success.BLength() 1808 | l += bthrift.Binary.FieldEndLength() 1809 | } 1810 | return l 1811 | } 1812 | 1813 | func (p *IMServiceSendArgs) GetFirstArgument() interface{} { 1814 | return p.Req 1815 | } 1816 | 1817 | func (p *IMServiceSendResult) GetResult() interface{} { 1818 | return p.Success 1819 | } 1820 | 1821 | func (p *IMServicePullArgs) GetFirstArgument() interface{} { 1822 | return p.Req 1823 | } 1824 | 1825 | func (p *IMServicePullResult) GetResult() interface{} { 1826 | return p.Success 1827 | } 1828 | -------------------------------------------------------------------------------- /http-server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "log" 6 | "time" 7 | 8 | "github.com/TikTokTechImmersion/assignment_demo_2023/http-server/kitex_gen/rpc" 9 | "github.com/TikTokTechImmersion/assignment_demo_2023/http-server/kitex_gen/rpc/imservice" 10 | "github.com/TikTokTechImmersion/assignment_demo_2023/http-server/proto_gen/api" 11 | "github.com/cloudwego/hertz/pkg/app" 12 | "github.com/cloudwego/hertz/pkg/app/server" 13 | "github.com/cloudwego/hertz/pkg/common/utils" 14 | "github.com/cloudwego/hertz/pkg/protocol/consts" 15 | "github.com/cloudwego/kitex/client" 16 | etcd "github.com/kitex-contrib/registry-etcd" 17 | ) 18 | 19 | var cli imservice.Client 20 | 21 | func main() { 22 | r, err := etcd.NewEtcdResolver([]string{"etcd:2379"}) 23 | if err != nil { 24 | log.Fatal(err) 25 | } 26 | cli = imservice.MustNewClient("demo.rpc.server", 27 | client.WithResolver(r), 28 | client.WithRPCTimeout(1*time.Second), 29 | client.WithHostPorts("rpc-server:8888"), 30 | ) 31 | 32 | h := server.Default(server.WithHostPorts("0.0.0.0:8080")) 33 | 34 | h.GET("/ping", func(c context.Context, ctx *app.RequestContext) { 35 | ctx.JSON(consts.StatusOK, utils.H{"message": "pong"}) 36 | }) 37 | 38 | h.POST("/api/send", sendMessage) 39 | h.GET("/api/pull", pullMessage) 40 | 41 | h.Spin() 42 | } 43 | 44 | func sendMessage(ctx context.Context, c *app.RequestContext) { 45 | var req api.SendRequest 46 | err := c.Bind(&req) 47 | if err != nil { 48 | c.String(consts.StatusBadRequest, "Failed to parse request body: %v", err) 49 | return 50 | } 51 | resp, err := cli.Send(ctx, &rpc.SendRequest{ 52 | Message: &rpc.Message{ 53 | Chat: req.Chat, 54 | Text: req.Text, 55 | Sender: req.Sender, 56 | }, 57 | }) 58 | if err != nil { 59 | c.String(consts.StatusInternalServerError, err.Error()) 60 | } else if resp.Code != 0 { 61 | c.String(consts.StatusInternalServerError, resp.Msg) 62 | } else { 63 | c.Status(consts.StatusOK) 64 | } 65 | } 66 | 67 | func pullMessage(ctx context.Context, c *app.RequestContext) { 68 | var req api.PullRequest 69 | err := c.Bind(&req) 70 | if err != nil { 71 | c.String(consts.StatusBadRequest, "Failed to parse request body: %v", err) 72 | return 73 | } 74 | 75 | resp, err := cli.Pull(ctx, &rpc.PullRequest{ 76 | Chat: req.Chat, 77 | Cursor: req.Cursor, 78 | Limit: req.Limit, 79 | Reverse: &req.Reverse, 80 | }) 81 | if err != nil { 82 | c.String(consts.StatusInternalServerError, err.Error()) 83 | return 84 | } else if resp.Code != 0 { 85 | c.String(consts.StatusInternalServerError, resp.Msg) 86 | return 87 | } 88 | messages := make([]*api.Message, 0, len(resp.Messages)) 89 | for _, msg := range resp.Messages { 90 | messages = append(messages, &api.Message{ 91 | Chat: msg.Chat, 92 | Text: msg.Text, 93 | Sender: msg.Sender, 94 | SendTime: msg.SendTime, 95 | }) 96 | } 97 | c.JSON(consts.StatusOK, &api.PullResponse{ 98 | Messages: messages, 99 | HasMore: resp.GetHasMore(), 100 | NextCursor: resp.GetNextCursor(), 101 | }) 102 | } 103 | -------------------------------------------------------------------------------- /http-server/proto_gen/api/idl_http.pb.go: -------------------------------------------------------------------------------- 1 | // API for pull mode IM service. 2 | 3 | // Code generated by protoc-gen-go. DO NOT EDIT. 4 | // versions: 5 | // protoc-gen-go v1.30.0 6 | // protoc v3.21.12 7 | // source: idl_http.proto 8 | 9 | package api 10 | 11 | import ( 12 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 13 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 14 | reflect "reflect" 15 | sync "sync" 16 | ) 17 | 18 | const ( 19 | // Verify that this generated code is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 21 | // Verify that runtime/protoimpl is sufficiently up-to-date. 22 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 23 | ) 24 | 25 | type Message struct { 26 | state protoimpl.MessageState 27 | sizeCache protoimpl.SizeCache 28 | unknownFields protoimpl.UnknownFields 29 | 30 | Chat string `protobuf:"bytes,1,opt,name=chat,proto3" json:"chat,omitempty"` // format ":", e.g. "john:doe" 31 | Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"` // message text content 32 | Sender string `protobuf:"bytes,3,opt,name=sender,proto3" json:"sender,omitempty"` // sender identifier of the message 33 | SendTime int64 `protobuf:"varint,4,opt,name=send_time,json=sendTime,proto3" json:"send_time,omitempty"` // unit: microseconds 34 | } 35 | 36 | func (x *Message) Reset() { 37 | *x = Message{} 38 | if protoimpl.UnsafeEnabled { 39 | mi := &file_idl_http_proto_msgTypes[0] 40 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 41 | ms.StoreMessageInfo(mi) 42 | } 43 | } 44 | 45 | func (x *Message) String() string { 46 | return protoimpl.X.MessageStringOf(x) 47 | } 48 | 49 | func (*Message) ProtoMessage() {} 50 | 51 | func (x *Message) ProtoReflect() protoreflect.Message { 52 | mi := &file_idl_http_proto_msgTypes[0] 53 | if protoimpl.UnsafeEnabled && x != nil { 54 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 55 | if ms.LoadMessageInfo() == nil { 56 | ms.StoreMessageInfo(mi) 57 | } 58 | return ms 59 | } 60 | return mi.MessageOf(x) 61 | } 62 | 63 | // Deprecated: Use Message.ProtoReflect.Descriptor instead. 64 | func (*Message) Descriptor() ([]byte, []int) { 65 | return file_idl_http_proto_rawDescGZIP(), []int{0} 66 | } 67 | 68 | func (x *Message) GetChat() string { 69 | if x != nil { 70 | return x.Chat 71 | } 72 | return "" 73 | } 74 | 75 | func (x *Message) GetText() string { 76 | if x != nil { 77 | return x.Text 78 | } 79 | return "" 80 | } 81 | 82 | func (x *Message) GetSender() string { 83 | if x != nil { 84 | return x.Sender 85 | } 86 | return "" 87 | } 88 | 89 | func (x *Message) GetSendTime() int64 { 90 | if x != nil { 91 | return x.SendTime 92 | } 93 | return 0 94 | } 95 | 96 | type SendRequest struct { 97 | state protoimpl.MessageState 98 | sizeCache protoimpl.SizeCache 99 | unknownFields protoimpl.UnknownFields 100 | 101 | Chat string `protobuf:"bytes,1,opt,name=chat,proto3" json:"chat,omitempty"` // format ":", e.g. "john:doe" 102 | Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"` // message text content to be sent 103 | Sender string `protobuf:"bytes,3,opt,name=sender,proto3" json:"sender,omitempty"` // sender identifier 104 | } 105 | 106 | func (x *SendRequest) Reset() { 107 | *x = SendRequest{} 108 | if protoimpl.UnsafeEnabled { 109 | mi := &file_idl_http_proto_msgTypes[1] 110 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 111 | ms.StoreMessageInfo(mi) 112 | } 113 | } 114 | 115 | func (x *SendRequest) String() string { 116 | return protoimpl.X.MessageStringOf(x) 117 | } 118 | 119 | func (*SendRequest) ProtoMessage() {} 120 | 121 | func (x *SendRequest) ProtoReflect() protoreflect.Message { 122 | mi := &file_idl_http_proto_msgTypes[1] 123 | if protoimpl.UnsafeEnabled && x != nil { 124 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 125 | if ms.LoadMessageInfo() == nil { 126 | ms.StoreMessageInfo(mi) 127 | } 128 | return ms 129 | } 130 | return mi.MessageOf(x) 131 | } 132 | 133 | // Deprecated: Use SendRequest.ProtoReflect.Descriptor instead. 134 | func (*SendRequest) Descriptor() ([]byte, []int) { 135 | return file_idl_http_proto_rawDescGZIP(), []int{1} 136 | } 137 | 138 | func (x *SendRequest) GetChat() string { 139 | if x != nil { 140 | return x.Chat 141 | } 142 | return "" 143 | } 144 | 145 | func (x *SendRequest) GetText() string { 146 | if x != nil { 147 | return x.Text 148 | } 149 | return "" 150 | } 151 | 152 | func (x *SendRequest) GetSender() string { 153 | if x != nil { 154 | return x.Sender 155 | } 156 | return "" 157 | } 158 | 159 | type SendResponse struct { 160 | state protoimpl.MessageState 161 | sizeCache protoimpl.SizeCache 162 | unknownFields protoimpl.UnknownFields 163 | } 164 | 165 | func (x *SendResponse) Reset() { 166 | *x = SendResponse{} 167 | if protoimpl.UnsafeEnabled { 168 | mi := &file_idl_http_proto_msgTypes[2] 169 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 170 | ms.StoreMessageInfo(mi) 171 | } 172 | } 173 | 174 | func (x *SendResponse) String() string { 175 | return protoimpl.X.MessageStringOf(x) 176 | } 177 | 178 | func (*SendResponse) ProtoMessage() {} 179 | 180 | func (x *SendResponse) ProtoReflect() protoreflect.Message { 181 | mi := &file_idl_http_proto_msgTypes[2] 182 | if protoimpl.UnsafeEnabled && x != nil { 183 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 184 | if ms.LoadMessageInfo() == nil { 185 | ms.StoreMessageInfo(mi) 186 | } 187 | return ms 188 | } 189 | return mi.MessageOf(x) 190 | } 191 | 192 | // Deprecated: Use SendResponse.ProtoReflect.Descriptor instead. 193 | func (*SendResponse) Descriptor() ([]byte, []int) { 194 | return file_idl_http_proto_rawDescGZIP(), []int{2} 195 | } 196 | 197 | type PullRequest struct { 198 | state protoimpl.MessageState 199 | sizeCache protoimpl.SizeCache 200 | unknownFields protoimpl.UnknownFields 201 | 202 | Chat string `protobuf:"bytes,1,opt,name=chat,proto3" json:"chat,omitempty"` // format ":", e.g. "john:doe" 203 | Cursor int64 `protobuf:"varint,2,opt,name=cursor,proto3" json:"cursor,omitempty"` // starting position of message's send_time, inclusively, 0 by default 204 | Limit int32 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` // the maximum number of messages returned per request, 10 by default 205 | Reverse bool `protobuf:"varint,4,opt,name=reverse,proto3" json:"reverse,omitempty"` // if false, the results will be sorted in ascending order by time 206 | } 207 | 208 | func (x *PullRequest) Reset() { 209 | *x = PullRequest{} 210 | if protoimpl.UnsafeEnabled { 211 | mi := &file_idl_http_proto_msgTypes[3] 212 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 213 | ms.StoreMessageInfo(mi) 214 | } 215 | } 216 | 217 | func (x *PullRequest) String() string { 218 | return protoimpl.X.MessageStringOf(x) 219 | } 220 | 221 | func (*PullRequest) ProtoMessage() {} 222 | 223 | func (x *PullRequest) ProtoReflect() protoreflect.Message { 224 | mi := &file_idl_http_proto_msgTypes[3] 225 | if protoimpl.UnsafeEnabled && x != nil { 226 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 227 | if ms.LoadMessageInfo() == nil { 228 | ms.StoreMessageInfo(mi) 229 | } 230 | return ms 231 | } 232 | return mi.MessageOf(x) 233 | } 234 | 235 | // Deprecated: Use PullRequest.ProtoReflect.Descriptor instead. 236 | func (*PullRequest) Descriptor() ([]byte, []int) { 237 | return file_idl_http_proto_rawDescGZIP(), []int{3} 238 | } 239 | 240 | func (x *PullRequest) GetChat() string { 241 | if x != nil { 242 | return x.Chat 243 | } 244 | return "" 245 | } 246 | 247 | func (x *PullRequest) GetCursor() int64 { 248 | if x != nil { 249 | return x.Cursor 250 | } 251 | return 0 252 | } 253 | 254 | func (x *PullRequest) GetLimit() int32 { 255 | if x != nil { 256 | return x.Limit 257 | } 258 | return 0 259 | } 260 | 261 | func (x *PullRequest) GetReverse() bool { 262 | if x != nil { 263 | return x.Reverse 264 | } 265 | return false 266 | } 267 | 268 | type PullResponse struct { 269 | state protoimpl.MessageState 270 | sizeCache protoimpl.SizeCache 271 | unknownFields protoimpl.UnknownFields 272 | 273 | Messages []*Message `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` 274 | HasMore bool `protobuf:"varint,2,opt,name=has_more,json=hasMore,proto3" json:"has_more,omitempty"` // if true, can use next_cursor to pull the next page of messages 275 | NextCursor int64 `protobuf:"varint,3,opt,name=next_cursor,json=nextCursor,proto3" json:"next_cursor,omitempty"` // starting position of next page, inclusively 276 | } 277 | 278 | func (x *PullResponse) Reset() { 279 | *x = PullResponse{} 280 | if protoimpl.UnsafeEnabled { 281 | mi := &file_idl_http_proto_msgTypes[4] 282 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 283 | ms.StoreMessageInfo(mi) 284 | } 285 | } 286 | 287 | func (x *PullResponse) String() string { 288 | return protoimpl.X.MessageStringOf(x) 289 | } 290 | 291 | func (*PullResponse) ProtoMessage() {} 292 | 293 | func (x *PullResponse) ProtoReflect() protoreflect.Message { 294 | mi := &file_idl_http_proto_msgTypes[4] 295 | if protoimpl.UnsafeEnabled && x != nil { 296 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 297 | if ms.LoadMessageInfo() == nil { 298 | ms.StoreMessageInfo(mi) 299 | } 300 | return ms 301 | } 302 | return mi.MessageOf(x) 303 | } 304 | 305 | // Deprecated: Use PullResponse.ProtoReflect.Descriptor instead. 306 | func (*PullResponse) Descriptor() ([]byte, []int) { 307 | return file_idl_http_proto_rawDescGZIP(), []int{4} 308 | } 309 | 310 | func (x *PullResponse) GetMessages() []*Message { 311 | if x != nil { 312 | return x.Messages 313 | } 314 | return nil 315 | } 316 | 317 | func (x *PullResponse) GetHasMore() bool { 318 | if x != nil { 319 | return x.HasMore 320 | } 321 | return false 322 | } 323 | 324 | func (x *PullResponse) GetNextCursor() int64 { 325 | if x != nil { 326 | return x.NextCursor 327 | } 328 | return 0 329 | } 330 | 331 | var File_idl_http_proto protoreflect.FileDescriptor 332 | 333 | var file_idl_http_proto_rawDesc = []byte{ 334 | 0x0a, 0x0e, 0x69, 0x64, 0x6c, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 335 | 0x12, 0x03, 0x61, 0x70, 0x69, 0x22, 0x66, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 336 | 0x12, 0x12, 0x0a, 0x04, 0x63, 0x68, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 337 | 0x63, 0x68, 0x61, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x02, 0x20, 0x01, 338 | 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x64, 339 | 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 340 | 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 341 | 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x4d, 0x0a, 342 | 0x0b, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 343 | 0x63, 0x68, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x68, 0x61, 0x74, 344 | 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 345 | 0x74, 0x65, 0x78, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x03, 346 | 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x0e, 0x0a, 0x0c, 347 | 0x53, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x69, 0x0a, 0x0b, 348 | 0x50, 0x75, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 349 | 0x68, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x68, 0x61, 0x74, 0x12, 350 | 0x16, 0x0a, 0x06, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 351 | 0x06, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 352 | 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x18, 0x0a, 353 | 0x07, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 354 | 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x22, 0x74, 0x0a, 0x0c, 0x50, 0x75, 0x6c, 0x6c, 0x52, 355 | 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 356 | 0x67, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x61, 0x70, 0x69, 0x2e, 357 | 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 358 | 0x73, 0x12, 0x19, 0x0a, 0x08, 0x68, 0x61, 0x73, 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 359 | 0x01, 0x28, 0x08, 0x52, 0x07, 0x68, 0x61, 0x73, 0x4d, 0x6f, 0x72, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 360 | 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 361 | 0x03, 0x52, 0x0a, 0x6e, 0x65, 0x78, 0x74, 0x43, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x32, 0x6a, 0x0a, 362 | 0x0e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 363 | 0x2b, 0x0a, 0x04, 0x53, 0x65, 0x6e, 0x64, 0x12, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x65, 364 | 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x61, 0x70, 0x69, 0x2e, 365 | 0x53, 0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2b, 0x0a, 0x04, 366 | 0x50, 0x75, 0x6c, 0x6c, 0x12, 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x50, 0x75, 0x6c, 0x6c, 0x52, 367 | 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x50, 0x75, 0x6c, 368 | 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2f, 0x61, 0x70, 369 | 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 370 | } 371 | 372 | var ( 373 | file_idl_http_proto_rawDescOnce sync.Once 374 | file_idl_http_proto_rawDescData = file_idl_http_proto_rawDesc 375 | ) 376 | 377 | func file_idl_http_proto_rawDescGZIP() []byte { 378 | file_idl_http_proto_rawDescOnce.Do(func() { 379 | file_idl_http_proto_rawDescData = protoimpl.X.CompressGZIP(file_idl_http_proto_rawDescData) 380 | }) 381 | return file_idl_http_proto_rawDescData 382 | } 383 | 384 | var file_idl_http_proto_msgTypes = make([]protoimpl.MessageInfo, 5) 385 | var file_idl_http_proto_goTypes = []interface{}{ 386 | (*Message)(nil), // 0: api.Message 387 | (*SendRequest)(nil), // 1: api.SendRequest 388 | (*SendResponse)(nil), // 2: api.SendResponse 389 | (*PullRequest)(nil), // 3: api.PullRequest 390 | (*PullResponse)(nil), // 4: api.PullResponse 391 | } 392 | var file_idl_http_proto_depIdxs = []int32{ 393 | 0, // 0: api.PullResponse.messages:type_name -> api.Message 394 | 1, // 1: api.MessageService.Send:input_type -> api.SendRequest 395 | 3, // 2: api.MessageService.Pull:input_type -> api.PullRequest 396 | 2, // 3: api.MessageService.Send:output_type -> api.SendResponse 397 | 4, // 4: api.MessageService.Pull:output_type -> api.PullResponse 398 | 3, // [3:5] is the sub-list for method output_type 399 | 1, // [1:3] is the sub-list for method input_type 400 | 1, // [1:1] is the sub-list for extension type_name 401 | 1, // [1:1] is the sub-list for extension extendee 402 | 0, // [0:1] is the sub-list for field type_name 403 | } 404 | 405 | func init() { file_idl_http_proto_init() } 406 | func file_idl_http_proto_init() { 407 | if File_idl_http_proto != nil { 408 | return 409 | } 410 | if !protoimpl.UnsafeEnabled { 411 | file_idl_http_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 412 | switch v := v.(*Message); i { 413 | case 0: 414 | return &v.state 415 | case 1: 416 | return &v.sizeCache 417 | case 2: 418 | return &v.unknownFields 419 | default: 420 | return nil 421 | } 422 | } 423 | file_idl_http_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 424 | switch v := v.(*SendRequest); i { 425 | case 0: 426 | return &v.state 427 | case 1: 428 | return &v.sizeCache 429 | case 2: 430 | return &v.unknownFields 431 | default: 432 | return nil 433 | } 434 | } 435 | file_idl_http_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 436 | switch v := v.(*SendResponse); i { 437 | case 0: 438 | return &v.state 439 | case 1: 440 | return &v.sizeCache 441 | case 2: 442 | return &v.unknownFields 443 | default: 444 | return nil 445 | } 446 | } 447 | file_idl_http_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { 448 | switch v := v.(*PullRequest); i { 449 | case 0: 450 | return &v.state 451 | case 1: 452 | return &v.sizeCache 453 | case 2: 454 | return &v.unknownFields 455 | default: 456 | return nil 457 | } 458 | } 459 | file_idl_http_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { 460 | switch v := v.(*PullResponse); i { 461 | case 0: 462 | return &v.state 463 | case 1: 464 | return &v.sizeCache 465 | case 2: 466 | return &v.unknownFields 467 | default: 468 | return nil 469 | } 470 | } 471 | } 472 | type x struct{} 473 | out := protoimpl.TypeBuilder{ 474 | File: protoimpl.DescBuilder{ 475 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 476 | RawDescriptor: file_idl_http_proto_rawDesc, 477 | NumEnums: 0, 478 | NumMessages: 5, 479 | NumExtensions: 0, 480 | NumServices: 1, 481 | }, 482 | GoTypes: file_idl_http_proto_goTypes, 483 | DependencyIndexes: file_idl_http_proto_depIdxs, 484 | MessageInfos: file_idl_http_proto_msgTypes, 485 | }.Build() 486 | File_idl_http_proto = out.File 487 | file_idl_http_proto_rawDesc = nil 488 | file_idl_http_proto_goTypes = nil 489 | file_idl_http_proto_depIdxs = nil 490 | } 491 | -------------------------------------------------------------------------------- /idl_http.proto: -------------------------------------------------------------------------------- 1 | // API for pull mode IM service. 2 | syntax = "proto3"; 3 | 4 | package api; 5 | 6 | option go_package = "/api"; 7 | 8 | message Message { 9 | string chat = 1; // format ":", e.g. "john:doe" 10 | string text = 2; // message text content 11 | string sender = 3; // sender identifier of the message 12 | int64 send_time = 4; // unit: microseconds 13 | } 14 | 15 | message SendRequest { 16 | string chat = 1; // format ":", e.g. "john:doe" 17 | string text = 2; // message text content to be sent 18 | string sender = 3; // sender identifier 19 | } 20 | 21 | message SendResponse {} // return a reasonable HTTP status code if error occurs 22 | 23 | message PullRequest { 24 | string chat = 1; // format ":", e.g. "john:doe" 25 | int64 cursor = 2; // starting position of message's send_time, inclusively, 0 by default 26 | int32 limit = 3; // the maximum number of messages returned per request, 10 by default 27 | bool reverse = 4; // if false, the results will be sorted in ascending order by time 28 | } 29 | 30 | message PullResponse { 31 | repeated Message messages = 1; 32 | bool has_more = 2; // if true, can use next_cursor to pull the next page of messages 33 | int64 next_cursor = 3; // starting position of next page, inclusively 34 | } 35 | 36 | service MessageService { 37 | rpc Send (SendRequest) returns (SendResponse); // POST 38 | rpc Pull (PullRequest) returns (PullResponse); // GET 39 | } 40 | -------------------------------------------------------------------------------- /idl_rpc.thrift: -------------------------------------------------------------------------------- 1 | // API for pull mode IM service. 2 | namespace go rpc 3 | 4 | struct Message { 5 | 1: string Chat // format ":", e.g. "john:doe" 6 | 2: string Text // message text content 7 | 3: string Sender // sender identifier 8 | 4: i64 SendTime // unit: microseconds 9 | } 10 | 11 | struct SendRequest { 12 | 1: required Message message // message to be sent 13 | } 14 | 15 | struct SendResponse { 16 | 1: required i32 Code // zero for success, non-zero for failures 17 | 2: required string Msg // prompt information 18 | } 19 | 20 | struct PullRequest { 21 | 1: required string Chat // format ":", e.g. "john:doe" 22 | 2: required i64 Cursor // starting position of message's send_time, inclusively, 0 by default 23 | 3: required i32 Limit // the maximum number of messages returned per request, 10 by default 24 | 4: optional bool Reverse // if false, the results will be sorted in ascending order by time 25 | } 26 | 27 | struct PullResponse { 28 | 1: required i32 Code // zero for success, non-zero for failures 29 | 2: required string Msg // prompt information 30 | 3: optional list Messages 31 | 4: optional bool HasMore // if true, can use next_cursor to pull the next page of messages 32 | 5: optional i64 NextCursor // starting position of next page, inclusively 33 | } 34 | 35 | service IMService { 36 | SendResponse Send(1: SendRequest req) 37 | PullResponse Pull(2: PullRequest req) 38 | } 39 | -------------------------------------------------------------------------------- /rpc-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.18 2 | WORKDIR /app 3 | COPY . . 4 | RUN sh ./build.sh 5 | EXPOSE 8888 6 | CMD ["./output/bootstrap.sh"] 7 | -------------------------------------------------------------------------------- /rpc-server/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | RUN_NAME="demo.im.rpc" 3 | 4 | mkdir -p output/bin 5 | cp script/* output/ 6 | chmod +x output/bootstrap.sh 7 | 8 | if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then 9 | go build -o output/bin/${RUN_NAME} 10 | else 11 | go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./... 12 | fi 13 | -------------------------------------------------------------------------------- /rpc-server/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/apache/thrift v0.13.0 7 | github.com/cloudwego/kitex v0.5.2 8 | github.com/kitex-contrib/registry-etcd v0.1.0 9 | github.com/stretchr/testify v1.8.2 10 | ) 11 | 12 | require ( 13 | github.com/bytedance/gopkg v0.0.0-20220817015305-b879a72dc90f // indirect 14 | github.com/chenzhuoyu/iasm v0.0.0-20230222070914-0b1b64b0e762 // indirect 15 | github.com/choleraehyq/pid v0.0.16 // indirect 16 | github.com/cloudwego/fastpb v0.0.4 // indirect 17 | github.com/cloudwego/frugal v0.1.6 // indirect 18 | github.com/cloudwego/netpoll v0.3.2 // indirect 19 | github.com/cloudwego/thriftgo v0.2.9 // indirect 20 | github.com/coreos/go-semver v0.3.0 // indirect 21 | github.com/coreos/go-systemd/v22 v22.3.2 // indirect 22 | github.com/davecgh/go-spew v1.1.1 // indirect 23 | github.com/gogo/protobuf v1.3.2 // indirect 24 | github.com/golang/protobuf v1.5.2 // indirect 25 | github.com/google/pprof v0.0.0-20220608213341-c488b8fa1db3 // indirect 26 | github.com/jhump/protoreflect v1.8.2 // indirect 27 | github.com/json-iterator/go v1.1.12 // indirect 28 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 29 | github.com/modern-go/reflect2 v1.0.2 // indirect 30 | github.com/oleiade/lane v1.0.1 // indirect 31 | github.com/pmezard/go-difflib v1.0.0 // indirect 32 | github.com/sirupsen/logrus v1.8.1 // indirect 33 | github.com/smartystreets/goconvey v1.7.2 // indirect 34 | github.com/tidwall/gjson v1.9.3 // indirect 35 | github.com/tidwall/match v1.1.1 // indirect 36 | github.com/tidwall/pretty v1.2.0 // indirect 37 | go.etcd.io/etcd/api/v3 v3.5.5 // indirect 38 | go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect 39 | go.etcd.io/etcd/client/v3 v3.5.5 // indirect 40 | go.uber.org/atomic v1.8.0 // indirect 41 | go.uber.org/multierr v1.6.0 // indirect 42 | go.uber.org/zap v1.17.0 // indirect 43 | golang.org/x/arch v0.2.0 // indirect 44 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect 45 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect 46 | golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect 47 | golang.org/x/text v0.6.0 // indirect 48 | golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect 49 | google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect 50 | google.golang.org/grpc v1.41.0 // indirect 51 | google.golang.org/protobuf v1.28.1 // indirect 52 | gopkg.in/yaml.v3 v3.0.1 // indirect 53 | ) 54 | 55 | replace github.com/apache/thrift => github.com/apache/thrift v0.13.0 56 | -------------------------------------------------------------------------------- /rpc-server/handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "math/rand" 6 | 7 | "github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server/kitex_gen/rpc" 8 | ) 9 | 10 | // IMServiceImpl implements the last service interface defined in the IDL. 11 | type IMServiceImpl struct{} 12 | 13 | func (s *IMServiceImpl) Send(ctx context.Context, req *rpc.SendRequest) (*rpc.SendResponse, error) { 14 | resp := rpc.NewSendResponse() 15 | resp.Code, resp.Msg = areYouLucky() 16 | return resp, nil 17 | } 18 | 19 | func (s *IMServiceImpl) Pull(ctx context.Context, req *rpc.PullRequest) (*rpc.PullResponse, error) { 20 | resp := rpc.NewPullResponse() 21 | resp.Code, resp.Msg = areYouLucky() 22 | return resp, nil 23 | } 24 | 25 | func areYouLucky() (int32, string) { 26 | if rand.Int31n(2) == 1 { 27 | return 0, "success" 28 | } else { 29 | return 500, "oops" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rpc-server/handler_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "testing" 7 | 8 | "github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server/kitex_gen/rpc" 9 | "github.com/stretchr/testify/assert" 10 | ) 11 | 12 | func TestIMServiceImpl_Send(t *testing.T) { 13 | type args struct { 14 | ctx context.Context 15 | req *rpc.SendRequest 16 | } 17 | tests := []struct { 18 | name string 19 | args args 20 | wantErr error 21 | }{ 22 | { 23 | name: "success", 24 | args: args{ 25 | ctx: context.Background(), 26 | req: &rpc.SendRequest{}, 27 | }, 28 | wantErr: nil, 29 | }, 30 | } 31 | for _, tt := range tests { 32 | t.Run(tt.name, func(t *testing.T) { 33 | s := &IMServiceImpl{} 34 | got, err := s.Send(tt.args.ctx, tt.args.req) 35 | assert.True(t, errors.Is(err, tt.wantErr)) 36 | assert.NotNil(t, got) 37 | }) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rpc-server/kitex_gen/rpc/imservice/client.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | 3 | package imservice 4 | 5 | import ( 6 | "context" 7 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server/kitex_gen/rpc" 8 | client "github.com/cloudwego/kitex/client" 9 | callopt "github.com/cloudwego/kitex/client/callopt" 10 | ) 11 | 12 | // Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. 13 | type Client interface { 14 | Send(ctx context.Context, req *rpc.SendRequest, callOptions ...callopt.Option) (r *rpc.SendResponse, err error) 15 | Pull(ctx context.Context, req *rpc.PullRequest, callOptions ...callopt.Option) (r *rpc.PullResponse, err error) 16 | } 17 | 18 | // NewClient creates a client for the service defined in IDL. 19 | func NewClient(destService string, opts ...client.Option) (Client, error) { 20 | var options []client.Option 21 | options = append(options, client.WithDestService(destService)) 22 | 23 | options = append(options, opts...) 24 | 25 | kc, err := client.NewClient(serviceInfo(), options...) 26 | if err != nil { 27 | return nil, err 28 | } 29 | return &kIMServiceClient{ 30 | kClient: newServiceClient(kc), 31 | }, nil 32 | } 33 | 34 | // MustNewClient creates a client for the service defined in IDL. It panics if any error occurs. 35 | func MustNewClient(destService string, opts ...client.Option) Client { 36 | kc, err := NewClient(destService, opts...) 37 | if err != nil { 38 | panic(err) 39 | } 40 | return kc 41 | } 42 | 43 | type kIMServiceClient struct { 44 | *kClient 45 | } 46 | 47 | func (p *kIMServiceClient) Send(ctx context.Context, req *rpc.SendRequest, callOptions ...callopt.Option) (r *rpc.SendResponse, err error) { 48 | ctx = client.NewCtxWithCallOptions(ctx, callOptions) 49 | return p.kClient.Send(ctx, req) 50 | } 51 | 52 | func (p *kIMServiceClient) Pull(ctx context.Context, req *rpc.PullRequest, callOptions ...callopt.Option) (r *rpc.PullResponse, err error) { 53 | ctx = client.NewCtxWithCallOptions(ctx, callOptions) 54 | return p.kClient.Pull(ctx, req) 55 | } 56 | -------------------------------------------------------------------------------- /rpc-server/kitex_gen/rpc/imservice/imservice.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | 3 | package imservice 4 | 5 | import ( 6 | "context" 7 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server/kitex_gen/rpc" 8 | client "github.com/cloudwego/kitex/client" 9 | kitex "github.com/cloudwego/kitex/pkg/serviceinfo" 10 | ) 11 | 12 | func serviceInfo() *kitex.ServiceInfo { 13 | return iMServiceServiceInfo 14 | } 15 | 16 | var iMServiceServiceInfo = NewServiceInfo() 17 | 18 | func NewServiceInfo() *kitex.ServiceInfo { 19 | serviceName := "IMService" 20 | handlerType := (*rpc.IMService)(nil) 21 | methods := map[string]kitex.MethodInfo{ 22 | "Send": kitex.NewMethodInfo(sendHandler, newIMServiceSendArgs, newIMServiceSendResult, false), 23 | "Pull": kitex.NewMethodInfo(pullHandler, newIMServicePullArgs, newIMServicePullResult, false), 24 | } 25 | extra := map[string]interface{}{ 26 | "PackageName": "rpc", 27 | } 28 | svcInfo := &kitex.ServiceInfo{ 29 | ServiceName: serviceName, 30 | HandlerType: handlerType, 31 | Methods: methods, 32 | PayloadCodec: kitex.Thrift, 33 | KiteXGenVersion: "v0.5.2", 34 | Extra: extra, 35 | } 36 | return svcInfo 37 | } 38 | 39 | func sendHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { 40 | realArg := arg.(*rpc.IMServiceSendArgs) 41 | realResult := result.(*rpc.IMServiceSendResult) 42 | success, err := handler.(rpc.IMService).Send(ctx, realArg.Req) 43 | if err != nil { 44 | return err 45 | } 46 | realResult.Success = success 47 | return nil 48 | } 49 | func newIMServiceSendArgs() interface{} { 50 | return rpc.NewIMServiceSendArgs() 51 | } 52 | 53 | func newIMServiceSendResult() interface{} { 54 | return rpc.NewIMServiceSendResult() 55 | } 56 | 57 | func pullHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { 58 | realArg := arg.(*rpc.IMServicePullArgs) 59 | realResult := result.(*rpc.IMServicePullResult) 60 | success, err := handler.(rpc.IMService).Pull(ctx, realArg.Req) 61 | if err != nil { 62 | return err 63 | } 64 | realResult.Success = success 65 | return nil 66 | } 67 | func newIMServicePullArgs() interface{} { 68 | return rpc.NewIMServicePullArgs() 69 | } 70 | 71 | func newIMServicePullResult() interface{} { 72 | return rpc.NewIMServicePullResult() 73 | } 74 | 75 | type kClient struct { 76 | c client.Client 77 | } 78 | 79 | func newServiceClient(c client.Client) *kClient { 80 | return &kClient{ 81 | c: c, 82 | } 83 | } 84 | 85 | func (p *kClient) Send(ctx context.Context, req *rpc.SendRequest) (r *rpc.SendResponse, err error) { 86 | var _args rpc.IMServiceSendArgs 87 | _args.Req = req 88 | var _result rpc.IMServiceSendResult 89 | if err = p.c.Call(ctx, "Send", &_args, &_result); err != nil { 90 | return 91 | } 92 | return _result.GetSuccess(), nil 93 | } 94 | 95 | func (p *kClient) Pull(ctx context.Context, req *rpc.PullRequest) (r *rpc.PullResponse, err error) { 96 | var _args rpc.IMServicePullArgs 97 | _args.Req = req 98 | var _result rpc.IMServicePullResult 99 | if err = p.c.Call(ctx, "Pull", &_args, &_result); err != nil { 100 | return 101 | } 102 | return _result.GetSuccess(), nil 103 | } 104 | -------------------------------------------------------------------------------- /rpc-server/kitex_gen/rpc/imservice/invoker.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | 3 | package imservice 4 | 5 | import ( 6 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server/kitex_gen/rpc" 7 | server "github.com/cloudwego/kitex/server" 8 | ) 9 | 10 | // NewInvoker creates a server.Invoker with the given handler and options. 11 | func NewInvoker(handler rpc.IMService, opts ...server.Option) server.Invoker { 12 | var options []server.Option 13 | 14 | options = append(options, opts...) 15 | 16 | s := server.NewInvoker(options...) 17 | if err := s.RegisterService(serviceInfo(), handler); err != nil { 18 | panic(err) 19 | } 20 | if err := s.Init(); err != nil { 21 | panic(err) 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /rpc-server/kitex_gen/rpc/imservice/server.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | package imservice 3 | 4 | import ( 5 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server/kitex_gen/rpc" 6 | server "github.com/cloudwego/kitex/server" 7 | ) 8 | 9 | // NewServer creates a server.Server with the given handler and options. 10 | func NewServer(handler rpc.IMService, opts ...server.Option) server.Server { 11 | var options []server.Option 12 | 13 | options = append(options, opts...) 14 | 15 | svr := server.NewServer(options...) 16 | if err := svr.RegisterService(serviceInfo(), handler); err != nil { 17 | panic(err) 18 | } 19 | return svr 20 | } 21 | -------------------------------------------------------------------------------- /rpc-server/kitex_gen/rpc/k-consts.go: -------------------------------------------------------------------------------- 1 | package rpc 2 | 3 | // KitexUnusedProtection is used to prevent 'imported and not used' error. 4 | var KitexUnusedProtection = struct{}{} 5 | -------------------------------------------------------------------------------- /rpc-server/kitex_gen/rpc/k-idl_rpc.go: -------------------------------------------------------------------------------- 1 | // Code generated by Kitex v0.5.2. DO NOT EDIT. 2 | 3 | package rpc 4 | 5 | import ( 6 | "bytes" 7 | "fmt" 8 | "reflect" 9 | "strings" 10 | 11 | "github.com/apache/thrift/lib/go/thrift" 12 | 13 | "github.com/cloudwego/kitex/pkg/protocol/bthrift" 14 | ) 15 | 16 | // unused protection 17 | var ( 18 | _ = fmt.Formatter(nil) 19 | _ = (*bytes.Buffer)(nil) 20 | _ = (*strings.Builder)(nil) 21 | _ = reflect.Type(nil) 22 | _ = thrift.TProtocol(nil) 23 | _ = bthrift.BinaryWriter(nil) 24 | ) 25 | 26 | func (p *Message) FastRead(buf []byte) (int, error) { 27 | var err error 28 | var offset int 29 | var l int 30 | var fieldTypeId thrift.TType 31 | var fieldId int16 32 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 33 | offset += l 34 | if err != nil { 35 | goto ReadStructBeginError 36 | } 37 | 38 | for { 39 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 40 | offset += l 41 | if err != nil { 42 | goto ReadFieldBeginError 43 | } 44 | if fieldTypeId == thrift.STOP { 45 | break 46 | } 47 | switch fieldId { 48 | case 1: 49 | if fieldTypeId == thrift.STRING { 50 | l, err = p.FastReadField1(buf[offset:]) 51 | offset += l 52 | if err != nil { 53 | goto ReadFieldError 54 | } 55 | } else { 56 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 57 | offset += l 58 | if err != nil { 59 | goto SkipFieldError 60 | } 61 | } 62 | case 2: 63 | if fieldTypeId == thrift.STRING { 64 | l, err = p.FastReadField2(buf[offset:]) 65 | offset += l 66 | if err != nil { 67 | goto ReadFieldError 68 | } 69 | } else { 70 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 71 | offset += l 72 | if err != nil { 73 | goto SkipFieldError 74 | } 75 | } 76 | case 3: 77 | if fieldTypeId == thrift.STRING { 78 | l, err = p.FastReadField3(buf[offset:]) 79 | offset += l 80 | if err != nil { 81 | goto ReadFieldError 82 | } 83 | } else { 84 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 85 | offset += l 86 | if err != nil { 87 | goto SkipFieldError 88 | } 89 | } 90 | case 4: 91 | if fieldTypeId == thrift.I64 { 92 | l, err = p.FastReadField4(buf[offset:]) 93 | offset += l 94 | if err != nil { 95 | goto ReadFieldError 96 | } 97 | } else { 98 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 99 | offset += l 100 | if err != nil { 101 | goto SkipFieldError 102 | } 103 | } 104 | default: 105 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 106 | offset += l 107 | if err != nil { 108 | goto SkipFieldError 109 | } 110 | } 111 | 112 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 113 | offset += l 114 | if err != nil { 115 | goto ReadFieldEndError 116 | } 117 | } 118 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 119 | offset += l 120 | if err != nil { 121 | goto ReadStructEndError 122 | } 123 | 124 | return offset, nil 125 | ReadStructBeginError: 126 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 127 | ReadFieldBeginError: 128 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 129 | ReadFieldError: 130 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_Message[fieldId]), err) 131 | SkipFieldError: 132 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 133 | ReadFieldEndError: 134 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 135 | ReadStructEndError: 136 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 137 | } 138 | 139 | func (p *Message) FastReadField1(buf []byte) (int, error) { 140 | offset := 0 141 | 142 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 143 | return offset, err 144 | } else { 145 | offset += l 146 | 147 | p.Chat = v 148 | 149 | } 150 | return offset, nil 151 | } 152 | 153 | func (p *Message) FastReadField2(buf []byte) (int, error) { 154 | offset := 0 155 | 156 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 157 | return offset, err 158 | } else { 159 | offset += l 160 | 161 | p.Text = v 162 | 163 | } 164 | return offset, nil 165 | } 166 | 167 | func (p *Message) FastReadField3(buf []byte) (int, error) { 168 | offset := 0 169 | 170 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 171 | return offset, err 172 | } else { 173 | offset += l 174 | 175 | p.Sender = v 176 | 177 | } 178 | return offset, nil 179 | } 180 | 181 | func (p *Message) FastReadField4(buf []byte) (int, error) { 182 | offset := 0 183 | 184 | if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { 185 | return offset, err 186 | } else { 187 | offset += l 188 | 189 | p.SendTime = v 190 | 191 | } 192 | return offset, nil 193 | } 194 | 195 | // for compatibility 196 | func (p *Message) FastWrite(buf []byte) int { 197 | return 0 198 | } 199 | 200 | func (p *Message) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 201 | offset := 0 202 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Message") 203 | if p != nil { 204 | offset += p.fastWriteField4(buf[offset:], binaryWriter) 205 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 206 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 207 | offset += p.fastWriteField3(buf[offset:], binaryWriter) 208 | } 209 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 210 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 211 | return offset 212 | } 213 | 214 | func (p *Message) BLength() int { 215 | l := 0 216 | l += bthrift.Binary.StructBeginLength("Message") 217 | if p != nil { 218 | l += p.field1Length() 219 | l += p.field2Length() 220 | l += p.field3Length() 221 | l += p.field4Length() 222 | } 223 | l += bthrift.Binary.FieldStopLength() 224 | l += bthrift.Binary.StructEndLength() 225 | return l 226 | } 227 | 228 | func (p *Message) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 229 | offset := 0 230 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Chat", thrift.STRING, 1) 231 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Chat) 232 | 233 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 234 | return offset 235 | } 236 | 237 | func (p *Message) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 238 | offset := 0 239 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Text", thrift.STRING, 2) 240 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Text) 241 | 242 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 243 | return offset 244 | } 245 | 246 | func (p *Message) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { 247 | offset := 0 248 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Sender", thrift.STRING, 3) 249 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Sender) 250 | 251 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 252 | return offset 253 | } 254 | 255 | func (p *Message) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { 256 | offset := 0 257 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "SendTime", thrift.I64, 4) 258 | offset += bthrift.Binary.WriteI64(buf[offset:], p.SendTime) 259 | 260 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 261 | return offset 262 | } 263 | 264 | func (p *Message) field1Length() int { 265 | l := 0 266 | l += bthrift.Binary.FieldBeginLength("Chat", thrift.STRING, 1) 267 | l += bthrift.Binary.StringLengthNocopy(p.Chat) 268 | 269 | l += bthrift.Binary.FieldEndLength() 270 | return l 271 | } 272 | 273 | func (p *Message) field2Length() int { 274 | l := 0 275 | l += bthrift.Binary.FieldBeginLength("Text", thrift.STRING, 2) 276 | l += bthrift.Binary.StringLengthNocopy(p.Text) 277 | 278 | l += bthrift.Binary.FieldEndLength() 279 | return l 280 | } 281 | 282 | func (p *Message) field3Length() int { 283 | l := 0 284 | l += bthrift.Binary.FieldBeginLength("Sender", thrift.STRING, 3) 285 | l += bthrift.Binary.StringLengthNocopy(p.Sender) 286 | 287 | l += bthrift.Binary.FieldEndLength() 288 | return l 289 | } 290 | 291 | func (p *Message) field4Length() int { 292 | l := 0 293 | l += bthrift.Binary.FieldBeginLength("SendTime", thrift.I64, 4) 294 | l += bthrift.Binary.I64Length(p.SendTime) 295 | 296 | l += bthrift.Binary.FieldEndLength() 297 | return l 298 | } 299 | 300 | func (p *SendRequest) FastRead(buf []byte) (int, error) { 301 | var err error 302 | var offset int 303 | var l int 304 | var fieldTypeId thrift.TType 305 | var fieldId int16 306 | var issetMessage bool = false 307 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 308 | offset += l 309 | if err != nil { 310 | goto ReadStructBeginError 311 | } 312 | 313 | for { 314 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 315 | offset += l 316 | if err != nil { 317 | goto ReadFieldBeginError 318 | } 319 | if fieldTypeId == thrift.STOP { 320 | break 321 | } 322 | switch fieldId { 323 | case 1: 324 | if fieldTypeId == thrift.STRUCT { 325 | l, err = p.FastReadField1(buf[offset:]) 326 | offset += l 327 | if err != nil { 328 | goto ReadFieldError 329 | } 330 | issetMessage = true 331 | } else { 332 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 333 | offset += l 334 | if err != nil { 335 | goto SkipFieldError 336 | } 337 | } 338 | default: 339 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 340 | offset += l 341 | if err != nil { 342 | goto SkipFieldError 343 | } 344 | } 345 | 346 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 347 | offset += l 348 | if err != nil { 349 | goto ReadFieldEndError 350 | } 351 | } 352 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 353 | offset += l 354 | if err != nil { 355 | goto ReadStructEndError 356 | } 357 | 358 | if !issetMessage { 359 | fieldId = 1 360 | goto RequiredFieldNotSetError 361 | } 362 | return offset, nil 363 | ReadStructBeginError: 364 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 365 | ReadFieldBeginError: 366 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 367 | ReadFieldError: 368 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_SendRequest[fieldId]), err) 369 | SkipFieldError: 370 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 371 | ReadFieldEndError: 372 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 373 | ReadStructEndError: 374 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 375 | RequiredFieldNotSetError: 376 | return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_SendRequest[fieldId])) 377 | } 378 | 379 | func (p *SendRequest) FastReadField1(buf []byte) (int, error) { 380 | offset := 0 381 | 382 | tmp := NewMessage() 383 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 384 | return offset, err 385 | } else { 386 | offset += l 387 | } 388 | p.Message = tmp 389 | return offset, nil 390 | } 391 | 392 | // for compatibility 393 | func (p *SendRequest) FastWrite(buf []byte) int { 394 | return 0 395 | } 396 | 397 | func (p *SendRequest) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 398 | offset := 0 399 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "SendRequest") 400 | if p != nil { 401 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 402 | } 403 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 404 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 405 | return offset 406 | } 407 | 408 | func (p *SendRequest) BLength() int { 409 | l := 0 410 | l += bthrift.Binary.StructBeginLength("SendRequest") 411 | if p != nil { 412 | l += p.field1Length() 413 | } 414 | l += bthrift.Binary.FieldStopLength() 415 | l += bthrift.Binary.StructEndLength() 416 | return l 417 | } 418 | 419 | func (p *SendRequest) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 420 | offset := 0 421 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRUCT, 1) 422 | offset += p.Message.FastWriteNocopy(buf[offset:], binaryWriter) 423 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 424 | return offset 425 | } 426 | 427 | func (p *SendRequest) field1Length() int { 428 | l := 0 429 | l += bthrift.Binary.FieldBeginLength("message", thrift.STRUCT, 1) 430 | l += p.Message.BLength() 431 | l += bthrift.Binary.FieldEndLength() 432 | return l 433 | } 434 | 435 | func (p *SendResponse) FastRead(buf []byte) (int, error) { 436 | var err error 437 | var offset int 438 | var l int 439 | var fieldTypeId thrift.TType 440 | var fieldId int16 441 | var issetCode bool = false 442 | var issetMsg bool = false 443 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 444 | offset += l 445 | if err != nil { 446 | goto ReadStructBeginError 447 | } 448 | 449 | for { 450 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 451 | offset += l 452 | if err != nil { 453 | goto ReadFieldBeginError 454 | } 455 | if fieldTypeId == thrift.STOP { 456 | break 457 | } 458 | switch fieldId { 459 | case 1: 460 | if fieldTypeId == thrift.I32 { 461 | l, err = p.FastReadField1(buf[offset:]) 462 | offset += l 463 | if err != nil { 464 | goto ReadFieldError 465 | } 466 | issetCode = true 467 | } else { 468 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 469 | offset += l 470 | if err != nil { 471 | goto SkipFieldError 472 | } 473 | } 474 | case 2: 475 | if fieldTypeId == thrift.STRING { 476 | l, err = p.FastReadField2(buf[offset:]) 477 | offset += l 478 | if err != nil { 479 | goto ReadFieldError 480 | } 481 | issetMsg = true 482 | } else { 483 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 484 | offset += l 485 | if err != nil { 486 | goto SkipFieldError 487 | } 488 | } 489 | default: 490 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 491 | offset += l 492 | if err != nil { 493 | goto SkipFieldError 494 | } 495 | } 496 | 497 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 498 | offset += l 499 | if err != nil { 500 | goto ReadFieldEndError 501 | } 502 | } 503 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 504 | offset += l 505 | if err != nil { 506 | goto ReadStructEndError 507 | } 508 | 509 | if !issetCode { 510 | fieldId = 1 511 | goto RequiredFieldNotSetError 512 | } 513 | 514 | if !issetMsg { 515 | fieldId = 2 516 | goto RequiredFieldNotSetError 517 | } 518 | return offset, nil 519 | ReadStructBeginError: 520 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 521 | ReadFieldBeginError: 522 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 523 | ReadFieldError: 524 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_SendResponse[fieldId]), err) 525 | SkipFieldError: 526 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 527 | ReadFieldEndError: 528 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 529 | ReadStructEndError: 530 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 531 | RequiredFieldNotSetError: 532 | return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_SendResponse[fieldId])) 533 | } 534 | 535 | func (p *SendResponse) FastReadField1(buf []byte) (int, error) { 536 | offset := 0 537 | 538 | if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { 539 | return offset, err 540 | } else { 541 | offset += l 542 | 543 | p.Code = v 544 | 545 | } 546 | return offset, nil 547 | } 548 | 549 | func (p *SendResponse) FastReadField2(buf []byte) (int, error) { 550 | offset := 0 551 | 552 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 553 | return offset, err 554 | } else { 555 | offset += l 556 | 557 | p.Msg = v 558 | 559 | } 560 | return offset, nil 561 | } 562 | 563 | // for compatibility 564 | func (p *SendResponse) FastWrite(buf []byte) int { 565 | return 0 566 | } 567 | 568 | func (p *SendResponse) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 569 | offset := 0 570 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "SendResponse") 571 | if p != nil { 572 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 573 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 574 | } 575 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 576 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 577 | return offset 578 | } 579 | 580 | func (p *SendResponse) BLength() int { 581 | l := 0 582 | l += bthrift.Binary.StructBeginLength("SendResponse") 583 | if p != nil { 584 | l += p.field1Length() 585 | l += p.field2Length() 586 | } 587 | l += bthrift.Binary.FieldStopLength() 588 | l += bthrift.Binary.StructEndLength() 589 | return l 590 | } 591 | 592 | func (p *SendResponse) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 593 | offset := 0 594 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Code", thrift.I32, 1) 595 | offset += bthrift.Binary.WriteI32(buf[offset:], p.Code) 596 | 597 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 598 | return offset 599 | } 600 | 601 | func (p *SendResponse) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 602 | offset := 0 603 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Msg", thrift.STRING, 2) 604 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Msg) 605 | 606 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 607 | return offset 608 | } 609 | 610 | func (p *SendResponse) field1Length() int { 611 | l := 0 612 | l += bthrift.Binary.FieldBeginLength("Code", thrift.I32, 1) 613 | l += bthrift.Binary.I32Length(p.Code) 614 | 615 | l += bthrift.Binary.FieldEndLength() 616 | return l 617 | } 618 | 619 | func (p *SendResponse) field2Length() int { 620 | l := 0 621 | l += bthrift.Binary.FieldBeginLength("Msg", thrift.STRING, 2) 622 | l += bthrift.Binary.StringLengthNocopy(p.Msg) 623 | 624 | l += bthrift.Binary.FieldEndLength() 625 | return l 626 | } 627 | 628 | func (p *PullRequest) FastRead(buf []byte) (int, error) { 629 | var err error 630 | var offset int 631 | var l int 632 | var fieldTypeId thrift.TType 633 | var fieldId int16 634 | var issetChat bool = false 635 | var issetCursor bool = false 636 | var issetLimit bool = false 637 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 638 | offset += l 639 | if err != nil { 640 | goto ReadStructBeginError 641 | } 642 | 643 | for { 644 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 645 | offset += l 646 | if err != nil { 647 | goto ReadFieldBeginError 648 | } 649 | if fieldTypeId == thrift.STOP { 650 | break 651 | } 652 | switch fieldId { 653 | case 1: 654 | if fieldTypeId == thrift.STRING { 655 | l, err = p.FastReadField1(buf[offset:]) 656 | offset += l 657 | if err != nil { 658 | goto ReadFieldError 659 | } 660 | issetChat = true 661 | } else { 662 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 663 | offset += l 664 | if err != nil { 665 | goto SkipFieldError 666 | } 667 | } 668 | case 2: 669 | if fieldTypeId == thrift.I64 { 670 | l, err = p.FastReadField2(buf[offset:]) 671 | offset += l 672 | if err != nil { 673 | goto ReadFieldError 674 | } 675 | issetCursor = true 676 | } else { 677 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 678 | offset += l 679 | if err != nil { 680 | goto SkipFieldError 681 | } 682 | } 683 | case 3: 684 | if fieldTypeId == thrift.I32 { 685 | l, err = p.FastReadField3(buf[offset:]) 686 | offset += l 687 | if err != nil { 688 | goto ReadFieldError 689 | } 690 | issetLimit = true 691 | } else { 692 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 693 | offset += l 694 | if err != nil { 695 | goto SkipFieldError 696 | } 697 | } 698 | case 4: 699 | if fieldTypeId == thrift.BOOL { 700 | l, err = p.FastReadField4(buf[offset:]) 701 | offset += l 702 | if err != nil { 703 | goto ReadFieldError 704 | } 705 | } else { 706 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 707 | offset += l 708 | if err != nil { 709 | goto SkipFieldError 710 | } 711 | } 712 | default: 713 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 714 | offset += l 715 | if err != nil { 716 | goto SkipFieldError 717 | } 718 | } 719 | 720 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 721 | offset += l 722 | if err != nil { 723 | goto ReadFieldEndError 724 | } 725 | } 726 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 727 | offset += l 728 | if err != nil { 729 | goto ReadStructEndError 730 | } 731 | 732 | if !issetChat { 733 | fieldId = 1 734 | goto RequiredFieldNotSetError 735 | } 736 | 737 | if !issetCursor { 738 | fieldId = 2 739 | goto RequiredFieldNotSetError 740 | } 741 | 742 | if !issetLimit { 743 | fieldId = 3 744 | goto RequiredFieldNotSetError 745 | } 746 | return offset, nil 747 | ReadStructBeginError: 748 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 749 | ReadFieldBeginError: 750 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 751 | ReadFieldError: 752 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PullRequest[fieldId]), err) 753 | SkipFieldError: 754 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 755 | ReadFieldEndError: 756 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 757 | ReadStructEndError: 758 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 759 | RequiredFieldNotSetError: 760 | return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_PullRequest[fieldId])) 761 | } 762 | 763 | func (p *PullRequest) FastReadField1(buf []byte) (int, error) { 764 | offset := 0 765 | 766 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 767 | return offset, err 768 | } else { 769 | offset += l 770 | 771 | p.Chat = v 772 | 773 | } 774 | return offset, nil 775 | } 776 | 777 | func (p *PullRequest) FastReadField2(buf []byte) (int, error) { 778 | offset := 0 779 | 780 | if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { 781 | return offset, err 782 | } else { 783 | offset += l 784 | 785 | p.Cursor = v 786 | 787 | } 788 | return offset, nil 789 | } 790 | 791 | func (p *PullRequest) FastReadField3(buf []byte) (int, error) { 792 | offset := 0 793 | 794 | if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { 795 | return offset, err 796 | } else { 797 | offset += l 798 | 799 | p.Limit = v 800 | 801 | } 802 | return offset, nil 803 | } 804 | 805 | func (p *PullRequest) FastReadField4(buf []byte) (int, error) { 806 | offset := 0 807 | 808 | if v, l, err := bthrift.Binary.ReadBool(buf[offset:]); err != nil { 809 | return offset, err 810 | } else { 811 | offset += l 812 | p.Reverse = &v 813 | 814 | } 815 | return offset, nil 816 | } 817 | 818 | // for compatibility 819 | func (p *PullRequest) FastWrite(buf []byte) int { 820 | return 0 821 | } 822 | 823 | func (p *PullRequest) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 824 | offset := 0 825 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "PullRequest") 826 | if p != nil { 827 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 828 | offset += p.fastWriteField3(buf[offset:], binaryWriter) 829 | offset += p.fastWriteField4(buf[offset:], binaryWriter) 830 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 831 | } 832 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 833 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 834 | return offset 835 | } 836 | 837 | func (p *PullRequest) BLength() int { 838 | l := 0 839 | l += bthrift.Binary.StructBeginLength("PullRequest") 840 | if p != nil { 841 | l += p.field1Length() 842 | l += p.field2Length() 843 | l += p.field3Length() 844 | l += p.field4Length() 845 | } 846 | l += bthrift.Binary.FieldStopLength() 847 | l += bthrift.Binary.StructEndLength() 848 | return l 849 | } 850 | 851 | func (p *PullRequest) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 852 | offset := 0 853 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Chat", thrift.STRING, 1) 854 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Chat) 855 | 856 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 857 | return offset 858 | } 859 | 860 | func (p *PullRequest) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 861 | offset := 0 862 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Cursor", thrift.I64, 2) 863 | offset += bthrift.Binary.WriteI64(buf[offset:], p.Cursor) 864 | 865 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 866 | return offset 867 | } 868 | 869 | func (p *PullRequest) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { 870 | offset := 0 871 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Limit", thrift.I32, 3) 872 | offset += bthrift.Binary.WriteI32(buf[offset:], p.Limit) 873 | 874 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 875 | return offset 876 | } 877 | 878 | func (p *PullRequest) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { 879 | offset := 0 880 | if p.IsSetReverse() { 881 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Reverse", thrift.BOOL, 4) 882 | offset += bthrift.Binary.WriteBool(buf[offset:], *p.Reverse) 883 | 884 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 885 | } 886 | return offset 887 | } 888 | 889 | func (p *PullRequest) field1Length() int { 890 | l := 0 891 | l += bthrift.Binary.FieldBeginLength("Chat", thrift.STRING, 1) 892 | l += bthrift.Binary.StringLengthNocopy(p.Chat) 893 | 894 | l += bthrift.Binary.FieldEndLength() 895 | return l 896 | } 897 | 898 | func (p *PullRequest) field2Length() int { 899 | l := 0 900 | l += bthrift.Binary.FieldBeginLength("Cursor", thrift.I64, 2) 901 | l += bthrift.Binary.I64Length(p.Cursor) 902 | 903 | l += bthrift.Binary.FieldEndLength() 904 | return l 905 | } 906 | 907 | func (p *PullRequest) field3Length() int { 908 | l := 0 909 | l += bthrift.Binary.FieldBeginLength("Limit", thrift.I32, 3) 910 | l += bthrift.Binary.I32Length(p.Limit) 911 | 912 | l += bthrift.Binary.FieldEndLength() 913 | return l 914 | } 915 | 916 | func (p *PullRequest) field4Length() int { 917 | l := 0 918 | if p.IsSetReverse() { 919 | l += bthrift.Binary.FieldBeginLength("Reverse", thrift.BOOL, 4) 920 | l += bthrift.Binary.BoolLength(*p.Reverse) 921 | 922 | l += bthrift.Binary.FieldEndLength() 923 | } 924 | return l 925 | } 926 | 927 | func (p *PullResponse) FastRead(buf []byte) (int, error) { 928 | var err error 929 | var offset int 930 | var l int 931 | var fieldTypeId thrift.TType 932 | var fieldId int16 933 | var issetCode bool = false 934 | var issetMsg bool = false 935 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 936 | offset += l 937 | if err != nil { 938 | goto ReadStructBeginError 939 | } 940 | 941 | for { 942 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 943 | offset += l 944 | if err != nil { 945 | goto ReadFieldBeginError 946 | } 947 | if fieldTypeId == thrift.STOP { 948 | break 949 | } 950 | switch fieldId { 951 | case 1: 952 | if fieldTypeId == thrift.I32 { 953 | l, err = p.FastReadField1(buf[offset:]) 954 | offset += l 955 | if err != nil { 956 | goto ReadFieldError 957 | } 958 | issetCode = true 959 | } else { 960 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 961 | offset += l 962 | if err != nil { 963 | goto SkipFieldError 964 | } 965 | } 966 | case 2: 967 | if fieldTypeId == thrift.STRING { 968 | l, err = p.FastReadField2(buf[offset:]) 969 | offset += l 970 | if err != nil { 971 | goto ReadFieldError 972 | } 973 | issetMsg = true 974 | } else { 975 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 976 | offset += l 977 | if err != nil { 978 | goto SkipFieldError 979 | } 980 | } 981 | case 3: 982 | if fieldTypeId == thrift.LIST { 983 | l, err = p.FastReadField3(buf[offset:]) 984 | offset += l 985 | if err != nil { 986 | goto ReadFieldError 987 | } 988 | } else { 989 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 990 | offset += l 991 | if err != nil { 992 | goto SkipFieldError 993 | } 994 | } 995 | case 4: 996 | if fieldTypeId == thrift.BOOL { 997 | l, err = p.FastReadField4(buf[offset:]) 998 | offset += l 999 | if err != nil { 1000 | goto ReadFieldError 1001 | } 1002 | } else { 1003 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1004 | offset += l 1005 | if err != nil { 1006 | goto SkipFieldError 1007 | } 1008 | } 1009 | case 5: 1010 | if fieldTypeId == thrift.I64 { 1011 | l, err = p.FastReadField5(buf[offset:]) 1012 | offset += l 1013 | if err != nil { 1014 | goto ReadFieldError 1015 | } 1016 | } else { 1017 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1018 | offset += l 1019 | if err != nil { 1020 | goto SkipFieldError 1021 | } 1022 | } 1023 | default: 1024 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1025 | offset += l 1026 | if err != nil { 1027 | goto SkipFieldError 1028 | } 1029 | } 1030 | 1031 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1032 | offset += l 1033 | if err != nil { 1034 | goto ReadFieldEndError 1035 | } 1036 | } 1037 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1038 | offset += l 1039 | if err != nil { 1040 | goto ReadStructEndError 1041 | } 1042 | 1043 | if !issetCode { 1044 | fieldId = 1 1045 | goto RequiredFieldNotSetError 1046 | } 1047 | 1048 | if !issetMsg { 1049 | fieldId = 2 1050 | goto RequiredFieldNotSetError 1051 | } 1052 | return offset, nil 1053 | ReadStructBeginError: 1054 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1055 | ReadFieldBeginError: 1056 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1057 | ReadFieldError: 1058 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_PullResponse[fieldId]), err) 1059 | SkipFieldError: 1060 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1061 | ReadFieldEndError: 1062 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1063 | ReadStructEndError: 1064 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1065 | RequiredFieldNotSetError: 1066 | return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_PullResponse[fieldId])) 1067 | } 1068 | 1069 | func (p *PullResponse) FastReadField1(buf []byte) (int, error) { 1070 | offset := 0 1071 | 1072 | if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { 1073 | return offset, err 1074 | } else { 1075 | offset += l 1076 | 1077 | p.Code = v 1078 | 1079 | } 1080 | return offset, nil 1081 | } 1082 | 1083 | func (p *PullResponse) FastReadField2(buf []byte) (int, error) { 1084 | offset := 0 1085 | 1086 | if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 1087 | return offset, err 1088 | } else { 1089 | offset += l 1090 | 1091 | p.Msg = v 1092 | 1093 | } 1094 | return offset, nil 1095 | } 1096 | 1097 | func (p *PullResponse) FastReadField3(buf []byte) (int, error) { 1098 | offset := 0 1099 | 1100 | _, size, l, err := bthrift.Binary.ReadListBegin(buf[offset:]) 1101 | offset += l 1102 | if err != nil { 1103 | return offset, err 1104 | } 1105 | p.Messages = make([]*Message, 0, size) 1106 | for i := 0; i < size; i++ { 1107 | _elem := NewMessage() 1108 | if l, err := _elem.FastRead(buf[offset:]); err != nil { 1109 | return offset, err 1110 | } else { 1111 | offset += l 1112 | } 1113 | 1114 | p.Messages = append(p.Messages, _elem) 1115 | } 1116 | if l, err := bthrift.Binary.ReadListEnd(buf[offset:]); err != nil { 1117 | return offset, err 1118 | } else { 1119 | offset += l 1120 | } 1121 | return offset, nil 1122 | } 1123 | 1124 | func (p *PullResponse) FastReadField4(buf []byte) (int, error) { 1125 | offset := 0 1126 | 1127 | if v, l, err := bthrift.Binary.ReadBool(buf[offset:]); err != nil { 1128 | return offset, err 1129 | } else { 1130 | offset += l 1131 | p.HasMore = &v 1132 | 1133 | } 1134 | return offset, nil 1135 | } 1136 | 1137 | func (p *PullResponse) FastReadField5(buf []byte) (int, error) { 1138 | offset := 0 1139 | 1140 | if v, l, err := bthrift.Binary.ReadI64(buf[offset:]); err != nil { 1141 | return offset, err 1142 | } else { 1143 | offset += l 1144 | p.NextCursor = &v 1145 | 1146 | } 1147 | return offset, nil 1148 | } 1149 | 1150 | // for compatibility 1151 | func (p *PullResponse) FastWrite(buf []byte) int { 1152 | return 0 1153 | } 1154 | 1155 | func (p *PullResponse) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1156 | offset := 0 1157 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "PullResponse") 1158 | if p != nil { 1159 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 1160 | offset += p.fastWriteField4(buf[offset:], binaryWriter) 1161 | offset += p.fastWriteField5(buf[offset:], binaryWriter) 1162 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 1163 | offset += p.fastWriteField3(buf[offset:], binaryWriter) 1164 | } 1165 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1166 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1167 | return offset 1168 | } 1169 | 1170 | func (p *PullResponse) BLength() int { 1171 | l := 0 1172 | l += bthrift.Binary.StructBeginLength("PullResponse") 1173 | if p != nil { 1174 | l += p.field1Length() 1175 | l += p.field2Length() 1176 | l += p.field3Length() 1177 | l += p.field4Length() 1178 | l += p.field5Length() 1179 | } 1180 | l += bthrift.Binary.FieldStopLength() 1181 | l += bthrift.Binary.StructEndLength() 1182 | return l 1183 | } 1184 | 1185 | func (p *PullResponse) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1186 | offset := 0 1187 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Code", thrift.I32, 1) 1188 | offset += bthrift.Binary.WriteI32(buf[offset:], p.Code) 1189 | 1190 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1191 | return offset 1192 | } 1193 | 1194 | func (p *PullResponse) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1195 | offset := 0 1196 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Msg", thrift.STRING, 2) 1197 | offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Msg) 1198 | 1199 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1200 | return offset 1201 | } 1202 | 1203 | func (p *PullResponse) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1204 | offset := 0 1205 | if p.IsSetMessages() { 1206 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Messages", thrift.LIST, 3) 1207 | listBeginOffset := offset 1208 | offset += bthrift.Binary.ListBeginLength(thrift.STRUCT, 0) 1209 | var length int 1210 | for _, v := range p.Messages { 1211 | length++ 1212 | offset += v.FastWriteNocopy(buf[offset:], binaryWriter) 1213 | } 1214 | bthrift.Binary.WriteListBegin(buf[listBeginOffset:], thrift.STRUCT, length) 1215 | offset += bthrift.Binary.WriteListEnd(buf[offset:]) 1216 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1217 | } 1218 | return offset 1219 | } 1220 | 1221 | func (p *PullResponse) fastWriteField4(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1222 | offset := 0 1223 | if p.IsSetHasMore() { 1224 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "HasMore", thrift.BOOL, 4) 1225 | offset += bthrift.Binary.WriteBool(buf[offset:], *p.HasMore) 1226 | 1227 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1228 | } 1229 | return offset 1230 | } 1231 | 1232 | func (p *PullResponse) fastWriteField5(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1233 | offset := 0 1234 | if p.IsSetNextCursor() { 1235 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "NextCursor", thrift.I64, 5) 1236 | offset += bthrift.Binary.WriteI64(buf[offset:], *p.NextCursor) 1237 | 1238 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1239 | } 1240 | return offset 1241 | } 1242 | 1243 | func (p *PullResponse) field1Length() int { 1244 | l := 0 1245 | l += bthrift.Binary.FieldBeginLength("Code", thrift.I32, 1) 1246 | l += bthrift.Binary.I32Length(p.Code) 1247 | 1248 | l += bthrift.Binary.FieldEndLength() 1249 | return l 1250 | } 1251 | 1252 | func (p *PullResponse) field2Length() int { 1253 | l := 0 1254 | l += bthrift.Binary.FieldBeginLength("Msg", thrift.STRING, 2) 1255 | l += bthrift.Binary.StringLengthNocopy(p.Msg) 1256 | 1257 | l += bthrift.Binary.FieldEndLength() 1258 | return l 1259 | } 1260 | 1261 | func (p *PullResponse) field3Length() int { 1262 | l := 0 1263 | if p.IsSetMessages() { 1264 | l += bthrift.Binary.FieldBeginLength("Messages", thrift.LIST, 3) 1265 | l += bthrift.Binary.ListBeginLength(thrift.STRUCT, len(p.Messages)) 1266 | for _, v := range p.Messages { 1267 | l += v.BLength() 1268 | } 1269 | l += bthrift.Binary.ListEndLength() 1270 | l += bthrift.Binary.FieldEndLength() 1271 | } 1272 | return l 1273 | } 1274 | 1275 | func (p *PullResponse) field4Length() int { 1276 | l := 0 1277 | if p.IsSetHasMore() { 1278 | l += bthrift.Binary.FieldBeginLength("HasMore", thrift.BOOL, 4) 1279 | l += bthrift.Binary.BoolLength(*p.HasMore) 1280 | 1281 | l += bthrift.Binary.FieldEndLength() 1282 | } 1283 | return l 1284 | } 1285 | 1286 | func (p *PullResponse) field5Length() int { 1287 | l := 0 1288 | if p.IsSetNextCursor() { 1289 | l += bthrift.Binary.FieldBeginLength("NextCursor", thrift.I64, 5) 1290 | l += bthrift.Binary.I64Length(*p.NextCursor) 1291 | 1292 | l += bthrift.Binary.FieldEndLength() 1293 | } 1294 | return l 1295 | } 1296 | 1297 | func (p *IMServiceSendArgs) FastRead(buf []byte) (int, error) { 1298 | var err error 1299 | var offset int 1300 | var l int 1301 | var fieldTypeId thrift.TType 1302 | var fieldId int16 1303 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 1304 | offset += l 1305 | if err != nil { 1306 | goto ReadStructBeginError 1307 | } 1308 | 1309 | for { 1310 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 1311 | offset += l 1312 | if err != nil { 1313 | goto ReadFieldBeginError 1314 | } 1315 | if fieldTypeId == thrift.STOP { 1316 | break 1317 | } 1318 | switch fieldId { 1319 | case 1: 1320 | if fieldTypeId == thrift.STRUCT { 1321 | l, err = p.FastReadField1(buf[offset:]) 1322 | offset += l 1323 | if err != nil { 1324 | goto ReadFieldError 1325 | } 1326 | } else { 1327 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1328 | offset += l 1329 | if err != nil { 1330 | goto SkipFieldError 1331 | } 1332 | } 1333 | default: 1334 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1335 | offset += l 1336 | if err != nil { 1337 | goto SkipFieldError 1338 | } 1339 | } 1340 | 1341 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1342 | offset += l 1343 | if err != nil { 1344 | goto ReadFieldEndError 1345 | } 1346 | } 1347 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1348 | offset += l 1349 | if err != nil { 1350 | goto ReadStructEndError 1351 | } 1352 | 1353 | return offset, nil 1354 | ReadStructBeginError: 1355 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1356 | ReadFieldBeginError: 1357 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1358 | ReadFieldError: 1359 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IMServiceSendArgs[fieldId]), err) 1360 | SkipFieldError: 1361 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1362 | ReadFieldEndError: 1363 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1364 | ReadStructEndError: 1365 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1366 | } 1367 | 1368 | func (p *IMServiceSendArgs) FastReadField1(buf []byte) (int, error) { 1369 | offset := 0 1370 | 1371 | tmp := NewSendRequest() 1372 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 1373 | return offset, err 1374 | } else { 1375 | offset += l 1376 | } 1377 | p.Req = tmp 1378 | return offset, nil 1379 | } 1380 | 1381 | // for compatibility 1382 | func (p *IMServiceSendArgs) FastWrite(buf []byte) int { 1383 | return 0 1384 | } 1385 | 1386 | func (p *IMServiceSendArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1387 | offset := 0 1388 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Send_args") 1389 | if p != nil { 1390 | offset += p.fastWriteField1(buf[offset:], binaryWriter) 1391 | } 1392 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1393 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1394 | return offset 1395 | } 1396 | 1397 | func (p *IMServiceSendArgs) BLength() int { 1398 | l := 0 1399 | l += bthrift.Binary.StructBeginLength("Send_args") 1400 | if p != nil { 1401 | l += p.field1Length() 1402 | } 1403 | l += bthrift.Binary.FieldStopLength() 1404 | l += bthrift.Binary.StructEndLength() 1405 | return l 1406 | } 1407 | 1408 | func (p *IMServiceSendArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1409 | offset := 0 1410 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req", thrift.STRUCT, 1) 1411 | offset += p.Req.FastWriteNocopy(buf[offset:], binaryWriter) 1412 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1413 | return offset 1414 | } 1415 | 1416 | func (p *IMServiceSendArgs) field1Length() int { 1417 | l := 0 1418 | l += bthrift.Binary.FieldBeginLength("req", thrift.STRUCT, 1) 1419 | l += p.Req.BLength() 1420 | l += bthrift.Binary.FieldEndLength() 1421 | return l 1422 | } 1423 | 1424 | func (p *IMServiceSendResult) FastRead(buf []byte) (int, error) { 1425 | var err error 1426 | var offset int 1427 | var l int 1428 | var fieldTypeId thrift.TType 1429 | var fieldId int16 1430 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 1431 | offset += l 1432 | if err != nil { 1433 | goto ReadStructBeginError 1434 | } 1435 | 1436 | for { 1437 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 1438 | offset += l 1439 | if err != nil { 1440 | goto ReadFieldBeginError 1441 | } 1442 | if fieldTypeId == thrift.STOP { 1443 | break 1444 | } 1445 | switch fieldId { 1446 | case 0: 1447 | if fieldTypeId == thrift.STRUCT { 1448 | l, err = p.FastReadField0(buf[offset:]) 1449 | offset += l 1450 | if err != nil { 1451 | goto ReadFieldError 1452 | } 1453 | } else { 1454 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1455 | offset += l 1456 | if err != nil { 1457 | goto SkipFieldError 1458 | } 1459 | } 1460 | default: 1461 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1462 | offset += l 1463 | if err != nil { 1464 | goto SkipFieldError 1465 | } 1466 | } 1467 | 1468 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1469 | offset += l 1470 | if err != nil { 1471 | goto ReadFieldEndError 1472 | } 1473 | } 1474 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1475 | offset += l 1476 | if err != nil { 1477 | goto ReadStructEndError 1478 | } 1479 | 1480 | return offset, nil 1481 | ReadStructBeginError: 1482 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1483 | ReadFieldBeginError: 1484 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1485 | ReadFieldError: 1486 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IMServiceSendResult[fieldId]), err) 1487 | SkipFieldError: 1488 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1489 | ReadFieldEndError: 1490 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1491 | ReadStructEndError: 1492 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1493 | } 1494 | 1495 | func (p *IMServiceSendResult) FastReadField0(buf []byte) (int, error) { 1496 | offset := 0 1497 | 1498 | tmp := NewSendResponse() 1499 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 1500 | return offset, err 1501 | } else { 1502 | offset += l 1503 | } 1504 | p.Success = tmp 1505 | return offset, nil 1506 | } 1507 | 1508 | // for compatibility 1509 | func (p *IMServiceSendResult) FastWrite(buf []byte) int { 1510 | return 0 1511 | } 1512 | 1513 | func (p *IMServiceSendResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1514 | offset := 0 1515 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Send_result") 1516 | if p != nil { 1517 | offset += p.fastWriteField0(buf[offset:], binaryWriter) 1518 | } 1519 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1520 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1521 | return offset 1522 | } 1523 | 1524 | func (p *IMServiceSendResult) BLength() int { 1525 | l := 0 1526 | l += bthrift.Binary.StructBeginLength("Send_result") 1527 | if p != nil { 1528 | l += p.field0Length() 1529 | } 1530 | l += bthrift.Binary.FieldStopLength() 1531 | l += bthrift.Binary.StructEndLength() 1532 | return l 1533 | } 1534 | 1535 | func (p *IMServiceSendResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1536 | offset := 0 1537 | if p.IsSetSuccess() { 1538 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) 1539 | offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) 1540 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1541 | } 1542 | return offset 1543 | } 1544 | 1545 | func (p *IMServiceSendResult) field0Length() int { 1546 | l := 0 1547 | if p.IsSetSuccess() { 1548 | l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) 1549 | l += p.Success.BLength() 1550 | l += bthrift.Binary.FieldEndLength() 1551 | } 1552 | return l 1553 | } 1554 | 1555 | func (p *IMServicePullArgs) FastRead(buf []byte) (int, error) { 1556 | var err error 1557 | var offset int 1558 | var l int 1559 | var fieldTypeId thrift.TType 1560 | var fieldId int16 1561 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 1562 | offset += l 1563 | if err != nil { 1564 | goto ReadStructBeginError 1565 | } 1566 | 1567 | for { 1568 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 1569 | offset += l 1570 | if err != nil { 1571 | goto ReadFieldBeginError 1572 | } 1573 | if fieldTypeId == thrift.STOP { 1574 | break 1575 | } 1576 | switch fieldId { 1577 | case 2: 1578 | if fieldTypeId == thrift.STRUCT { 1579 | l, err = p.FastReadField2(buf[offset:]) 1580 | offset += l 1581 | if err != nil { 1582 | goto ReadFieldError 1583 | } 1584 | } else { 1585 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1586 | offset += l 1587 | if err != nil { 1588 | goto SkipFieldError 1589 | } 1590 | } 1591 | default: 1592 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1593 | offset += l 1594 | if err != nil { 1595 | goto SkipFieldError 1596 | } 1597 | } 1598 | 1599 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1600 | offset += l 1601 | if err != nil { 1602 | goto ReadFieldEndError 1603 | } 1604 | } 1605 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1606 | offset += l 1607 | if err != nil { 1608 | goto ReadStructEndError 1609 | } 1610 | 1611 | return offset, nil 1612 | ReadStructBeginError: 1613 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1614 | ReadFieldBeginError: 1615 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1616 | ReadFieldError: 1617 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IMServicePullArgs[fieldId]), err) 1618 | SkipFieldError: 1619 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1620 | ReadFieldEndError: 1621 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1622 | ReadStructEndError: 1623 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1624 | } 1625 | 1626 | func (p *IMServicePullArgs) FastReadField2(buf []byte) (int, error) { 1627 | offset := 0 1628 | 1629 | tmp := NewPullRequest() 1630 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 1631 | return offset, err 1632 | } else { 1633 | offset += l 1634 | } 1635 | p.Req = tmp 1636 | return offset, nil 1637 | } 1638 | 1639 | // for compatibility 1640 | func (p *IMServicePullArgs) FastWrite(buf []byte) int { 1641 | return 0 1642 | } 1643 | 1644 | func (p *IMServicePullArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1645 | offset := 0 1646 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Pull_args") 1647 | if p != nil { 1648 | offset += p.fastWriteField2(buf[offset:], binaryWriter) 1649 | } 1650 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1651 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1652 | return offset 1653 | } 1654 | 1655 | func (p *IMServicePullArgs) BLength() int { 1656 | l := 0 1657 | l += bthrift.Binary.StructBeginLength("Pull_args") 1658 | if p != nil { 1659 | l += p.field2Length() 1660 | } 1661 | l += bthrift.Binary.FieldStopLength() 1662 | l += bthrift.Binary.StructEndLength() 1663 | return l 1664 | } 1665 | 1666 | func (p *IMServicePullArgs) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1667 | offset := 0 1668 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req", thrift.STRUCT, 2) 1669 | offset += p.Req.FastWriteNocopy(buf[offset:], binaryWriter) 1670 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1671 | return offset 1672 | } 1673 | 1674 | func (p *IMServicePullArgs) field2Length() int { 1675 | l := 0 1676 | l += bthrift.Binary.FieldBeginLength("req", thrift.STRUCT, 2) 1677 | l += p.Req.BLength() 1678 | l += bthrift.Binary.FieldEndLength() 1679 | return l 1680 | } 1681 | 1682 | func (p *IMServicePullResult) FastRead(buf []byte) (int, error) { 1683 | var err error 1684 | var offset int 1685 | var l int 1686 | var fieldTypeId thrift.TType 1687 | var fieldId int16 1688 | _, l, err = bthrift.Binary.ReadStructBegin(buf) 1689 | offset += l 1690 | if err != nil { 1691 | goto ReadStructBeginError 1692 | } 1693 | 1694 | for { 1695 | _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 1696 | offset += l 1697 | if err != nil { 1698 | goto ReadFieldBeginError 1699 | } 1700 | if fieldTypeId == thrift.STOP { 1701 | break 1702 | } 1703 | switch fieldId { 1704 | case 0: 1705 | if fieldTypeId == thrift.STRUCT { 1706 | l, err = p.FastReadField0(buf[offset:]) 1707 | offset += l 1708 | if err != nil { 1709 | goto ReadFieldError 1710 | } 1711 | } else { 1712 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1713 | offset += l 1714 | if err != nil { 1715 | goto SkipFieldError 1716 | } 1717 | } 1718 | default: 1719 | l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 1720 | offset += l 1721 | if err != nil { 1722 | goto SkipFieldError 1723 | } 1724 | } 1725 | 1726 | l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 1727 | offset += l 1728 | if err != nil { 1729 | goto ReadFieldEndError 1730 | } 1731 | } 1732 | l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 1733 | offset += l 1734 | if err != nil { 1735 | goto ReadStructEndError 1736 | } 1737 | 1738 | return offset, nil 1739 | ReadStructBeginError: 1740 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 1741 | ReadFieldBeginError: 1742 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 1743 | ReadFieldError: 1744 | return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_IMServicePullResult[fieldId]), err) 1745 | SkipFieldError: 1746 | return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 1747 | ReadFieldEndError: 1748 | return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 1749 | ReadStructEndError: 1750 | return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 1751 | } 1752 | 1753 | func (p *IMServicePullResult) FastReadField0(buf []byte) (int, error) { 1754 | offset := 0 1755 | 1756 | tmp := NewPullResponse() 1757 | if l, err := tmp.FastRead(buf[offset:]); err != nil { 1758 | return offset, err 1759 | } else { 1760 | offset += l 1761 | } 1762 | p.Success = tmp 1763 | return offset, nil 1764 | } 1765 | 1766 | // for compatibility 1767 | func (p *IMServicePullResult) FastWrite(buf []byte) int { 1768 | return 0 1769 | } 1770 | 1771 | func (p *IMServicePullResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1772 | offset := 0 1773 | offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Pull_result") 1774 | if p != nil { 1775 | offset += p.fastWriteField0(buf[offset:], binaryWriter) 1776 | } 1777 | offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1778 | offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1779 | return offset 1780 | } 1781 | 1782 | func (p *IMServicePullResult) BLength() int { 1783 | l := 0 1784 | l += bthrift.Binary.StructBeginLength("Pull_result") 1785 | if p != nil { 1786 | l += p.field0Length() 1787 | } 1788 | l += bthrift.Binary.FieldStopLength() 1789 | l += bthrift.Binary.StructEndLength() 1790 | return l 1791 | } 1792 | 1793 | func (p *IMServicePullResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1794 | offset := 0 1795 | if p.IsSetSuccess() { 1796 | offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) 1797 | offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) 1798 | offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1799 | } 1800 | return offset 1801 | } 1802 | 1803 | func (p *IMServicePullResult) field0Length() int { 1804 | l := 0 1805 | if p.IsSetSuccess() { 1806 | l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) 1807 | l += p.Success.BLength() 1808 | l += bthrift.Binary.FieldEndLength() 1809 | } 1810 | return l 1811 | } 1812 | 1813 | func (p *IMServiceSendArgs) GetFirstArgument() interface{} { 1814 | return p.Req 1815 | } 1816 | 1817 | func (p *IMServiceSendResult) GetResult() interface{} { 1818 | return p.Success 1819 | } 1820 | 1821 | func (p *IMServicePullArgs) GetFirstArgument() interface{} { 1822 | return p.Req 1823 | } 1824 | 1825 | func (p *IMServicePullResult) GetResult() interface{} { 1826 | return p.Success 1827 | } 1828 | -------------------------------------------------------------------------------- /rpc-server/kitex_info.yaml: -------------------------------------------------------------------------------- 1 | kitexinfo: 2 | ServiceName: 'demo.im.rpc' 3 | ToolVersion: 'v0.5.1' 4 | -------------------------------------------------------------------------------- /rpc-server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | rpc "github.com/TikTokTechImmersion/assignment_demo_2023/rpc-server/kitex_gen/rpc/imservice" 7 | "github.com/cloudwego/kitex/pkg/rpcinfo" 8 | "github.com/cloudwego/kitex/server" 9 | etcd "github.com/kitex-contrib/registry-etcd" 10 | ) 11 | 12 | func main() { 13 | r, err := etcd.NewEtcdRegistry([]string{"etcd:2379"}) // r should not be reused. 14 | if err != nil { 15 | log.Fatal(err) 16 | } 17 | 18 | svr := rpc.NewServer(new(IMServiceImpl), server.WithRegistry(r), server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ 19 | ServiceName: "demo.rpc.server", 20 | })) 21 | 22 | err = svr.Run() 23 | if err != nil { 24 | log.Println(err.Error()) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /rpc-server/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | CURDIR=$(cd $(dirname $0); pwd) 3 | 4 | if [ "X$1" != "X" ]; then 5 | RUNTIME_ROOT=$1 6 | else 7 | RUNTIME_ROOT=${CURDIR} 8 | fi 9 | 10 | export KITEX_RUNTIME_ROOT=$RUNTIME_ROOT 11 | export KITEX_LOG_DIR="$RUNTIME_ROOT/log" 12 | 13 | if [ ! -d "$KITEX_LOG_DIR/app" ]; then 14 | mkdir -p "$KITEX_LOG_DIR/app" 15 | fi 16 | 17 | if [ ! -d "$KITEX_LOG_DIR/rpc" ]; then 18 | mkdir -p "$KITEX_LOG_DIR/rpc" 19 | fi 20 | 21 | exec "$CURDIR/bin/demo.im.rpc" 22 | --------------------------------------------------------------------------------