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

feat(p2) Support hessian2 dubbo enumeration #1325

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions tool/internal_pkg/pluginmode/thriftgo/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func (p *patcher) buildTemplates() (err error) {
structLikeCodec,
structLikeProtocol,
javaClassName,
enumJavaClassName,
enumStructLikeProtocol,
processor,
)
} else {
Expand All @@ -146,6 +148,8 @@ func (p *patcher) buildTemplates() (err error) {
structLikeFieldLength,
structLikeProtocol,
javaClassName,
enumJavaClassName,
enumStructLikeProtocol,
fieldFastRead,
fieldFastReadStructLike,
fieldFastReadBaseType,
Expand Down
55 changes: 55 additions & 0 deletions tool/internal_pkg/pluginmode/thriftgo/register_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package {{ .PkgName}}

import (
"fmt"
"github.com/kitex-contrib/codec-dubbo/pkg/hessian2/enum"
s5364733 marked this conversation as resolved.
Show resolved Hide resolved

"github.com/pkg/errors"
"github.com/kitex-contrib/codec-dubbo/pkg/hessian2"
Expand All @@ -30,6 +31,13 @@ var objects{{ .IDLName}} = []interface{}{
{{- range .Scope.StructLikes}}
&{{ .GoName}}{},
{{- end}}

{{- range .Scope.Enums}}
{{- range .Values}}
{{ .GoName}},
{{- end}}
{{- end}}

}

func init() {
Expand All @@ -46,10 +54,19 @@ func Get{{.GoName}}IDLAnnotations() map[string][]string {
}
{{- end}}


{{- $Scope := .Scope}}
{{/*Store the current context for later use*/}}


{{- range .Scope.StructLikes}}
{{template "StructLikeProtocol" .}}
{{- end}}


{{template "EnumStructLikeProtocol" .}}


{{- range .Scope.Services}}
{{- range .Functions}}

Expand Down Expand Up @@ -192,3 +209,41 @@ func (p *{{$TypeName}}) JavaClassName() string {
{{- end}}{{/* end if */}}
{{- end}}{{/* end JavaClassName */}}
`

const enumJavaClassName = `
{{define "EnumJavaClassName"}}
{{- $TypeName := .GetName}}
{{- $anno := .Annotations }}
{{- $value := $anno.ILocValueByKey "JavaClassName" 0}}
{{- if ne "" $value}}
func ({{$TypeName}}) JavaClassName() string {
return "{{$value}}"
}
{{- end}}{{/* end if */}}
{{- end}}{{/* end JavaClassName */}}
`

const enumStructLikeProtocol = `
{{define "EnumStructLikeProtocol"}}
{{- range .Scope.Enums}}
{{- $EnumOfCur := . }}
{{- if gt (len $EnumOfCur.Values) 0}}
var {{$EnumOfCur.GetName}}Values = map[string]{{$EnumOfCur.GetName}}{
{{- range $idx , $EnumValSub := $EnumOfCur.Values }}
"{{$EnumValSub.GetName}}": {{$EnumValSub.GoName}},
{{- end}}
}

{{- template "EnumJavaClassName" $EnumOfCur}}
{{/* EnumValue() method */}}
func ({{$EnumOfCur.GetName}}) EnumValue(s string) enum.JavaEnum {
v, ok := {{$EnumOfCur.GetName -}}Values[s]
if ok {
return enum.JavaEnum(v)
}
return enum.InvalidJavaEnum
}
{{- end}}
{{- end}}
{{- end}}
`