enum.go 441 B

1234567891011121314151617
  1. package cc
  2. const enumTpl = `
  3. {{ $f := .Field }}{{ $r := .Rules }}
  4. {{ template "const" . }}
  5. {{ template "in" . }}
  6. {{ if $r.GetDefinedOnly }}
  7. {{ if or $f.Type.IsRepeated $f.Type.IsMap }}
  8. if (!{{ class $f.Type.Element.Enum }}_IsValid({{ accessor . }})) {
  9. {{ else }}
  10. if (!{{ class $f.Type.Enum }}_IsValid({{ accessor . }})) {
  11. {{ end }}
  12. {{ err . "value must be one of the defined enum values" }}
  13. }
  14. {{ end }}
  15. `