blob: cf156ee0ecdf4817f2cbdf4d422a635fb01d4591 [file] [log] [blame]
Jonathan Hart44bdbfc2020-04-14 17:45:47 -07001/*
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 */
7package of11
8
9import (
10 "encoding/json"
11 "fmt"
12 "net"
13
14 "github.com/opencord/goloxi"
15)
16
17// TODO: set real types
18type uint128 = goloxi.Uint128
19type Checksum128 [16]byte
20type Bitmap128 uint128
21type Bitmap512 struct {
22 a, b, c, d uint128
23}
24type Unimplemented struct{}
25type BSNVport uint16
26type ControllerURI uint16
27
28func (h *Header) MessageType() uint8 {
29 return h.Type
30}
31
32func (h *Header) MessageName() string {
33 return Type(h.Type).String()
34}
35
36func (self *Checksum128) Decode(decoder *goloxi.Decoder) error {
37 return nil
38}
39
40func (self *Checksum128) Serialize(encoder *goloxi.Encoder) error {
41 return nil
42}
43func (self *Bitmap128) Decode(decoder *goloxi.Decoder) error {
44 return nil
45}
46
47func (self *Bitmap128) Serialize(encoder *goloxi.Encoder) error {
48 return nil
49}
50func (self *Bitmap512) Decode(decoder *goloxi.Decoder) error {
51 return nil
52}
53
54func (self *Bitmap512) Serialize(encoder *goloxi.Encoder) error {
55 return nil
56}
57func (self *BSNVport) Decode(decoder *goloxi.Decoder) error {
58 return nil
59}
60
61func (self *BSNVport) Serialize(encoder *goloxi.Encoder) error {
62 return nil
63}
64func (self *ControllerURI) Decode(decoder *goloxi.Decoder) error {
65 return nil
66}
67
68func (self *ControllerURI) Serialize(encoder *goloxi.Encoder) error {
69 return nil
70}
71
72type FmCmd uint8
73
74func (self *FmCmd) Serialize(encoder *goloxi.Encoder) error {
75 encoder.PutUint8(uint8(*self))
76 return nil
77}
78
79func (self *FmCmd) Decode(decoder *goloxi.Decoder) error {
80 *self = FmCmd(decoder.ReadUint8())
81 return nil
82}
83
84type MatchBmap uint32
85
86func (self *MatchBmap) Serialize(encoder *goloxi.Encoder) error {
87 encoder.PutUint32(uint32(*self))
88 return nil
89}
90
91func (self *MatchBmap) Decode(decoder *goloxi.Decoder) error {
92 *self = MatchBmap(decoder.ReadUint32())
93 return nil
94}
95
96type WcBmap uint32
97
98func (self *WcBmap) Serialize(encoder *goloxi.Encoder) error {
99 encoder.PutUint32(uint32(*self))
100 return nil
101}
102
103func (self *WcBmap) Decode(decoder *goloxi.Decoder) error {
104 *self = WcBmap(decoder.ReadUint32())
105 return nil
106}
107
108type Match = MatchV2
109type PortNo uint32
110
111func (self *PortNo) Serialize(encoder *goloxi.Encoder) error {
112 encoder.PutUint32(uint32(*self))
113 return nil
114}
115
116func (self *PortNo) Decode(decoder *goloxi.Decoder) error {
117 *self = PortNo(decoder.ReadUint32())
118 return nil
119}
120
121func 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
130func (self *Port) Serialize(encoder *goloxi.Encoder) error {
131 portNo := PortNo(*self)
132 return portNo.Serialize(encoder)
133}
134
135func (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
144func 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}