Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kitex.exe 使用 protobuf 生成的代码无法正确处理使用 google.protobuf.Empty 的无参函数 #1145

Closed
zhangsilly opened this issue Oct 18, 2023 · 1 comment

Comments

@zhangsilly
Copy link

Describe the bug

IDL定义

syntax = "proto3";

package demo.export;

option go_package = "demo/kitex_gen/provider";

import "google/protobuf/empty.proto";

message Response {
    int64 code = 1;
}

service DemoProvider {
  rpc Hello(google.protobuf.Empty) returns (Response) {}
}

运行 kitex.exe 命令生成代码,最终生成的 demo\kitex_gen\provider\demoprovider\demoprovider.go 代码如下但不正确:

import (
    emptypb "google.golang.org/protobuf/types/known/emptypb"
)

type HelloArgs struct {
	Req *emptypb.Empty
}

func (p *HelloArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
	if !p.IsSetReq() {
		p.Req = new(emptypb.Empty)
	}
	return p.Req.FastRead(buf, _type, number)
}

func (p *HelloArgs) FastWrite(buf []byte) (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.FastWrite(buf)
}

func (p *HelloArgs) Size() (n int) {
	if !p.IsSetReq() {
		return 0
	}
	return p.Req.Size()
}

代码提示错误:

*emptypb.Empty 没有 FastRead、FastWrite、Size 三个函数

@HeyJavaBean
Copy link
Member

因为 fastpb 现在还没支持 google protoc 引用的产物生成
参考:cloudwego/fastpb#17

可以先执行 kitex 命令的时候带上 -no-fast-api 参数,把 fastpb 改为正常的 protobuf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants