blob: 90da4da5e2c4314944de319087d45a043692a676 [file] [log] [blame]
// 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: stats
// Packages stats defines the non-native types exported by the stats service.
package stats
import (
"fmt"
"v.io/v23/vdl"
)
var _ = __VDLInit() // Must be first; see __VDLInit comments for details.
//////////////////////////////////////////////////
// Type definitions
// HistogramBucket is one histogram bucket.
type HistogramBucket struct {
// LowBound is the lower bound of the bucket.
LowBound int64
// Count is the number of values in the bucket.
Count int64
}
func (HistogramBucket) __VDLReflect(struct {
Name string `vdl:"v.io/x/ref/services/stats.HistogramBucket"`
}) {
}
func (m *HistogramBucket) FillVDLTarget(t vdl.Target, tt *vdl.Type) error {
fieldsTarget1, err := t.StartFields(tt)
if err != nil {
return err
}
var4 := (m.LowBound == int64(0))
if var4 {
if err := fieldsTarget1.ZeroField("LowBound"); err != nil && err != vdl.ErrFieldNoExist {
return err
}
} else {
keyTarget2, fieldTarget3, err := fieldsTarget1.StartField("LowBound")
if err != vdl.ErrFieldNoExist {
if err != nil {
return err
}
if err := fieldTarget3.FromInt(int64(m.LowBound), tt.NonOptional().Field(0).Type); err != nil {
return err
}
if err := fieldsTarget1.FinishField(keyTarget2, fieldTarget3); err != nil {
return err
}
}
}
var7 := (m.Count == int64(0))
if var7 {
if err := fieldsTarget1.ZeroField("Count"); err != nil && err != vdl.ErrFieldNoExist {
return err
}
} else {
keyTarget5, fieldTarget6, err := fieldsTarget1.StartField("Count")
if err != vdl.ErrFieldNoExist {
if err != nil {
return err
}
if err := fieldTarget6.FromInt(int64(m.Count), tt.NonOptional().Field(1).Type); err != nil {
return err
}
if err := fieldsTarget1.FinishField(keyTarget5, fieldTarget6); err != nil {
return err
}
}
}
if err := t.FinishFields(fieldsTarget1); err != nil {
return err
}
return nil
}
func (m *HistogramBucket) MakeVDLTarget() vdl.Target {
return &HistogramBucketTarget{Value: m}
}
type HistogramBucketTarget struct {
Value *HistogramBucket
lowBoundTarget vdl.Int64Target
countTarget vdl.Int64Target
vdl.TargetBase
vdl.FieldsTargetBase
}
func (t *HistogramBucketTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) {
if ttWant := vdl.TypeOf((*HistogramBucket)(nil)).Elem(); !vdl.Compatible(tt, ttWant) {
return nil, fmt.Errorf("type %v incompatible with %v", tt, ttWant)
}
return t, nil
}
func (t *HistogramBucketTarget) StartField(name string) (key, field vdl.Target, _ error) {
switch name {
case "LowBound":
t.lowBoundTarget.Value = &t.Value.LowBound
target, err := &t.lowBoundTarget, error(nil)
return nil, target, err
case "Count":
t.countTarget.Value = &t.Value.Count
target, err := &t.countTarget, error(nil)
return nil, target, err
default:
return nil, nil, fmt.Errorf("field %s not in struct v.io/x/ref/services/stats.HistogramBucket", name)
}
}
func (t *HistogramBucketTarget) FinishField(_, _ vdl.Target) error {
return nil
}
func (t *HistogramBucketTarget) ZeroField(name string) error {
switch name {
case "LowBound":
t.Value.LowBound = int64(0)
return nil
case "Count":
t.Value.Count = int64(0)
return nil
default:
return fmt.Errorf("field %s not in struct v.io/x/ref/services/stats.HistogramBucket", name)
}
}
func (t *HistogramBucketTarget) FinishFields(_ vdl.FieldsTarget) error {
return nil
}
func (x *HistogramBucket) VDLRead(dec vdl.Decoder) error {
*x = HistogramBucket{}
var err error
if err = dec.StartValue(); err != nil {
return err
}
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
}
for {
f, err := dec.NextField()
if err != nil {
return err
}
switch f {
case "":
return dec.FinishValue()
case "LowBound":
if err = dec.StartValue(); err != nil {
return err
}
if x.LowBound, err = dec.DecodeInt(64); err != nil {
return err
}
if err = dec.FinishValue(); err != nil {
return err
}
case "Count":
if err = dec.StartValue(); err != nil {
return err
}
if x.Count, err = dec.DecodeInt(64); err != nil {
return err
}
if err = dec.FinishValue(); err != nil {
return err
}
default:
if err = dec.SkipValue(); err != nil {
return err
}
}
}
}
// HistogramValue is the value of Histogram objects.
type HistogramValue struct {
// Count is the total number of values added to the histogram.
Count int64
// Sum is the sum of all the values added to the histogram.
Sum int64
// Min is the minimum of all the values added to the histogram.
Min int64
// Max is the maximum of all the values added to the histogram.
Max int64
// Buckets contains all the buckets of the histogram.
Buckets []HistogramBucket
}
func (HistogramValue) __VDLReflect(struct {
Name string `vdl:"v.io/x/ref/services/stats.HistogramValue"`
}) {
}
func (m *HistogramValue) FillVDLTarget(t vdl.Target, tt *vdl.Type) error {
fieldsTarget1, err := t.StartFields(tt)
if err != nil {
return err
}
var4 := (m.Count == int64(0))
if var4 {
if err := fieldsTarget1.ZeroField("Count"); err != nil && err != vdl.ErrFieldNoExist {
return err
}
} else {
keyTarget2, fieldTarget3, err := fieldsTarget1.StartField("Count")
if err != vdl.ErrFieldNoExist {
if err != nil {
return err
}
if err := fieldTarget3.FromInt(int64(m.Count), tt.NonOptional().Field(0).Type); err != nil {
return err
}
if err := fieldsTarget1.FinishField(keyTarget2, fieldTarget3); err != nil {
return err
}
}
}
var7 := (m.Sum == int64(0))
if var7 {
if err := fieldsTarget1.ZeroField("Sum"); err != nil && err != vdl.ErrFieldNoExist {
return err
}
} else {
keyTarget5, fieldTarget6, err := fieldsTarget1.StartField("Sum")
if err != vdl.ErrFieldNoExist {
if err != nil {
return err
}
if err := fieldTarget6.FromInt(int64(m.Sum), tt.NonOptional().Field(1).Type); err != nil {
return err
}
if err := fieldsTarget1.FinishField(keyTarget5, fieldTarget6); err != nil {
return err
}
}
}
var10 := (m.Min == int64(0))
if var10 {
if err := fieldsTarget1.ZeroField("Min"); err != nil && err != vdl.ErrFieldNoExist {
return err
}
} else {
keyTarget8, fieldTarget9, err := fieldsTarget1.StartField("Min")
if err != vdl.ErrFieldNoExist {
if err != nil {
return err
}
if err := fieldTarget9.FromInt(int64(m.Min), tt.NonOptional().Field(2).Type); err != nil {
return err
}
if err := fieldsTarget1.FinishField(keyTarget8, fieldTarget9); err != nil {
return err
}
}
}
var13 := (m.Max == int64(0))
if var13 {
if err := fieldsTarget1.ZeroField("Max"); err != nil && err != vdl.ErrFieldNoExist {
return err
}
} else {
keyTarget11, fieldTarget12, err := fieldsTarget1.StartField("Max")
if err != vdl.ErrFieldNoExist {
if err != nil {
return err
}
if err := fieldTarget12.FromInt(int64(m.Max), tt.NonOptional().Field(3).Type); err != nil {
return err
}
if err := fieldsTarget1.FinishField(keyTarget11, fieldTarget12); err != nil {
return err
}
}
}
var var16 bool
if len(m.Buckets) == 0 {
var16 = true
}
if var16 {
if err := fieldsTarget1.ZeroField("Buckets"); err != nil && err != vdl.ErrFieldNoExist {
return err
}
} else {
keyTarget14, fieldTarget15, err := fieldsTarget1.StartField("Buckets")
if err != vdl.ErrFieldNoExist {
if err != nil {
return err
}
listTarget17, err := fieldTarget15.StartList(tt.NonOptional().Field(4).Type, len(m.Buckets))
if err != nil {
return err
}
for i, elem19 := range m.Buckets {
elemTarget18, err := listTarget17.StartElem(i)
if err != nil {
return err
}
if err := elem19.FillVDLTarget(elemTarget18, tt.NonOptional().Field(4).Type.Elem()); err != nil {
return err
}
if err := listTarget17.FinishElem(elemTarget18); err != nil {
return err
}
}
if err := fieldTarget15.FinishList(listTarget17); err != nil {
return err
}
if err := fieldsTarget1.FinishField(keyTarget14, fieldTarget15); err != nil {
return err
}
}
}
if err := t.FinishFields(fieldsTarget1); err != nil {
return err
}
return nil
}
func (m *HistogramValue) MakeVDLTarget() vdl.Target {
return &HistogramValueTarget{Value: m}
}
type HistogramValueTarget struct {
Value *HistogramValue
countTarget vdl.Int64Target
sumTarget vdl.Int64Target
minTarget vdl.Int64Target
maxTarget vdl.Int64Target
bucketsTarget __VDLTarget1_list
vdl.TargetBase
vdl.FieldsTargetBase
}
func (t *HistogramValueTarget) StartFields(tt *vdl.Type) (vdl.FieldsTarget, error) {
if ttWant := vdl.TypeOf((*HistogramValue)(nil)).Elem(); !vdl.Compatible(tt, ttWant) {
return nil, fmt.Errorf("type %v incompatible with %v", tt, ttWant)
}
return t, nil
}
func (t *HistogramValueTarget) StartField(name string) (key, field vdl.Target, _ error) {
switch name {
case "Count":
t.countTarget.Value = &t.Value.Count
target, err := &t.countTarget, error(nil)
return nil, target, err
case "Sum":
t.sumTarget.Value = &t.Value.Sum
target, err := &t.sumTarget, error(nil)
return nil, target, err
case "Min":
t.minTarget.Value = &t.Value.Min
target, err := &t.minTarget, error(nil)
return nil, target, err
case "Max":
t.maxTarget.Value = &t.Value.Max
target, err := &t.maxTarget, error(nil)
return nil, target, err
case "Buckets":
t.bucketsTarget.Value = &t.Value.Buckets
target, err := &t.bucketsTarget, error(nil)
return nil, target, err
default:
return nil, nil, fmt.Errorf("field %s not in struct v.io/x/ref/services/stats.HistogramValue", name)
}
}
func (t *HistogramValueTarget) FinishField(_, _ vdl.Target) error {
return nil
}
func (t *HistogramValueTarget) ZeroField(name string) error {
switch name {
case "Count":
t.Value.Count = int64(0)
return nil
case "Sum":
t.Value.Sum = int64(0)
return nil
case "Min":
t.Value.Min = int64(0)
return nil
case "Max":
t.Value.Max = int64(0)
return nil
case "Buckets":
t.Value.Buckets = []HistogramBucket(nil)
return nil
default:
return fmt.Errorf("field %s not in struct v.io/x/ref/services/stats.HistogramValue", name)
}
}
func (t *HistogramValueTarget) FinishFields(_ vdl.FieldsTarget) error {
return nil
}
// []HistogramBucket
type __VDLTarget1_list struct {
Value *[]HistogramBucket
elemTarget HistogramBucketTarget
vdl.TargetBase
vdl.ListTargetBase
}
func (t *__VDLTarget1_list) StartList(tt *vdl.Type, len int) (vdl.ListTarget, error) {
if ttWant := vdl.TypeOf((*[]HistogramBucket)(nil)); !vdl.Compatible(tt, ttWant) {
return nil, fmt.Errorf("type %v incompatible with %v", tt, ttWant)
}
if cap(*t.Value) < len {
*t.Value = make([]HistogramBucket, len)
} else {
*t.Value = (*t.Value)[:len]
}
return t, nil
}
func (t *__VDLTarget1_list) StartElem(index int) (elem vdl.Target, _ error) {
t.elemTarget.Value = &(*t.Value)[index]
target, err := &t.elemTarget, error(nil)
return target, err
}
func (t *__VDLTarget1_list) FinishElem(elem vdl.Target) error {
return nil
}
func (t *__VDLTarget1_list) FinishList(elem vdl.ListTarget) error {
return nil
}
func (x *HistogramValue) VDLRead(dec vdl.Decoder) error {
*x = HistogramValue{}
var err error
if err = dec.StartValue(); err != nil {
return err
}
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
}
for {
f, err := dec.NextField()
if err != nil {
return err
}
switch f {
case "":
return dec.FinishValue()
case "Count":
if err = dec.StartValue(); err != nil {
return err
}
if x.Count, err = dec.DecodeInt(64); err != nil {
return err
}
if err = dec.FinishValue(); err != nil {
return err
}
case "Sum":
if err = dec.StartValue(); err != nil {
return err
}
if x.Sum, err = dec.DecodeInt(64); err != nil {
return err
}
if err = dec.FinishValue(); err != nil {
return err
}
case "Min":
if err = dec.StartValue(); err != nil {
return err
}
if x.Min, err = dec.DecodeInt(64); err != nil {
return err
}
if err = dec.FinishValue(); err != nil {
return err
}
case "Max":
if err = dec.StartValue(); err != nil {
return err
}
if x.Max, err = dec.DecodeInt(64); err != nil {
return err
}
if err = dec.FinishValue(); err != nil {
return err
}
case "Buckets":
if err = __VDLRead1_list(dec, &x.Buckets); err != nil {
return err
}
default:
if err = dec.SkipValue(); err != nil {
return err
}
}
}
}
func __VDLRead1_list(dec vdl.Decoder, x *[]HistogramBucket) error {
var err error
if err = dec.StartValue(); err != nil {
return err
}
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible list %T, from %v", *x, dec.Type())
}
switch len := dec.LenHint(); {
case len > 0:
*x = make([]HistogramBucket, 0, len)
default:
*x = nil
}
for {
switch done, err := dec.NextEntry(); {
case err != nil:
return err
case done:
return dec.FinishValue()
}
var elem HistogramBucket
if err = elem.VDLRead(dec); err != nil {
return err
}
*x = append(*x, elem)
}
}
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((*HistogramBucket)(nil))
vdl.Register((*HistogramValue)(nil))
return struct{}{}
}