Jonathan Hart | 44bdbfc | 2020-04-14 17:45:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 3 | * Copyright (c) 2011, 2012 Open Networking Foundation |
| 4 | * Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler. |
| 5 | * Copyright 2018, Red Hat, Inc. |
| 6 | */ |
| 7 | // Automatically generated by LOXI from template module.go |
| 8 | // Do not modify |
| 9 | |
| 10 | package of15 |
| 11 | |
| 12 | import ( |
| 13 | "encoding/json" |
| 14 | "fmt" |
| 15 | "net" |
| 16 | |
| 17 | "github.com/opencord/goloxi" |
| 18 | ) |
| 19 | |
| 20 | type Oxs struct { |
| 21 | TypeLen uint32 |
| 22 | } |
| 23 | |
| 24 | type IOxs interface { |
| 25 | goloxi.Serializable |
| 26 | GetTypeLen() uint32 |
| 27 | GetOXSName() string |
| 28 | GetOXSValue() interface{} |
| 29 | } |
| 30 | |
| 31 | func (self *Oxs) GetTypeLen() uint32 { |
| 32 | return self.TypeLen |
| 33 | } |
| 34 | |
| 35 | func (self *Oxs) SetTypeLen(v uint32) { |
| 36 | self.TypeLen = v |
| 37 | } |
| 38 | |
| 39 | func (self *Oxs) Serialize(encoder *goloxi.Encoder) error { |
| 40 | |
| 41 | encoder.PutUint32(uint32(self.TypeLen)) |
| 42 | |
| 43 | return nil |
| 44 | } |
| 45 | |
| 46 | func DecodeOxs(decoder *goloxi.Decoder) (IOxs, error) { |
| 47 | _oxs := &Oxs{} |
| 48 | if decoder.Length() < 4 { |
| 49 | return nil, fmt.Errorf("Oxs packet too short: %d < 4", decoder.Length()) |
| 50 | } |
| 51 | _oxs.TypeLen = uint32(decoder.ReadUint32()) |
| 52 | |
| 53 | switch _oxs.TypeLen { |
| 54 | case 2147616776: |
| 55 | return DecodeOxsByteCount(_oxs, decoder) |
| 56 | case 2147614728: |
| 57 | return DecodeOxsDuration(_oxs, decoder) |
| 58 | case 2147615748: |
| 59 | return DecodeOxsFlowCount(_oxs, decoder) |
| 60 | case 2147616264: |
| 61 | return DecodeOxsPacketCount(_oxs, decoder) |
| 62 | case 2147615240: |
| 63 | return DecodeOxsIdleTime(_oxs, decoder) |
| 64 | default: |
| 65 | return nil, fmt.Errorf("Invalid type '%d' for 'Oxs'", _oxs.TypeLen) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func NewOxs(_type_len uint32) *Oxs { |
| 70 | obj := &Oxs{} |
| 71 | obj.TypeLen = _type_len |
| 72 | return obj |
| 73 | } |
| 74 | |
| 75 | type OxsByteCount struct { |
| 76 | *Oxs |
| 77 | Value uint64 |
| 78 | } |
| 79 | |
| 80 | type IOxsByteCount interface { |
| 81 | IOxs |
| 82 | GetValue() uint64 |
| 83 | } |
| 84 | |
| 85 | func (self *OxsByteCount) GetValue() uint64 { |
| 86 | return self.Value |
| 87 | } |
| 88 | |
| 89 | func (self *OxsByteCount) SetValue(v uint64) { |
| 90 | self.Value = v |
| 91 | } |
| 92 | |
| 93 | func (self *OxsByteCount) Serialize(encoder *goloxi.Encoder) error { |
| 94 | if err := self.Oxs.Serialize(encoder); err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | encoder.PutUint64(uint64(self.Value)) |
| 99 | |
| 100 | return nil |
| 101 | } |
| 102 | |
| 103 | func DecodeOxsByteCount(parent *Oxs, decoder *goloxi.Decoder) (*OxsByteCount, error) { |
| 104 | _oxsbytecount := &OxsByteCount{Oxs: parent} |
| 105 | if decoder.Length() < 8 { |
| 106 | return nil, fmt.Errorf("OxsByteCount packet too short: %d < 8", decoder.Length()) |
| 107 | } |
| 108 | _oxsbytecount.Value = uint64(decoder.ReadUint64()) |
| 109 | return _oxsbytecount, nil |
| 110 | } |
| 111 | |
| 112 | func NewOxsByteCount() *OxsByteCount { |
| 113 | obj := &OxsByteCount{ |
| 114 | Oxs: NewOxs(2147616776), |
| 115 | } |
| 116 | return obj |
| 117 | } |
| 118 | func (self *OxsByteCount) GetOXSName() string { |
| 119 | return "byte_count" |
| 120 | } |
| 121 | |
| 122 | func (self *OxsByteCount) GetOXSValue() interface{} { |
| 123 | return self.Value |
| 124 | } |
| 125 | |
| 126 | func (self *OxsByteCount) MarshalJSON() ([]byte, error) { |
| 127 | var value interface{} = self.GetOXSValue() |
| 128 | switch t := value.(type) { |
| 129 | case net.HardwareAddr: |
| 130 | value = t.String() |
| 131 | case net.IP: |
| 132 | value = t.String() |
| 133 | default: |
| 134 | if s, ok := t.(fmt.Stringer); ok { |
| 135 | value = s.String() |
| 136 | } else { |
| 137 | value = t |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | jsonValue, err := json.Marshal(value) |
| 142 | if err != nil { |
| 143 | return nil, err |
| 144 | } |
| 145 | return []byte(fmt.Sprintf("{\"Type\":\"%s\",\"Value\":%s}", self.GetOXSName(), string(jsonValue))), nil |
| 146 | } |
| 147 | |
| 148 | type OxsDuration struct { |
| 149 | *Oxs |
| 150 | Value uint64 |
| 151 | } |
| 152 | |
| 153 | type IOxsDuration interface { |
| 154 | IOxs |
| 155 | GetValue() uint64 |
| 156 | } |
| 157 | |
| 158 | func (self *OxsDuration) GetValue() uint64 { |
| 159 | return self.Value |
| 160 | } |
| 161 | |
| 162 | func (self *OxsDuration) SetValue(v uint64) { |
| 163 | self.Value = v |
| 164 | } |
| 165 | |
| 166 | func (self *OxsDuration) Serialize(encoder *goloxi.Encoder) error { |
| 167 | if err := self.Oxs.Serialize(encoder); err != nil { |
| 168 | return err |
| 169 | } |
| 170 | |
| 171 | encoder.PutUint64(uint64(self.Value)) |
| 172 | |
| 173 | return nil |
| 174 | } |
| 175 | |
| 176 | func DecodeOxsDuration(parent *Oxs, decoder *goloxi.Decoder) (*OxsDuration, error) { |
| 177 | _oxsduration := &OxsDuration{Oxs: parent} |
| 178 | if decoder.Length() < 8 { |
| 179 | return nil, fmt.Errorf("OxsDuration packet too short: %d < 8", decoder.Length()) |
| 180 | } |
| 181 | _oxsduration.Value = uint64(decoder.ReadUint64()) |
| 182 | return _oxsduration, nil |
| 183 | } |
| 184 | |
| 185 | func NewOxsDuration() *OxsDuration { |
| 186 | obj := &OxsDuration{ |
| 187 | Oxs: NewOxs(2147614728), |
| 188 | } |
| 189 | return obj |
| 190 | } |
| 191 | func (self *OxsDuration) GetOXSName() string { |
| 192 | return "duration" |
| 193 | } |
| 194 | |
| 195 | func (self *OxsDuration) GetOXSValue() interface{} { |
| 196 | return self.Value |
| 197 | } |
| 198 | |
| 199 | func (self *OxsDuration) MarshalJSON() ([]byte, error) { |
| 200 | var value interface{} = self.GetOXSValue() |
| 201 | switch t := value.(type) { |
| 202 | case net.HardwareAddr: |
| 203 | value = t.String() |
| 204 | case net.IP: |
| 205 | value = t.String() |
| 206 | default: |
| 207 | if s, ok := t.(fmt.Stringer); ok { |
| 208 | value = s.String() |
| 209 | } else { |
| 210 | value = t |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | jsonValue, err := json.Marshal(value) |
| 215 | if err != nil { |
| 216 | return nil, err |
| 217 | } |
| 218 | return []byte(fmt.Sprintf("{\"Type\":\"%s\",\"Value\":%s}", self.GetOXSName(), string(jsonValue))), nil |
| 219 | } |
| 220 | |
| 221 | type OxsFlowCount struct { |
| 222 | *Oxs |
| 223 | Value uint32 |
| 224 | } |
| 225 | |
| 226 | type IOxsFlowCount interface { |
| 227 | IOxs |
| 228 | GetValue() uint32 |
| 229 | } |
| 230 | |
| 231 | func (self *OxsFlowCount) GetValue() uint32 { |
| 232 | return self.Value |
| 233 | } |
| 234 | |
| 235 | func (self *OxsFlowCount) SetValue(v uint32) { |
| 236 | self.Value = v |
| 237 | } |
| 238 | |
| 239 | func (self *OxsFlowCount) Serialize(encoder *goloxi.Encoder) error { |
| 240 | if err := self.Oxs.Serialize(encoder); err != nil { |
| 241 | return err |
| 242 | } |
| 243 | |
| 244 | encoder.PutUint32(uint32(self.Value)) |
| 245 | |
| 246 | return nil |
| 247 | } |
| 248 | |
| 249 | func DecodeOxsFlowCount(parent *Oxs, decoder *goloxi.Decoder) (*OxsFlowCount, error) { |
| 250 | _oxsflowcount := &OxsFlowCount{Oxs: parent} |
| 251 | if decoder.Length() < 4 { |
| 252 | return nil, fmt.Errorf("OxsFlowCount packet too short: %d < 4", decoder.Length()) |
| 253 | } |
| 254 | _oxsflowcount.Value = uint32(decoder.ReadUint32()) |
| 255 | return _oxsflowcount, nil |
| 256 | } |
| 257 | |
| 258 | func NewOxsFlowCount() *OxsFlowCount { |
| 259 | obj := &OxsFlowCount{ |
| 260 | Oxs: NewOxs(2147615748), |
| 261 | } |
| 262 | return obj |
| 263 | } |
| 264 | func (self *OxsFlowCount) GetOXSName() string { |
| 265 | return "flow_count" |
| 266 | } |
| 267 | |
| 268 | func (self *OxsFlowCount) GetOXSValue() interface{} { |
| 269 | return self.Value |
| 270 | } |
| 271 | |
| 272 | func (self *OxsFlowCount) MarshalJSON() ([]byte, error) { |
| 273 | var value interface{} = self.GetOXSValue() |
| 274 | switch t := value.(type) { |
| 275 | case net.HardwareAddr: |
| 276 | value = t.String() |
| 277 | case net.IP: |
| 278 | value = t.String() |
| 279 | default: |
| 280 | if s, ok := t.(fmt.Stringer); ok { |
| 281 | value = s.String() |
| 282 | } else { |
| 283 | value = t |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | jsonValue, err := json.Marshal(value) |
| 288 | if err != nil { |
| 289 | return nil, err |
| 290 | } |
| 291 | return []byte(fmt.Sprintf("{\"Type\":\"%s\",\"Value\":%s}", self.GetOXSName(), string(jsonValue))), nil |
| 292 | } |
| 293 | |
| 294 | type OxsIdleTime struct { |
| 295 | *Oxs |
| 296 | Value uint64 |
| 297 | } |
| 298 | |
| 299 | type IOxsIdleTime interface { |
| 300 | IOxs |
| 301 | GetValue() uint64 |
| 302 | } |
| 303 | |
| 304 | func (self *OxsIdleTime) GetValue() uint64 { |
| 305 | return self.Value |
| 306 | } |
| 307 | |
| 308 | func (self *OxsIdleTime) SetValue(v uint64) { |
| 309 | self.Value = v |
| 310 | } |
| 311 | |
| 312 | func (self *OxsIdleTime) Serialize(encoder *goloxi.Encoder) error { |
| 313 | if err := self.Oxs.Serialize(encoder); err != nil { |
| 314 | return err |
| 315 | } |
| 316 | |
| 317 | encoder.PutUint64(uint64(self.Value)) |
| 318 | |
| 319 | return nil |
| 320 | } |
| 321 | |
| 322 | func DecodeOxsIdleTime(parent *Oxs, decoder *goloxi.Decoder) (*OxsIdleTime, error) { |
| 323 | _oxsidletime := &OxsIdleTime{Oxs: parent} |
| 324 | if decoder.Length() < 8 { |
| 325 | return nil, fmt.Errorf("OxsIdleTime packet too short: %d < 8", decoder.Length()) |
| 326 | } |
| 327 | _oxsidletime.Value = uint64(decoder.ReadUint64()) |
| 328 | return _oxsidletime, nil |
| 329 | } |
| 330 | |
| 331 | func NewOxsIdleTime() *OxsIdleTime { |
| 332 | obj := &OxsIdleTime{ |
| 333 | Oxs: NewOxs(2147615240), |
| 334 | } |
| 335 | return obj |
| 336 | } |
| 337 | func (self *OxsIdleTime) GetOXSName() string { |
| 338 | return "idle_time" |
| 339 | } |
| 340 | |
| 341 | func (self *OxsIdleTime) GetOXSValue() interface{} { |
| 342 | return self.Value |
| 343 | } |
| 344 | |
| 345 | func (self *OxsIdleTime) MarshalJSON() ([]byte, error) { |
| 346 | var value interface{} = self.GetOXSValue() |
| 347 | switch t := value.(type) { |
| 348 | case net.HardwareAddr: |
| 349 | value = t.String() |
| 350 | case net.IP: |
| 351 | value = t.String() |
| 352 | default: |
| 353 | if s, ok := t.(fmt.Stringer); ok { |
| 354 | value = s.String() |
| 355 | } else { |
| 356 | value = t |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | jsonValue, err := json.Marshal(value) |
| 361 | if err != nil { |
| 362 | return nil, err |
| 363 | } |
| 364 | return []byte(fmt.Sprintf("{\"Type\":\"%s\",\"Value\":%s}", self.GetOXSName(), string(jsonValue))), nil |
| 365 | } |
| 366 | |
| 367 | type OxsPacketCount struct { |
| 368 | *Oxs |
| 369 | Value uint64 |
| 370 | } |
| 371 | |
| 372 | type IOxsPacketCount interface { |
| 373 | IOxs |
| 374 | GetValue() uint64 |
| 375 | } |
| 376 | |
| 377 | func (self *OxsPacketCount) GetValue() uint64 { |
| 378 | return self.Value |
| 379 | } |
| 380 | |
| 381 | func (self *OxsPacketCount) SetValue(v uint64) { |
| 382 | self.Value = v |
| 383 | } |
| 384 | |
| 385 | func (self *OxsPacketCount) Serialize(encoder *goloxi.Encoder) error { |
| 386 | if err := self.Oxs.Serialize(encoder); err != nil { |
| 387 | return err |
| 388 | } |
| 389 | |
| 390 | encoder.PutUint64(uint64(self.Value)) |
| 391 | |
| 392 | return nil |
| 393 | } |
| 394 | |
| 395 | func DecodeOxsPacketCount(parent *Oxs, decoder *goloxi.Decoder) (*OxsPacketCount, error) { |
| 396 | _oxspacketcount := &OxsPacketCount{Oxs: parent} |
| 397 | if decoder.Length() < 8 { |
| 398 | return nil, fmt.Errorf("OxsPacketCount packet too short: %d < 8", decoder.Length()) |
| 399 | } |
| 400 | _oxspacketcount.Value = uint64(decoder.ReadUint64()) |
| 401 | return _oxspacketcount, nil |
| 402 | } |
| 403 | |
| 404 | func NewOxsPacketCount() *OxsPacketCount { |
| 405 | obj := &OxsPacketCount{ |
| 406 | Oxs: NewOxs(2147616264), |
| 407 | } |
| 408 | return obj |
| 409 | } |
| 410 | func (self *OxsPacketCount) GetOXSName() string { |
| 411 | return "packet_count" |
| 412 | } |
| 413 | |
| 414 | func (self *OxsPacketCount) GetOXSValue() interface{} { |
| 415 | return self.Value |
| 416 | } |
| 417 | |
| 418 | func (self *OxsPacketCount) MarshalJSON() ([]byte, error) { |
| 419 | var value interface{} = self.GetOXSValue() |
| 420 | switch t := value.(type) { |
| 421 | case net.HardwareAddr: |
| 422 | value = t.String() |
| 423 | case net.IP: |
| 424 | value = t.String() |
| 425 | default: |
| 426 | if s, ok := t.(fmt.Stringer); ok { |
| 427 | value = s.String() |
| 428 | } else { |
| 429 | value = t |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | jsonValue, err := json.Marshal(value) |
| 434 | if err != nil { |
| 435 | return nil, err |
| 436 | } |
| 437 | return []byte(fmt.Sprintf("{\"Type\":\"%s\",\"Value\":%s}", self.GetOXSName(), string(jsonValue))), nil |
| 438 | } |