| // 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: stress |
| |
| package stress |
| |
| import ( |
| "fmt" |
| "time" |
| "v.io/v23" |
| "v.io/v23/context" |
| "v.io/v23/rpc" |
| "v.io/v23/security/access" |
| "v.io/v23/vdl" |
| _ "v.io/v23/vdlroot/time" |
| ) |
| |
| var _ = __VDLInit() // Must be first; see __VDLInit comments for details. |
| |
| ////////////////////////////////////////////////// |
| // Type definitions |
| |
| type StressResults struct { |
| Iterations int64 |
| Qps float64 |
| MsecsPerRpc float64 |
| } |
| |
| func (StressResults) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/js.core/stress.StressResults"` |
| }) { |
| } |
| |
| func (m *StressResults) FillVDLTarget(t vdl.Target, tt *vdl.Type) error { |
| fieldsTarget1, err := t.StartFields(tt) |
| if err != nil { |
| return err |
| } |
| |
| keyTarget2, fieldTarget3, err := fieldsTarget1.StartField("Iterations") |
| if err != vdl.ErrFieldNoExist && err != nil { |
| return err |
| } |
| if err != vdl.ErrFieldNoExist { |
| if err := fieldTarget3.FromInt(int64(m.Iterations), tt.NonOptional().Field(0).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget2, fieldTarget3); err != nil { |
| return err |
| } |
| } |
| keyTarget4, fieldTarget5, err := fieldsTarget1.StartField("Qps") |
| if err != vdl.ErrFieldNoExist && err != nil { |
| return err |
| } |
| if err != vdl.ErrFieldNoExist { |
| if err := fieldTarget5.FromFloat(float64(m.Qps), tt.NonOptional().Field(1).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget4, fieldTarget5); err != nil { |
| return err |
| } |
| } |
| keyTarget6, fieldTarget7, err := fieldsTarget1.StartField("MsecsPerRpc") |
| if err != vdl.ErrFieldNoExist && err != nil { |
| return err |
| } |
| if err != vdl.ErrFieldNoExist { |
| if err := fieldTarget7.FromFloat(float64(m.MsecsPerRpc), tt.NonOptional().Field(2).Type); err != nil { |
| return err |
| } |
| if err := fieldsTarget1.FinishField(keyTarget6, fieldTarget7); err != nil { |
| return err |
| } |
| } |
| if err := t.FinishFields(fieldsTarget1); err != nil { |
| return err |
| } |
| return nil |
| } |
| |
| func (m *StressResults) MakeVDLTarget() vdl.Target { |
| return &StressResultsTarget{Value: m} |
| } |
| |
| type StressResultsTarget struct { |
| Value *StressResults |
| iterationsTarget vdl.Int64Target |
| qpsTarget vdl.Float64Target |
| msecsPerRpcTarget vdl.Float64Target |
| vdl.TargetBase |
| vdl.FieldsTargetBase |
| } |
| |
| func (t *StressResultsTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) { |
| |
| if ttWant := vdl.TypeOf((*StressResults)(nil)).Elem(); !vdl.Compatible(tt, ttWant) { |
| return nil, fmt.Errorf("type %v incompatible with %v", tt, ttWant) |
| } |
| return t, nil |
| } |
| func (t *StressResultsTarget) StartField(name string) (key, field vdl.Target, _ error) { |
| switch name { |
| case "Iterations": |
| t.iterationsTarget.Value = &t.Value.Iterations |
| target, err := &t.iterationsTarget, error(nil) |
| return nil, target, err |
| case "Qps": |
| t.qpsTarget.Value = &t.Value.Qps |
| target, err := &t.qpsTarget, error(nil) |
| return nil, target, err |
| case "MsecsPerRpc": |
| t.msecsPerRpcTarget.Value = &t.Value.MsecsPerRpc |
| target, err := &t.msecsPerRpcTarget, error(nil) |
| return nil, target, err |
| default: |
| return nil, nil, fmt.Errorf("field %s not in struct v.io/x/js.core/stress.StressResults", name) |
| } |
| } |
| func (t *StressResultsTarget) FinishField(_, _ vdl.Target) error { |
| return nil |
| } |
| func (t *StressResultsTarget) FinishFields(_ vdl.FieldsTarget) error { |
| |
| return nil |
| } |
| |
| ////////////////////////////////////////////////// |
| // Interface definitions |
| |
| // StressClientMethods is the client interface |
| // containing Stress methods. |
| type StressClientMethods interface { |
| // Echo returns the payload that it receives. |
| Echo(_ *context.T, Payload []byte, _ ...rpc.CallOpt) ([]byte, error) |
| // ServerEcho runs as many calls to Echo on the name provided in the duration |
| // specified and returns the peformance results. |
| ServerEcho(_ *context.T, totalTime time.Duration, name string, _ ...rpc.CallOpt) (StressResults, error) |
| } |
| |
| // StressClientStub adds universal methods to StressClientMethods. |
| type StressClientStub interface { |
| StressClientMethods |
| rpc.UniversalServiceMethods |
| } |
| |
| // StressClient returns a client stub for Stress. |
| func StressClient(name string) StressClientStub { |
| return implStressClientStub{name} |
| } |
| |
| type implStressClientStub struct { |
| name string |
| } |
| |
| func (c implStressClientStub) Echo(ctx *context.T, i0 []byte, opts ...rpc.CallOpt) (o0 []byte, err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "Echo", []interface{}{i0}, []interface{}{&o0}, opts...) |
| return |
| } |
| |
| func (c implStressClientStub) ServerEcho(ctx *context.T, i0 time.Duration, i1 string, opts ...rpc.CallOpt) (o0 StressResults, err error) { |
| err = v23.GetClient(ctx).Call(ctx, c.name, "ServerEcho", []interface{}{i0, i1}, []interface{}{&o0}, opts...) |
| return |
| } |
| |
| // StressServerMethods is the interface a server writer |
| // implements for Stress. |
| type StressServerMethods interface { |
| // Echo returns the payload that it receives. |
| Echo(_ *context.T, _ rpc.ServerCall, Payload []byte) ([]byte, error) |
| // ServerEcho runs as many calls to Echo on the name provided in the duration |
| // specified and returns the peformance results. |
| ServerEcho(_ *context.T, _ rpc.ServerCall, totalTime time.Duration, name string) (StressResults, error) |
| } |
| |
| // StressServerStubMethods is the server interface containing |
| // Stress methods, as expected by rpc.Server. |
| // There is no difference between this interface and StressServerMethods |
| // since there are no streaming methods. |
| type StressServerStubMethods StressServerMethods |
| |
| // StressServerStub adds universal methods to StressServerStubMethods. |
| type StressServerStub interface { |
| StressServerStubMethods |
| // Describe the Stress interfaces. |
| Describe__() []rpc.InterfaceDesc |
| } |
| |
| // StressServer returns a server stub for Stress. |
| // It converts an implementation of StressServerMethods into |
| // an object that may be used by rpc.Server. |
| func StressServer(impl StressServerMethods) StressServerStub { |
| stub := implStressServerStub{ |
| impl: impl, |
| } |
| // Initialize GlobState; always check the stub itself first, to handle the |
| // case where the user has the Glob method defined in their VDL source. |
| if gs := rpc.NewGlobState(stub); gs != nil { |
| stub.gs = gs |
| } else if gs := rpc.NewGlobState(impl); gs != nil { |
| stub.gs = gs |
| } |
| return stub |
| } |
| |
| type implStressServerStub struct { |
| impl StressServerMethods |
| gs *rpc.GlobState |
| } |
| |
| func (s implStressServerStub) Echo(ctx *context.T, call rpc.ServerCall, i0 []byte) ([]byte, error) { |
| return s.impl.Echo(ctx, call, i0) |
| } |
| |
| func (s implStressServerStub) ServerEcho(ctx *context.T, call rpc.ServerCall, i0 time.Duration, i1 string) (StressResults, error) { |
| return s.impl.ServerEcho(ctx, call, i0, i1) |
| } |
| |
| func (s implStressServerStub) Globber() *rpc.GlobState { |
| return s.gs |
| } |
| |
| func (s implStressServerStub) Describe__() []rpc.InterfaceDesc { |
| return []rpc.InterfaceDesc{StressDesc} |
| } |
| |
| // StressDesc describes the Stress interface. |
| var StressDesc rpc.InterfaceDesc = descStress |
| |
| // descStress hides the desc to keep godoc clean. |
| var descStress = rpc.InterfaceDesc{ |
| Name: "Stress", |
| PkgPath: "v.io/x/js.core/stress", |
| Methods: []rpc.MethodDesc{ |
| { |
| Name: "Echo", |
| Doc: "// Echo returns the payload that it receives.", |
| InArgs: []rpc.ArgDesc{ |
| {"Payload", ``}, // []byte |
| }, |
| OutArgs: []rpc.ArgDesc{ |
| {"", ``}, // []byte |
| }, |
| Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Read"))}, |
| }, |
| { |
| Name: "ServerEcho", |
| Doc: "// ServerEcho runs as many calls to Echo on the name provided in the duration\n// specified and returns the peformance results.", |
| InArgs: []rpc.ArgDesc{ |
| {"totalTime", ``}, // time.Duration |
| {"name", ``}, // string |
| }, |
| OutArgs: []rpc.ArgDesc{ |
| {"", ``}, // StressResults |
| }, |
| Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Read"))}, |
| }, |
| }, |
| } |
| |
| 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{}{} |
| } |
| |
| // Register types. |
| vdl.Register((*StressResults)(nil)) |
| |
| return struct{}{} |
| } |