Skip to content

Commit

Permalink
feat: support optional for java & cpp (#651)
Browse files Browse the repository at this point in the history
Signed-off-by: acrazing <[email protected]>
  • Loading branch information
acrazing authored Oct 3, 2022
1 parent a86024e commit e2b309c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions templates/cc/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ bool Validate(const {{ class . }}& m, pgv::ValidationMsg* err) {
{{ range .NonOneOfFields }}
{{- render (context .) -}}
{{ end -}}
{{ range .SyntheticOneOfFields }}
if ({{ hasAccessor (context .) }}) {
{{ render (context .) }}
}
{{ end }}
{{ range .RealOneOfs }}
switch (m.{{ .Name }}_case()) {
{{ range .Fields -}}
Expand Down
8 changes: 8 additions & 0 deletions templates/java/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const msgInnerTpl = `
{{- range .NonOneOfFields }}
{{ renderConstants (context .) }}
{{ end }}
{{ range .SyntheticOneOfFields }}
{{ renderConstants (context .) }}
{{ end }}
{{ range .RealOneOfs }}
{{ template "oneOfConst" . }}
{{ end }}
Expand All @@ -27,6 +30,11 @@ const msgInnerTpl = `
{{ range .NonOneOfFields -}}
{{ render (context .) }}
{{ end -}}
{{ range .SyntheticOneOfFields }}
if ({{ hasAccessor (context .) }}) {
{{ render (context .) }}
}
{{ end }}
{{ range .RealOneOfs }}
{{ template "oneOf" . }}
{{- end -}}
Expand Down

0 comments on commit e2b309c

Please sign in to comment.