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

[P2] The support of Extension type Enumeration #88

Open
s5364733 opened this issue Mar 26, 2024 · 4 comments
Open

[P2] The support of Extension type Enumeration #88

s5364733 opened this issue Mar 26, 2024 · 4 comments

Comments

@s5364733
Copy link

It seems that enumeration is not supported now, but Hessian-dubbo already has support for int enumeration.

// POJO interface
// !!! Pls attention that Every field name should be upper case.
// Otherwise the app may panic.
type POJO interface {
	JavaClassName() string // got a go struct's Java Class package name which should be a POJO class.
}

// POJOEnum enum for POJO
type POJOEnum interface {
	POJO
	String() string
	EnumValue(string) JavaEnum
}

// JavaEnum type
type JavaEnum int32

// JavaEnumClass struct
type JavaEnumClass struct {
	name string
}

The writing method when using the hessian2 protocol conversion type normally is as follows:

type CompanyEnum hessian.JavaEnum

const (
	Kigger     CompanyEnum = 5
	Zharhg CompanyEnum = 1
)

var companyName = map[CompanyEnum]string{
	Kigger:     "Kigger",
	Zharhg : "Zharhg ",
}

var companyValue = map[string]CompanyEnum{
	"Kigger":     Kigger,
	"Zharhg ": Zharhg ,
}

func (g CompanyEnum) JavaClassName() string {
	return "xxxxxx"
}

func (g CompanyEnum) String() string {
	s, ok := companyName[g]
	if ok {
		return s
	}

	return strconv.Itoa(int(g))
}

func (g CompanyEnum) EnumValue(s string) hessian.JavaEnum {
	v, ok := companyValue[s]
	if ok {
		return hessian.JavaEnum(v)
	}

	return hessian.InvalidJavaEnum
}

Because Codec-dubbo calls hessian-dubbo for serialization at the bottom level, the purpose can be achieved as long as the type can be guaranteed to be serialized by hessian-dubbo. For specific real-time solutions, you can refer to the implementation of extended thrift.

具体实现参考:
dubbo-go-hessian2
IDL-REF

@s5364733 s5364733 changed the title [P2] Support Enumeration [P2] The support of Extension type Enumeration Mar 26, 2024
@Lvnszn
Copy link
Collaborator

Lvnszn commented Mar 26, 2024

嗯,#64 跟这个应该是一个事情。尽量基于 thrift 的 enum 去实现。

@DMwangnima
Copy link
Collaborator

需要参照 thrift 的 enum,让它的生成内容向 dubbo-go-hessian2 已经支持的范围靠拢。并且我们最好不要修改 thriftgo,应该可以参照 cloudwego/kitex#1076, 拿到 thriftgo 解析好的 AST 后,再生成 hessian2 独有的代码

@s5364733
Copy link
Author

s5364733 commented Apr 2, 2024

梳理一下流程

1. 定义thrift 原语法如下:


enum Direction {
    NORTH,
    EAST,
    SOUTH,
    WEST
}

struct Location {
    1: Direction direction,
    2: i32 distance
}

2. 使用kitex cmd thrfit go 插件解析到thrift ast
3. 通过AST 拿到ENUM 相关参数
4. 通过参数在 register_tpl.go 中加入hessian-go-dubbo支持的枚举语法模板
5. 生成兼容代码,

生成兼容代码之后 因为Codec-Dubbo使用hessian2编码枚举,所以编码层应该不需要改动

@Lvnszn
Copy link
Collaborator

Lvnszn commented Apr 2, 2024

有几个问题还得确认

  1. thrift 原本生成的 enum 跟你想要的可能不是一个东西, enum 在 hessian 那边需要设定类型,实现接口和进行注册。这块应该需要设计一下怎么适配
  2. 然后适配 enum 的代码也需要设计一下, dubbo-codec 和 kitex 这两块怎么相互引用。

s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 11, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 11, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 11, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 15, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 15, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 15, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 17, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 17, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 17, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 25, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 25, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 25, 2024
s5364733 added a commit to s5364733/codec-dubbo that referenced this issue Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants