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 | package of11 |
| 8 | |
| 9 | import ( |
| 10 | "encoding/json" |
| 11 | "fmt" |
| 12 | "net" |
| 13 | |
| 14 | "github.com/opencord/goloxi" |
| 15 | ) |
| 16 | |
| 17 | // TODO: set real types |
| 18 | type uint128 = goloxi.Uint128 |
| 19 | type Checksum128 [16]byte |
| 20 | type Bitmap128 uint128 |
| 21 | type Bitmap512 struct { |
| 22 | a, b, c, d uint128 |
| 23 | } |
| 24 | type Unimplemented struct{} |
| 25 | type BSNVport uint16 |
| 26 | type ControllerURI uint16 |
| 27 | |
| 28 | func (h *Header) MessageType() uint8 { |
| 29 | return h.Type |
| 30 | } |
| 31 | |
| 32 | func (h *Header) MessageName() string { |
| 33 | return Type(h.Type).String() |
| 34 | } |
| 35 | |
| 36 | func (self *Checksum128) Decode(decoder *goloxi.Decoder) error { |
| 37 | return nil |
| 38 | } |
| 39 | |
| 40 | func (self *Checksum128) Serialize(encoder *goloxi.Encoder) error { |
| 41 | return nil |
| 42 | } |
| 43 | func (self *Bitmap128) Decode(decoder *goloxi.Decoder) error { |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | func (self *Bitmap128) Serialize(encoder *goloxi.Encoder) error { |
| 48 | return nil |
| 49 | } |
| 50 | func (self *Bitmap512) Decode(decoder *goloxi.Decoder) error { |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | func (self *Bitmap512) Serialize(encoder *goloxi.Encoder) error { |
| 55 | return nil |
| 56 | } |
| 57 | func (self *BSNVport) Decode(decoder *goloxi.Decoder) error { |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | func (self *BSNVport) Serialize(encoder *goloxi.Encoder) error { |
| 62 | return nil |
| 63 | } |
| 64 | func (self *ControllerURI) Decode(decoder *goloxi.Decoder) error { |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | func (self *ControllerURI) Serialize(encoder *goloxi.Encoder) error { |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | type FmCmd uint8 |
| 73 | |
| 74 | func (self *FmCmd) Serialize(encoder *goloxi.Encoder) error { |
| 75 | encoder.PutUint8(uint8(*self)) |
| 76 | return nil |
| 77 | } |
| 78 | |
| 79 | func (self *FmCmd) Decode(decoder *goloxi.Decoder) error { |
| 80 | *self = FmCmd(decoder.ReadUint8()) |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | type MatchBmap uint32 |
| 85 | |
| 86 | func (self *MatchBmap) Serialize(encoder *goloxi.Encoder) error { |
| 87 | encoder.PutUint32(uint32(*self)) |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | func (self *MatchBmap) Decode(decoder *goloxi.Decoder) error { |
| 92 | *self = MatchBmap(decoder.ReadUint32()) |
| 93 | return nil |
| 94 | } |
| 95 | |
| 96 | type WcBmap uint32 |
| 97 | |
| 98 | func (self *WcBmap) Serialize(encoder *goloxi.Encoder) error { |
| 99 | encoder.PutUint32(uint32(*self)) |
| 100 | return nil |
| 101 | } |
| 102 | |
| 103 | func (self *WcBmap) Decode(decoder *goloxi.Decoder) error { |
| 104 | *self = WcBmap(decoder.ReadUint32()) |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | type Match = MatchV2 |
| 109 | type PortNo uint32 |
| 110 | |
| 111 | func (self *PortNo) Serialize(encoder *goloxi.Encoder) error { |
| 112 | encoder.PutUint32(uint32(*self)) |
| 113 | return nil |
| 114 | } |
| 115 | |
| 116 | func (self *PortNo) Decode(decoder *goloxi.Decoder) error { |
| 117 | *self = PortNo(decoder.ReadUint32()) |
| 118 | return nil |
| 119 | } |
| 120 | |
| 121 | func DecodeMessage(data []byte) (goloxi.Message, error) { |
| 122 | header, err := DecodeHeader(goloxi.NewDecoder(data)) |
| 123 | if err != nil { |
| 124 | return nil, err |
| 125 | } |
| 126 | |
| 127 | return header.(goloxi.Message), nil |
| 128 | } |
| 129 | |
| 130 | func (self *Port) Serialize(encoder *goloxi.Encoder) error { |
| 131 | portNo := PortNo(*self) |
| 132 | return portNo.Serialize(encoder) |
| 133 | } |
| 134 | |
| 135 | func (self *Port) Decode(decoder *goloxi.Decoder) error { |
| 136 | portNo := PortNo(*self) |
| 137 | if err := portNo.Decode(decoder); err != nil { |
| 138 | return err |
| 139 | } |
| 140 | *self = Port(portNo) |
| 141 | return nil |
| 142 | } |
| 143 | |
| 144 | func jsonValue(value interface{}) ([]byte, error) { |
| 145 | switch t := value.(type) { |
| 146 | case net.HardwareAddr: |
| 147 | value = t.String() |
| 148 | case net.IP: |
| 149 | value = t.String() |
| 150 | default: |
| 151 | if s, ok := t.(fmt.Stringer); ok { |
| 152 | value = s.String() |
| 153 | } else { |
| 154 | value = t |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return json.Marshal(value) |
| 159 | } |