| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| // This file was auto-generated by the vanadium vdl tool. |
| // Package: channel |
| |
| package channel |
| |
| import ( |
| "fmt" |
| "reflect" |
| "v.io/v23/vdl" |
| "v.io/v23/vom" |
| ) |
| |
| var _ = __VDLInit() // Must be first; see __VDLInit comments for details. |
| |
| ////////////////////////////////////////////////// |
| // Type definitions |
| |
| type Request struct { |
| Type string |
| Seq uint32 |
| Body *vom.RawBytes |
| } |
| |
| func (Request) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/ref/services/wspr/internal/channel.Request"` |
| }) { |
| } |
| |
| func (m *Request) FillVDLTarget(t vdl.Target, tt *vdl.Type) error { |
| fieldsTarget1, err := t.StartFields(tt) |
| if err != nil { |
| return err |
| } |
| var4 := (m.Type == "") |
| if var4 { |
| if err := fieldsTarget1.ZeroField("Type"); err != nil && err != vdl.ErrFieldNoExist { |
| return err |
| } |
| } else { |
| keyTarget2, fieldTarget3, err := fieldsTarget1.StartField("Type") |
| if err != vdl.ErrFieldNoExist { |
| if err != nil { |
| return err |
| } |
| if err := fieldTarget3.FromString(string(m.Type), tt.NonOptional().Field(0).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget2, fieldTarget3); err != nil { |
| return err |
| } |
| } |
| } |
| var7 := (m.Seq == uint32(0)) |
| if var7 { |
| if err := fieldsTarget1.ZeroField("Seq"); err != nil && err != vdl.ErrFieldNoExist { |
| return err |
| } |
| } else { |
| keyTarget5, fieldTarget6, err := fieldsTarget1.StartField("Seq") |
| if err != vdl.ErrFieldNoExist { |
| if err != nil { |
| return err |
| } |
| if err := fieldTarget6.FromUint(uint64(m.Seq), tt.NonOptional().Field(1).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget5, fieldTarget6); err != nil { |
| return err |
| } |
| } |
| } |
| var10 := m.Body == nil || m.Body.IsNilAny() |
| if var10 { |
| if err := fieldsTarget1.ZeroField("Body"); err != nil && err != vdl.ErrFieldNoExist { |
| return err |
| } |
| } else { |
| keyTarget8, fieldTarget9, err := fieldsTarget1.StartField("Body") |
| if err != vdl.ErrFieldNoExist { |
| if err != nil { |
| return err |
| } |
| |
| if err := m.Body.FillVDLTarget(fieldTarget9, tt.NonOptional().Field(2).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget8, fieldTarget9); err != nil { |
| return err |
| } |
| } |
| } |
| if err := t.FinishFields(fieldsTarget1); err != nil { |
| return err |
| } |
| return nil |
| } |
| |
| func (m *Request) MakeVDLTarget() vdl.Target { |
| return &RequestTarget{Value: m} |
| } |
| |
| type RequestTarget struct { |
| Value *Request |
| typeTarget vdl.StringTarget |
| seqTarget vdl.Uint32Target |
| |
| vdl.TargetBase |
| vdl.FieldsTargetBase |
| } |
| |
| func (t *RequestTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) { |
| |
| if ttWant := vdl.TypeOf((*Request)(nil)).Elem(); !vdl.Compatible(tt, ttWant) { |
| return nil, fmt.Errorf("type %v incompatible with %v", tt, ttWant) |
| } |
| return t, nil |
| } |
| func (t *RequestTarget) StartField(name string) (key, field vdl.Target, _ error) { |
| switch name { |
| case "Type": |
| t.typeTarget.Value = &t.Value.Type |
| target, err := &t.typeTarget, error(nil) |
| return nil, target, err |
| case "Seq": |
| t.seqTarget.Value = &t.Value.Seq |
| target, err := &t.seqTarget, error(nil) |
| return nil, target, err |
| case "Body": |
| target, err := vdl.ReflectTarget(reflect.ValueOf(&t.Value.Body)) |
| return nil, target, err |
| default: |
| return nil, nil, fmt.Errorf("field %s not in struct v.io/x/ref/services/wspr/internal/channel.Request", name) |
| } |
| } |
| func (t *RequestTarget) FinishField(_, _ vdl.Target) error { |
| return nil |
| } |
| func (t *RequestTarget) ZeroField(name string) error { |
| switch name { |
| case "Type": |
| t.Value.Type = "" |
| return nil |
| case "Seq": |
| t.Value.Seq = uint32(0) |
| return nil |
| case "Body": |
| t.Value.Body = vom.RawBytesOf(vdl.ZeroValue(vdl.AnyType)) |
| return nil |
| default: |
| return fmt.Errorf("field %s not in struct v.io/x/ref/services/wspr/internal/channel.Request", name) |
| } |
| } |
| func (t *RequestTarget) FinishFields(_ vdl.FieldsTarget) error { |
| |
| return nil |
| } |
| |
| type Response struct { |
| ReqSeq uint32 |
| Err string // TODO(bprosnitz) change this back to error when it is possible to do so. (issue 368) |
| Body *vom.RawBytes |
| } |
| |
| func (Response) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/ref/services/wspr/internal/channel.Response"` |
| }) { |
| } |
| |
| func (m *Response) FillVDLTarget(t vdl.Target, tt *vdl.Type) error { |
| fieldsTarget1, err := t.StartFields(tt) |
| if err != nil { |
| return err |
| } |
| var4 := (m.ReqSeq == uint32(0)) |
| if var4 { |
| if err := fieldsTarget1.ZeroField("ReqSeq"); err != nil && err != vdl.ErrFieldNoExist { |
| return err |
| } |
| } else { |
| keyTarget2, fieldTarget3, err := fieldsTarget1.StartField("ReqSeq") |
| if err != vdl.ErrFieldNoExist { |
| if err != nil { |
| return err |
| } |
| if err := fieldTarget3.FromUint(uint64(m.ReqSeq), tt.NonOptional().Field(0).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget2, fieldTarget3); err != nil { |
| return err |
| } |
| } |
| } |
| var7 := (m.Err == "") |
| if var7 { |
| if err := fieldsTarget1.ZeroField("Err"); err != nil && err != vdl.ErrFieldNoExist { |
| return err |
| } |
| } else { |
| keyTarget5, fieldTarget6, err := fieldsTarget1.StartField("Err") |
| if err != vdl.ErrFieldNoExist { |
| if err != nil { |
| return err |
| } |
| if err := fieldTarget6.FromString(string(m.Err), tt.NonOptional().Field(1).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget5, fieldTarget6); err != nil { |
| return err |
| } |
| } |
| } |
| var10 := m.Body == nil || m.Body.IsNilAny() |
| if var10 { |
| if err := fieldsTarget1.ZeroField("Body"); err != nil && err != vdl.ErrFieldNoExist { |
| return err |
| } |
| } else { |
| keyTarget8, fieldTarget9, err := fieldsTarget1.StartField("Body") |
| if err != vdl.ErrFieldNoExist { |
| if err != nil { |
| return err |
| } |
| |
| if err := m.Body.FillVDLTarget(fieldTarget9, tt.NonOptional().Field(2).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget8, fieldTarget9); err != nil { |
| return err |
| } |
| } |
| } |
| if err := t.FinishFields(fieldsTarget1); err != nil { |
| return err |
| } |
| return nil |
| } |
| |
| func (m *Response) MakeVDLTarget() vdl.Target { |
| return &ResponseTarget{Value: m} |
| } |
| |
| type ResponseTarget struct { |
| Value *Response |
| reqSeqTarget vdl.Uint32Target |
| errTarget vdl.StringTarget |
| |
| vdl.TargetBase |
| vdl.FieldsTargetBase |
| } |
| |
| func (t *ResponseTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) { |
| |
| if ttWant := vdl.TypeOf((*Response)(nil)).Elem(); !vdl.Compatible(tt, ttWant) { |
| return nil, fmt.Errorf("type %v incompatible with %v", tt, ttWant) |
| } |
| return t, nil |
| } |
| func (t *ResponseTarget) StartField(name string) (key, field vdl.Target, _ error) { |
| switch name { |
| case "ReqSeq": |
| t.reqSeqTarget.Value = &t.Value.ReqSeq |
| target, err := &t.reqSeqTarget, error(nil) |
| return nil, target, err |
| case "Err": |
| t.errTarget.Value = &t.Value.Err |
| target, err := &t.errTarget, error(nil) |
| return nil, target, err |
| case "Body": |
| target, err := vdl.ReflectTarget(reflect.ValueOf(&t.Value.Body)) |
| return nil, target, err |
| default: |
| return nil, nil, fmt.Errorf("field %s not in struct v.io/x/ref/services/wspr/internal/channel.Response", name) |
| } |
| } |
| func (t *ResponseTarget) FinishField(_, _ vdl.Target) error { |
| return nil |
| } |
| func (t *ResponseTarget) ZeroField(name string) error { |
| switch name { |
| case "ReqSeq": |
| t.Value.ReqSeq = uint32(0) |
| return nil |
| case "Err": |
| t.Value.Err = "" |
| return nil |
| case "Body": |
| t.Value.Body = vom.RawBytesOf(vdl.ZeroValue(vdl.AnyType)) |
| return nil |
| default: |
| return fmt.Errorf("field %s not in struct v.io/x/ref/services/wspr/internal/channel.Response", name) |
| } |
| } |
| func (t *ResponseTarget) FinishFields(_ vdl.FieldsTarget) error { |
| |
| return nil |
| } |
| |
| type ( |
| // Message represents any single field of the Message union type. |
| Message interface { |
| // Index returns the field index. |
| Index() int |
| // Interface returns the field value as an interface. |
| Interface() interface{} |
| // Name returns the field name. |
| Name() string |
| // __VDLReflect describes the Message union type. |
| __VDLReflect(__MessageReflect) |
| FillVDLTarget(vdl.Target, *vdl.Type) error |
| } |
| // MessageRequest represents field Request of the Message union type. |
| MessageRequest struct{ Value Request } |
| // MessageResponse represents field Response of the Message union type. |
| MessageResponse struct{ Value Response } |
| // __MessageReflect describes the Message union type. |
| __MessageReflect struct { |
| Name string `vdl:"v.io/x/ref/services/wspr/internal/channel.Message"` |
| Type Message |
| UnionTargetFactory messageTargetFactory |
| Union struct { |
| Request MessageRequest |
| Response MessageResponse |
| } |
| } |
| ) |
| |
| func (x MessageRequest) Index() int { return 0 } |
| func (x MessageRequest) Interface() interface{} { return x.Value } |
| func (x MessageRequest) Name() string { return "Request" } |
| func (x MessageRequest) __VDLReflect(__MessageReflect) {} |
| |
| func (m MessageRequest) FillVDLTarget(t vdl.Target, tt *vdl.Type) error { |
| fieldsTarget1, err := t.StartFields(tt) |
| if err != nil { |
| return err |
| } |
| keyTarget2, fieldTarget3, err := fieldsTarget1.StartField("Request") |
| if err != nil { |
| return err |
| } |
| |
| if err := m.Value.FillVDLTarget(fieldTarget3, tt.NonOptional().Field(0).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget2, fieldTarget3); err != nil { |
| return err |
| } |
| if err := t.FinishFields(fieldsTarget1); err != nil { |
| return err |
| } |
| |
| return nil |
| } |
| |
| func (m MessageRequest) MakeVDLTarget() vdl.Target { |
| return nil |
| } |
| |
| func (x MessageResponse) Index() int { return 1 } |
| func (x MessageResponse) Interface() interface{} { return x.Value } |
| func (x MessageResponse) Name() string { return "Response" } |
| func (x MessageResponse) __VDLReflect(__MessageReflect) {} |
| |
| func (m MessageResponse) FillVDLTarget(t vdl.Target, tt *vdl.Type) error { |
| fieldsTarget1, err := t.StartFields(tt) |
| if err != nil { |
| return err |
| } |
| keyTarget2, fieldTarget3, err := fieldsTarget1.StartField("Response") |
| if err != nil { |
| return err |
| } |
| |
| if err := m.Value.FillVDLTarget(fieldTarget3, tt.NonOptional().Field(1).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget2, fieldTarget3); err != nil { |
| return err |
| } |
| if err := t.FinishFields(fieldsTarget1); err != nil { |
| return err |
| } |
| |
| return nil |
| } |
| |
| func (m MessageResponse) MakeVDLTarget() vdl.Target { |
| return nil |
| } |
| |
| type MessageTarget struct { |
| Value *Message |
| fieldName string |
| |
| vdl.TargetBase |
| vdl.FieldsTargetBase |
| } |
| |
| func (t *MessageTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) { |
| if ttWant := vdl.TypeOf((*Message)(nil)); !vdl.Compatible(tt, ttWant) { |
| return nil, fmt.Errorf("type %v incompatible with %v", tt, ttWant) |
| } |
| |
| return t, nil |
| } |
| func (t *MessageTarget) StartField(name string) (key, field vdl.Target, _ error) { |
| t.fieldName = name |
| switch name { |
| case "Request": |
| val := Request{ |
| Body: vom.RawBytesOf(vdl.ZeroValue(vdl.AnyType)), |
| } |
| return nil, &RequestTarget{Value: &val}, nil |
| case "Response": |
| val := Response{ |
| Body: vom.RawBytesOf(vdl.ZeroValue(vdl.AnyType)), |
| } |
| return nil, &ResponseTarget{Value: &val}, nil |
| default: |
| return nil, nil, fmt.Errorf("field %s not in union v.io/x/ref/services/wspr/internal/channel.Message", name) |
| } |
| } |
| func (t *MessageTarget) FinishField(_, fieldTarget vdl.Target) error { |
| switch t.fieldName { |
| case "Request": |
| *t.Value = MessageRequest{*(fieldTarget.(*RequestTarget)).Value} |
| case "Response": |
| *t.Value = MessageResponse{*(fieldTarget.(*ResponseTarget)).Value} |
| } |
| return nil |
| } |
| func (t *MessageTarget) FinishFields(_ vdl.FieldsTarget) error { |
| |
| return nil |
| } |
| |
| type messageTargetFactory struct{} |
| |
| func (t messageTargetFactory) VDLMakeUnionTarget(union interface{}) (vdl.Target, error) { |
| if typedUnion, ok := union.(*Message); ok { |
| return &MessageTarget{Value: typedUnion}, nil |
| } |
| return nil, fmt.Errorf("got %T, want *Message", union) |
| } |
| |
| var __VDLInitCalled bool |
| |
| // __VDLInit performs vdl initialization. It is safe to call multiple times. |
| // If you have an init ordering issue, just insert the following line verbatim |
| // into your source files in this package, right after the "package foo" clause: |
| // |
| // var _ = __VDLInit() |
| // |
| // The purpose of this function is to ensure that vdl initialization occurs in |
| // the right order, and very early in the init sequence. In particular, vdl |
| // registration and package variable initialization needs to occur before |
| // functions like vdl.TypeOf will work properly. |
| // |
| // This function returns a dummy value, so that it can be used to initialize the |
| // first var in the file, to take advantage of Go's defined init order. |
| func __VDLInit() struct{} { |
| if __VDLInitCalled { |
| return struct{}{} |
| } |
| __VDLInitCalled = true |
| |
| // Register types. |
| vdl.Register((*Request)(nil)) |
| vdl.Register((*Response)(nil)) |
| vdl.Register((*Message)(nil)) |
| |
| return struct{}{} |
| } |