cloudflared-mirror/vendor/zombiezen.com/go/capnproto2/capnpc-go/templates/structStructField

34 lines
1.0 KiB
Plaintext

func (s {{.Node.Name}}) {{.Field.Name|title}}() ({{.FieldType}}, error) {
{{template "_checktag" . -}}
p, err := s.Struct.Ptr({{.Field.Slot.Offset}})
{{if .Default.IsValid -}}
if err != nil {
return {{.FieldType}}{}, err
}
ss, err := p.StructDefault({{.Default}})
return {{.FieldType}}{Struct: ss}, err
{{- else -}}
return {{.FieldType}}{Struct: p.Struct()}, err
{{- end}}
}
{{template "_hasfield" .}}
func (s {{.Node.Name}}) Set{{.Field.Name|title}}(v {{.FieldType}}) error {
{{template "_settag" . -}}
return s.Struct.SetPtr({{.Field.Slot.Offset}}, v.Struct.ToPtr())
}
// New{{.Field.Name|title}} sets the {{.Field.Name}} field to a newly
// allocated {{.FieldType}} struct, preferring placement in s's segment.
func (s {{.Node.Name}}) New{{.Field.Name|title}}() ({{.FieldType}}, error) {
{{template "_settag" . -}}
ss, err := {{.G.RemoteNodeNew .TypeNode .Node}}(s.Struct.Segment())
if err != nil {
return {{.FieldType}}{}, err
}
err = s.Struct.SetPtr({{.Field.Slot.Offset}}, ss.Struct.ToPtr())
return ss, err
}