|
| 1 | +/* |
| 2 | +Package ocstructs is a generated package which contains definitions |
| 3 | +of structs which represent a YANG schema. The generated schema can be |
| 4 | +compressed by a series of transformations (compression was true |
| 5 | +in this case). |
| 6 | + |
| 7 | +This package was generated by codegen-tests |
| 8 | +using the following YANG input files: |
| 9 | + - ../testdata/modules/openconfig-multikey-list-name-conflict.yang |
| 10 | +Imported modules were sourced from: |
| 11 | +*/ |
| 12 | +package ocstructs |
| 13 | + |
| 14 | +import ( |
| 15 | + "encoding/json" |
| 16 | + "fmt" |
| 17 | + "reflect" |
| 18 | + |
| 19 | + "github.com/openconfig/ygot/ygot" |
| 20 | +) |
| 21 | + |
| 22 | +// Binary is a type that is used for fields that have a YANG type of |
| 23 | +// binary. It is used such that binary fields can be distinguished from |
| 24 | +// leaf-lists of uint8s (which are mapped to []uint8, equivalent to |
| 25 | +// []byte in reflection). |
| 26 | +type Binary []byte |
| 27 | + |
| 28 | +// YANGEmpty is a type that is used for fields that have a YANG type of |
| 29 | +// empty. It is used such that empty fields can be distinguished from boolean fields |
| 30 | +// in the generated code. |
| 31 | +type YANGEmpty bool |
| 32 | + |
| 33 | +// UnionInt8 is an int8 type assignable to unions of which it is a subtype. |
| 34 | +type UnionInt8 int8 |
| 35 | + |
| 36 | +// UnionInt16 is an int16 type assignable to unions of which it is a subtype. |
| 37 | +type UnionInt16 int16 |
| 38 | + |
| 39 | +// UnionInt32 is an int32 type assignable to unions of which it is a subtype. |
| 40 | +type UnionInt32 int32 |
| 41 | + |
| 42 | +// UnionInt64 is an int64 type assignable to unions of which it is a subtype. |
| 43 | +type UnionInt64 int64 |
| 44 | + |
| 45 | +// UnionUint8 is a uint8 type assignable to unions of which it is a subtype. |
| 46 | +type UnionUint8 uint8 |
| 47 | + |
| 48 | +// UnionUint16 is a uint16 type assignable to unions of which it is a subtype. |
| 49 | +type UnionUint16 uint16 |
| 50 | + |
| 51 | +// UnionUint32 is a uint32 type assignable to unions of which it is a subtype. |
| 52 | +type UnionUint32 uint32 |
| 53 | + |
| 54 | +// UnionUint64 is a uint64 type assignable to unions of which it is a subtype. |
| 55 | +type UnionUint64 uint64 |
| 56 | + |
| 57 | +// UnionFloat64 is a float64 type assignable to unions of which it is a subtype. |
| 58 | +type UnionFloat64 float64 |
| 59 | + |
| 60 | +// UnionString is a string type assignable to unions of which it is a subtype. |
| 61 | +type UnionString string |
| 62 | + |
| 63 | +// UnionBool is a bool type assignable to unions of which it is a subtype. |
| 64 | +type UnionBool bool |
| 65 | + |
| 66 | +// UnionUnsupported is an interface{} wrapper type for unsupported types. It is |
| 67 | +// assignable to unions of which it is a subtype. |
| 68 | +type UnionUnsupported struct { |
| 69 | + Value interface{} |
| 70 | +} |
| 71 | + |
| 72 | +// Model represents the /openconfig-multikey-list-name-conflict/model YANG schema element. |
| 73 | +type Model struct { |
| 74 | + MultiKey map[Model_MultiKey_YANGListKey]*Model_MultiKey `path:"a/multi-key" module:"openconfig-multikey-list-name-conflict"` |
| 75 | +} |
| 76 | + |
| 77 | +// IsYANGGoStruct ensures that Model implements the yang.GoStruct |
| 78 | +// interface. This allows functions that need to handle this struct to |
| 79 | +// identify it as being generated by ygen. |
| 80 | +func (*Model) IsYANGGoStruct() {} |
| 81 | + |
| 82 | +// Model_MultiKey_YANGListKey represents the key for list MultiKey of element /openconfig-multikey-list-name-conflict/model. |
| 83 | +type Model_MultiKey_YANGListKey struct { |
| 84 | + Key1 uint32 `path:"key1"` |
| 85 | + Key2 uint64 `path:"key2"` |
| 86 | +} |
| 87 | + |
| 88 | +// NewMultiKey creates a new entry in the MultiKey list of the |
| 89 | +// Model struct. The keys of the list are populated from the input |
| 90 | +// arguments. |
| 91 | +func (t *Model) NewMultiKey(Key1 uint32, Key2 uint64) (*Model_MultiKey, error){ |
| 92 | + |
| 93 | + // Initialise the list within the receiver struct if it has not already been |
| 94 | + // created. |
| 95 | + if t.MultiKey == nil { |
| 96 | + t.MultiKey = make(map[Model_MultiKey_YANGListKey]*Model_MultiKey) |
| 97 | + } |
| 98 | + |
| 99 | + key := Model_MultiKey_YANGListKey{ |
| 100 | + Key1: Key1, |
| 101 | + Key2: Key2, |
| 102 | + } |
| 103 | + |
| 104 | + // Ensure that this key has not already been used in the |
| 105 | + // list. Keyed YANG lists do not allow duplicate keys to |
| 106 | + // be created. |
| 107 | + if _, ok := t.MultiKey[key]; ok { |
| 108 | + return nil, fmt.Errorf("duplicate key %v for list MultiKey", key) |
| 109 | + } |
| 110 | + |
| 111 | + t.MultiKey[key] = &Model_MultiKey{ |
| 112 | + Key1: &Key1, |
| 113 | + Key2: &Key2, |
| 114 | + } |
| 115 | + |
| 116 | + return t.MultiKey[key], nil |
| 117 | +} |
| 118 | + |
| 119 | +// RenameMultiKey renames an entry in the list MultiKey within |
| 120 | +// the Model struct. The entry with key oldK is renamed to newK updating |
| 121 | +// the key within the value. |
| 122 | +func (t *Model) RenameMultiKey(oldK, newK Model_MultiKey_YANGListKey) error { |
| 123 | + if _, ok := t.MultiKey[newK]; ok { |
| 124 | + return fmt.Errorf("key %v already exists in MultiKey", newK) |
| 125 | + } |
| 126 | + |
| 127 | + e, ok := t.MultiKey[oldK] |
| 128 | + if !ok { |
| 129 | + return fmt.Errorf("key %v not found in MultiKey", oldK) |
| 130 | + } |
| 131 | + e.Key1 = &newK.Key1 |
| 132 | + e.Key2 = &newK.Key2 |
| 133 | + |
| 134 | + t.MultiKey[newK] = e |
| 135 | + delete(t.MultiKey, oldK) |
| 136 | + return nil |
| 137 | +} |
| 138 | + |
| 139 | +// Model_MultiKey represents the /openconfig-multikey-list-name-conflict/model/a/multi-key YANG schema element. |
| 140 | +type Model_MultiKey struct { |
| 141 | + Key *Model_MultiKey_Key `path:"state/key" module:"openconfig-multikey-list-name-conflict"` |
| 142 | + Key1 *uint32 `path:"config/key1|key1" module:"openconfig-multikey-list-name-conflict"` |
| 143 | + Key2 *uint64 `path:"config/key2|key2" module:"openconfig-multikey-list-name-conflict"` |
| 144 | +} |
| 145 | + |
| 146 | +// IsYANGGoStruct ensures that Model_MultiKey implements the yang.GoStruct |
| 147 | +// interface. This allows functions that need to handle this struct to |
| 148 | +// identify it as being generated by ygen. |
| 149 | +func (*Model_MultiKey) IsYANGGoStruct() {} |
| 150 | + |
| 151 | +// ΛListKeyMap returns the keys of the Model_MultiKey struct, which is a YANG list entry. |
| 152 | +func (t *Model_MultiKey) ΛListKeyMap() (map[string]interface{}, error) { |
| 153 | + if t.Key1 == nil { |
| 154 | + return nil, fmt.Errorf("nil value for key Key1") |
| 155 | + } |
| 156 | + |
| 157 | + if t.Key2 == nil { |
| 158 | + return nil, fmt.Errorf("nil value for key Key2") |
| 159 | + } |
| 160 | + |
| 161 | + return map[string]interface{}{ |
| 162 | + "key1": *t.Key1, |
| 163 | + "key2": *t.Key2, |
| 164 | + }, nil |
| 165 | +} |
| 166 | + |
| 167 | +// Model_MultiKey_Key represents the /openconfig-multikey-list-name-conflict/model/a/multi-key/state/key YANG schema element. |
| 168 | +type Model_MultiKey_Key struct { |
| 169 | + Key3 *uint8 `path:"key3" module:"openconfig-multikey-list-name-conflict"` |
| 170 | +} |
| 171 | + |
| 172 | +// IsYANGGoStruct ensures that Model_MultiKey_Key implements the yang.GoStruct |
| 173 | +// interface. This allows functions that need to handle this struct to |
| 174 | +// identify it as being generated by ygen. |
| 175 | +func (*Model_MultiKey_Key) IsYANGGoStruct() {} |
0 commit comments