Files
dolt/nomdl/codegen/ref.tmpl
Erik Arvidsson 2dec53453e NomDL: Add new serialization format
The new serialization format use "t " as in typed. The rest of the
message is a JSON array describing the typed data. The type is
described by types.TypeRef

Fixes #384
Issues #281, #304
2015-10-06 15:56:10 -07:00

37 lines
764 B
Cheetah

// {{.Name}}
type {{.Name}} struct {
r ref.Ref
}
func New{{.Name}}(r ref.Ref) {{.Name}} {
return {{.Name}}{r}
}
func (r {{.Name}}) Ref() ref.Ref {
return r.r
}
func (r {{.Name}}) Equals(other {{.Name}}) bool {
return r.Ref() == other.Ref()
}
func (r {{.Name}}) NomsValue() types.Value {
return types.Ref{R: r.r}
}
func {{.Name}}FromVal(p types.Value) {{.Name}} {
return {{.Name}}{p.(types.Ref).Ref()}
}
{{template "type_ref.tmpl" .}}
func (r {{.Name}}) GetValue(cs chunks.ChunkSource) {{userType .ElemType}} {
return {{valueToUser "types.ReadValue(r.r, cs)" .ElemType}}
}
func (r {{.Name}}) SetValue(val {{userType .ElemType}}, cs chunks.ChunkSink) {{.Name}} {
ref := types.WriteValue({{userToValue "val" .ElemType}}, cs)
return {{.Name}}{ref}
}