mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-30 10:45:18 -06:00
This is needed to be able to round trip enums. If there is no codegen for an enum that is read from the datastore we now return a types.Enum which can be serialized back to the same sequence.
47 lines
1.0 KiB
Cheetah
47 lines
1.0 KiB
Cheetah
{{$typesPackage := .TypesPackage}}
|
|
|
|
// {{.Name}}
|
|
|
|
type {{.Name}} uint32
|
|
|
|
{{$name := .Name}}
|
|
const ({{range $index, $id := .Ids}}
|
|
{{title $id}}{{if eq $index 0}} {{$name}} = iota{{end}}{{end}}
|
|
)
|
|
|
|
func New{{.Name}}() {{.Name}} {
|
|
return {{.Name}}(0)
|
|
}
|
|
|
|
var __typeRefFor{{.Name}} {{$typesPackage}}TypeRef
|
|
|
|
func (e {{.Name}}) TypeRef() {{$typesPackage}}TypeRef {
|
|
return __typeRefFor{{.Name}}
|
|
}
|
|
|
|
func init() {
|
|
__typeRefFor{{.Name}} = {{$typesPackage}}MakeTypeRef(__{{.PackageName}}PackageInFile_{{.FileID}}_CachedRef, {{.Ordinal}})
|
|
{{$typesPackage}}RegisterEnum(__typeRefFor{{.Name}}, builderFor{{.Name}}, readerFor{{.Name}})
|
|
}
|
|
|
|
func builderFor{{.Name}}(v uint32) {{$typesPackage}}Value {
|
|
return {{.Name}}(v)
|
|
}
|
|
|
|
func readerFor{{.Name}}(v {{$typesPackage}}Value) uint32 {
|
|
return uint32(v.({{.Name}}))
|
|
}
|
|
|
|
func (e {{.Name}}) Equals(other {{$typesPackage}}Value) bool {
|
|
return e == other
|
|
}
|
|
|
|
func (e {{.Name}}) Ref() ref.Ref {
|
|
throwaway := ref.Ref{}
|
|
return {{$typesPackage}}EnsureRef(&throwaway, e)
|
|
}
|
|
|
|
func (e {{.Name}}) Chunks() []ref.Ref {
|
|
return nil
|
|
}
|