| // 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: sbmodel |
| |
| // Syncbase data model for Sensor Log. |
| // |
| // Every type <T> stored in Syncbase is defined as a pair of types, K<T> and |
| // V<T>, representing data stored in the key and value, respectively, in a |
| // single collection. K<T> types satisfy the PersistentDataKey interface, |
| // supporting conversion to and from the row key. |
| package sbmodel |
| |
| import ( |
| "fmt" |
| "time" |
| "v.io/v23/vdl" |
| vdltime "v.io/v23/vdlroot/time" |
| ) |
| |
| var _ = __VDLInit() // Must be first; see __VDLInit comments for details. |
| |
| ////////////////////////////////////////////////// |
| // Type definitions |
| |
| // devicecfg : <DevId> |
| // Measuring device handle. Master only. |
| type VDeviceCfg struct { |
| // Human-readable, not necessarily unique description of the device. |
| Desc string |
| // Syncbase instance publishing the syncgroup created by the device. |
| SgPublishSb string |
| } |
| |
| func (VDeviceCfg) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/sensorlog/internal/sbmodel.VDeviceCfg"` |
| }) { |
| } |
| |
| func (x VDeviceCfg) VDLIsZero() bool { |
| return x == VDeviceCfg{} |
| } |
| |
| func (x VDeviceCfg) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(__VDLType_struct_1); err != nil { |
| return err |
| } |
| if x.Desc != "" { |
| if err := enc.NextFieldValueString(0, vdl.StringType, x.Desc); err != nil { |
| return err |
| } |
| } |
| if x.SgPublishSb != "" { |
| if err := enc.NextFieldValueString(1, vdl.StringType, x.SgPublishSb); err != nil { |
| return err |
| } |
| } |
| if err := enc.NextField(-1); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| func (x *VDeviceCfg) VDLRead(dec vdl.Decoder) error { |
| *x = VDeviceCfg{} |
| if err := dec.StartValue(__VDLType_struct_1); err != nil { |
| return err |
| } |
| decType := dec.Type() |
| for { |
| index, err := dec.NextField() |
| switch { |
| case err != nil: |
| return err |
| case index == -1: |
| return dec.FinishValue() |
| } |
| if decType != __VDLType_struct_1 { |
| index = __VDLType_struct_1.FieldIndexByName(decType.Field(index).Name) |
| if index == -1 { |
| if err := dec.SkipValue(); err != nil { |
| return err |
| } |
| continue |
| } |
| } |
| switch index { |
| case 0: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.Desc = value |
| } |
| case 1: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.SgPublishSb = value |
| } |
| } |
| } |
| } |
| |
| type KDeviceCfg struct { |
| DevId string |
| } |
| |
| func (KDeviceCfg) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/sensorlog/internal/sbmodel.KDeviceCfg"` |
| }) { |
| } |
| |
| func (x KDeviceCfg) VDLIsZero() bool { |
| return x == KDeviceCfg{} |
| } |
| |
| func (x KDeviceCfg) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(__VDLType_struct_2); err != nil { |
| return err |
| } |
| if x.DevId != "" { |
| if err := enc.NextFieldValueString(0, vdl.StringType, x.DevId); err != nil { |
| return err |
| } |
| } |
| if err := enc.NextField(-1); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| func (x *KDeviceCfg) VDLRead(dec vdl.Decoder) error { |
| *x = KDeviceCfg{} |
| if err := dec.StartValue(__VDLType_struct_2); err != nil { |
| return err |
| } |
| decType := dec.Type() |
| for { |
| index, err := dec.NextField() |
| switch { |
| case err != nil: |
| return err |
| case index == -1: |
| return dec.FinishValue() |
| } |
| if decType != __VDLType_struct_2 { |
| index = __VDLType_struct_2.FieldIndexByName(decType.Field(index).Name) |
| if index == -1 { |
| if err := dec.SkipValue(); err != nil { |
| return err |
| } |
| continue |
| } |
| } |
| switch index { |
| case 0: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.DevId = value |
| } |
| } |
| } |
| } |
| |
| // Sampling script and polling frequency. |
| type SamplerDef struct { |
| // Shell script executed after every Interval, starting from Start. |
| // It should output a single data point, if available. A non-zero exit |
| // status or failure to parse the value will produce an error instead. |
| Script string |
| Start time.Time |
| Interval time.Duration |
| } |
| |
| func (SamplerDef) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/sensorlog/internal/sbmodel.SamplerDef"` |
| }) { |
| } |
| |
| func (x SamplerDef) VDLIsZero() bool { |
| if x.Script != "" { |
| return false |
| } |
| if !x.Start.IsZero() { |
| return false |
| } |
| if x.Interval != 0 { |
| return false |
| } |
| return true |
| } |
| |
| func (x SamplerDef) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(__VDLType_struct_3); err != nil { |
| return err |
| } |
| if x.Script != "" { |
| if err := enc.NextFieldValueString(0, vdl.StringType, x.Script); err != nil { |
| return err |
| } |
| } |
| if !x.Start.IsZero() { |
| if err := enc.NextField(1); err != nil { |
| return err |
| } |
| var wire vdltime.Time |
| if err := vdltime.TimeFromNative(&wire, x.Start); err != nil { |
| return err |
| } |
| if err := wire.VDLWrite(enc); err != nil { |
| return err |
| } |
| } |
| if x.Interval != 0 { |
| if err := enc.NextField(2); err != nil { |
| return err |
| } |
| var wire vdltime.Duration |
| if err := vdltime.DurationFromNative(&wire, x.Interval); err != nil { |
| return err |
| } |
| if err := wire.VDLWrite(enc); err != nil { |
| return err |
| } |
| } |
| if err := enc.NextField(-1); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| func (x *SamplerDef) VDLRead(dec vdl.Decoder) error { |
| *x = SamplerDef{} |
| if err := dec.StartValue(__VDLType_struct_3); err != nil { |
| return err |
| } |
| decType := dec.Type() |
| for { |
| index, err := dec.NextField() |
| switch { |
| case err != nil: |
| return err |
| case index == -1: |
| return dec.FinishValue() |
| } |
| if decType != __VDLType_struct_3 { |
| index = __VDLType_struct_3.FieldIndexByName(decType.Field(index).Name) |
| if index == -1 { |
| if err := dec.SkipValue(); err != nil { |
| return err |
| } |
| continue |
| } |
| } |
| switch index { |
| case 0: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.Script = value |
| } |
| case 1: |
| var wire vdltime.Time |
| if err := wire.VDLRead(dec); err != nil { |
| return err |
| } |
| if err := vdltime.TimeToNative(wire, &x.Start); err != nil { |
| return err |
| } |
| case 2: |
| var wire vdltime.Duration |
| if err := wire.VDLRead(dec); err != nil { |
| return err |
| } |
| if err := vdltime.DurationToNative(wire, &x.Interval); err != nil { |
| return err |
| } |
| } |
| } |
| } |
| |
| // streamdef : <DevId>/<StreamId> |
| // Configures a stream of data to be measured. |
| type VStreamDef struct { |
| // Human-readable, not necessarily unique description of the stream. |
| Desc string |
| // Sampling configuration. |
| Sampler SamplerDef |
| // Flag to start and stop sampling. |
| Enabled bool |
| } |
| |
| func (VStreamDef) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/sensorlog/internal/sbmodel.VStreamDef"` |
| }) { |
| } |
| |
| func (x VStreamDef) VDLIsZero() bool { |
| if x.Desc != "" { |
| return false |
| } |
| if !x.Sampler.VDLIsZero() { |
| return false |
| } |
| if x.Enabled { |
| return false |
| } |
| return true |
| } |
| |
| func (x VStreamDef) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(__VDLType_struct_6); err != nil { |
| return err |
| } |
| if x.Desc != "" { |
| if err := enc.NextFieldValueString(0, vdl.StringType, x.Desc); err != nil { |
| return err |
| } |
| } |
| if !x.Sampler.VDLIsZero() { |
| if err := enc.NextField(1); err != nil { |
| return err |
| } |
| if err := x.Sampler.VDLWrite(enc); err != nil { |
| return err |
| } |
| } |
| if x.Enabled { |
| if err := enc.NextFieldValueBool(2, vdl.BoolType, x.Enabled); err != nil { |
| return err |
| } |
| } |
| if err := enc.NextField(-1); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| func (x *VStreamDef) VDLRead(dec vdl.Decoder) error { |
| *x = VStreamDef{} |
| if err := dec.StartValue(__VDLType_struct_6); err != nil { |
| return err |
| } |
| decType := dec.Type() |
| for { |
| index, err := dec.NextField() |
| switch { |
| case err != nil: |
| return err |
| case index == -1: |
| return dec.FinishValue() |
| } |
| if decType != __VDLType_struct_6 { |
| index = __VDLType_struct_6.FieldIndexByName(decType.Field(index).Name) |
| if index == -1 { |
| if err := dec.SkipValue(); err != nil { |
| return err |
| } |
| continue |
| } |
| } |
| switch index { |
| case 0: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.Desc = value |
| } |
| case 1: |
| if err := x.Sampler.VDLRead(dec); err != nil { |
| return err |
| } |
| case 2: |
| switch value, err := dec.ReadValueBool(); { |
| case err != nil: |
| return err |
| default: |
| x.Enabled = value |
| } |
| } |
| } |
| } |
| |
| type KStreamDef struct { |
| DevId string |
| StreamId string |
| } |
| |
| func (KStreamDef) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/sensorlog/internal/sbmodel.KStreamDef"` |
| }) { |
| } |
| |
| func (x KStreamDef) VDLIsZero() bool { |
| return x == KStreamDef{} |
| } |
| |
| func (x KStreamDef) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(__VDLType_struct_7); err != nil { |
| return err |
| } |
| if x.DevId != "" { |
| if err := enc.NextFieldValueString(0, vdl.StringType, x.DevId); err != nil { |
| return err |
| } |
| } |
| if x.StreamId != "" { |
| if err := enc.NextFieldValueString(1, vdl.StringType, x.StreamId); err != nil { |
| return err |
| } |
| } |
| if err := enc.NextField(-1); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| func (x *KStreamDef) VDLRead(dec vdl.Decoder) error { |
| *x = KStreamDef{} |
| if err := dec.StartValue(__VDLType_struct_7); err != nil { |
| return err |
| } |
| decType := dec.Type() |
| for { |
| index, err := dec.NextField() |
| switch { |
| case err != nil: |
| return err |
| case index == -1: |
| return dec.FinishValue() |
| } |
| if decType != __VDLType_struct_7 { |
| index = __VDLType_struct_7.FieldIndexByName(decType.Field(index).Name) |
| if index == -1 { |
| if err := dec.SkipValue(); err != nil { |
| return err |
| } |
| continue |
| } |
| } |
| switch index { |
| case 0: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.DevId = value |
| } |
| case 1: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.StreamId = value |
| } |
| } |
| } |
| } |
| |
| // sdata : <DevId>/<StreamId>/<Timestamp> |
| // Measured data value or error. |
| type KDataPoint struct { |
| DevId string |
| StreamId string |
| Timestamp time.Time |
| } |
| |
| func (KDataPoint) __VDLReflect(struct { |
| Name string `vdl:"v.io/x/sensorlog/internal/sbmodel.KDataPoint"` |
| }) { |
| } |
| |
| func (x KDataPoint) VDLIsZero() bool { |
| if x.DevId != "" { |
| return false |
| } |
| if x.StreamId != "" { |
| return false |
| } |
| if !x.Timestamp.IsZero() { |
| return false |
| } |
| return true |
| } |
| |
| func (x KDataPoint) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(__VDLType_struct_8); err != nil { |
| return err |
| } |
| if x.DevId != "" { |
| if err := enc.NextFieldValueString(0, vdl.StringType, x.DevId); err != nil { |
| return err |
| } |
| } |
| if x.StreamId != "" { |
| if err := enc.NextFieldValueString(1, vdl.StringType, x.StreamId); err != nil { |
| return err |
| } |
| } |
| if !x.Timestamp.IsZero() { |
| if err := enc.NextField(2); err != nil { |
| return err |
| } |
| var wire vdltime.Time |
| if err := vdltime.TimeFromNative(&wire, x.Timestamp); err != nil { |
| return err |
| } |
| if err := wire.VDLWrite(enc); err != nil { |
| return err |
| } |
| } |
| if err := enc.NextField(-1); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| func (x *KDataPoint) VDLRead(dec vdl.Decoder) error { |
| *x = KDataPoint{} |
| if err := dec.StartValue(__VDLType_struct_8); err != nil { |
| return err |
| } |
| decType := dec.Type() |
| for { |
| index, err := dec.NextField() |
| switch { |
| case err != nil: |
| return err |
| case index == -1: |
| return dec.FinishValue() |
| } |
| if decType != __VDLType_struct_8 { |
| index = __VDLType_struct_8.FieldIndexByName(decType.Field(index).Name) |
| if index == -1 { |
| if err := dec.SkipValue(); err != nil { |
| return err |
| } |
| continue |
| } |
| } |
| switch index { |
| case 0: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.DevId = value |
| } |
| case 1: |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| x.StreamId = value |
| } |
| case 2: |
| var wire vdltime.Time |
| if err := wire.VDLRead(dec); err != nil { |
| return err |
| } |
| if err := vdltime.TimeToNative(wire, &x.Timestamp); err != nil { |
| return err |
| } |
| } |
| } |
| } |
| |
| type ( |
| // VDataPoint represents any single field of the VDataPoint union type. |
| VDataPoint 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 VDataPoint union type. |
| __VDLReflect(__VDataPointReflect) |
| VDLIsZero() bool |
| VDLWrite(vdl.Encoder) error |
| } |
| // VDataPointValue represents field Value of the VDataPoint union type. |
| VDataPointValue struct{ Value float64 } |
| // VDataPointError represents field Error of the VDataPoint union type. |
| VDataPointError struct{ Value string } |
| // __VDataPointReflect describes the VDataPoint union type. |
| __VDataPointReflect struct { |
| Name string `vdl:"v.io/x/sensorlog/internal/sbmodel.VDataPoint"` |
| Type VDataPoint |
| Union struct { |
| Value VDataPointValue |
| Error VDataPointError |
| } |
| } |
| ) |
| |
| func (x VDataPointValue) Index() int { return 0 } |
| func (x VDataPointValue) Interface() interface{} { return x.Value } |
| func (x VDataPointValue) Name() string { return "Value" } |
| func (x VDataPointValue) __VDLReflect(__VDataPointReflect) {} |
| |
| func (x VDataPointError) Index() int { return 1 } |
| func (x VDataPointError) Interface() interface{} { return x.Value } |
| func (x VDataPointError) Name() string { return "Error" } |
| func (x VDataPointError) __VDLReflect(__VDataPointReflect) {} |
| |
| func (x VDataPointValue) VDLIsZero() bool { |
| return x.Value == 0 |
| } |
| |
| func (x VDataPointError) VDLIsZero() bool { |
| return false |
| } |
| |
| func (x VDataPointValue) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(__VDLType_union_9); err != nil { |
| return err |
| } |
| if err := enc.NextFieldValueFloat(0, vdl.Float64Type, x.Value); err != nil { |
| return err |
| } |
| if err := enc.NextField(-1); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| func (x VDataPointError) VDLWrite(enc vdl.Encoder) error { |
| if err := enc.StartValue(__VDLType_union_9); err != nil { |
| return err |
| } |
| if err := enc.NextFieldValueString(1, vdl.StringType, x.Value); err != nil { |
| return err |
| } |
| if err := enc.NextField(-1); err != nil { |
| return err |
| } |
| return enc.FinishValue() |
| } |
| |
| func VDLReadVDataPoint(dec vdl.Decoder, x *VDataPoint) error { |
| if err := dec.StartValue(__VDLType_union_9); err != nil { |
| return err |
| } |
| decType := dec.Type() |
| index, err := dec.NextField() |
| switch { |
| case err != nil: |
| return err |
| case index == -1: |
| return fmt.Errorf("missing field in union %T, from %v", x, decType) |
| } |
| if decType != __VDLType_union_9 { |
| name := decType.Field(index).Name |
| index = __VDLType_union_9.FieldIndexByName(name) |
| if index == -1 { |
| return fmt.Errorf("field %q not in union %T, from %v", name, x, decType) |
| } |
| } |
| switch index { |
| case 0: |
| var field VDataPointValue |
| switch value, err := dec.ReadValueFloat(64); { |
| case err != nil: |
| return err |
| default: |
| field.Value = value |
| } |
| *x = field |
| case 1: |
| var field VDataPointError |
| switch value, err := dec.ReadValueString(); { |
| case err != nil: |
| return err |
| default: |
| field.Value = value |
| } |
| *x = field |
| } |
| switch index, err := dec.NextField(); { |
| case err != nil: |
| return err |
| case index != -1: |
| return fmt.Errorf("extra field %d in union %T, from %v", index, x, dec.Type()) |
| } |
| return dec.FinishValue() |
| } |
| |
| // Hold type definitions in package-level variables, for better performance. |
| var ( |
| __VDLType_struct_1 *vdl.Type |
| __VDLType_struct_2 *vdl.Type |
| __VDLType_struct_3 *vdl.Type |
| __VDLType_struct_4 *vdl.Type |
| __VDLType_struct_5 *vdl.Type |
| __VDLType_struct_6 *vdl.Type |
| __VDLType_struct_7 *vdl.Type |
| __VDLType_struct_8 *vdl.Type |
| __VDLType_union_9 *vdl.Type |
| ) |
| |
| 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((*VDeviceCfg)(nil)) |
| vdl.Register((*KDeviceCfg)(nil)) |
| vdl.Register((*SamplerDef)(nil)) |
| vdl.Register((*VStreamDef)(nil)) |
| vdl.Register((*KStreamDef)(nil)) |
| vdl.Register((*KDataPoint)(nil)) |
| vdl.Register((*VDataPoint)(nil)) |
| |
| // Initialize type definitions. |
| __VDLType_struct_1 = vdl.TypeOf((*VDeviceCfg)(nil)).Elem() |
| __VDLType_struct_2 = vdl.TypeOf((*KDeviceCfg)(nil)).Elem() |
| __VDLType_struct_3 = vdl.TypeOf((*SamplerDef)(nil)).Elem() |
| __VDLType_struct_4 = vdl.TypeOf((*vdltime.Time)(nil)).Elem() |
| __VDLType_struct_5 = vdl.TypeOf((*vdltime.Duration)(nil)).Elem() |
| __VDLType_struct_6 = vdl.TypeOf((*VStreamDef)(nil)).Elem() |
| __VDLType_struct_7 = vdl.TypeOf((*KStreamDef)(nil)).Elem() |
| __VDLType_struct_8 = vdl.TypeOf((*KDataPoint)(nil)).Elem() |
| __VDLType_union_9 = vdl.TypeOf((*VDataPoint)(nil)) |
| |
| return struct{}{} |
| } |