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