Binary API generator improvements
[govpp.git] / examples / binapi / af_packet / af_packet.ba.go
1 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
2 // versions:
3 //  binapi-generator: v0.4.0-dev
4 //  VPP:              20.05-release
5 // source: /usr/share/vpp/api/core/af_packet.api.json
6
7 /*
8 Package af_packet contains generated code for VPP API file af_packet.api (2.0.0).
9
10 It consists of:
11           2 aliases
12           6 enums
13           8 messages
14 */
15 package af_packet
16
17 import (
18         "bytes"
19         "context"
20         "encoding/binary"
21         "fmt"
22         "io"
23         "math"
24         "net"
25         "strconv"
26         "strings"
27
28         api "git.fd.io/govpp.git/api"
29         codec "git.fd.io/govpp.git/codec"
30         struc "github.com/lunixbochs/struc"
31
32         interface_types "git.fd.io/govpp.git/examples/binapi/interface_types"
33 )
34
35 // This is a compile-time assertion to ensure that this generated file
36 // is compatible with the GoVPP api package it is being compiled against.
37 // A compilation error at this line likely means your copy of the
38 // GoVPP api package needs to be updated.
39 const _ = api.GoVppAPIPackageIsVersion2 // please upgrade the GoVPP api package
40
41 const (
42         // ModuleName is the name of this module.
43         ModuleName = "af_packet"
44         // APIVersion is the API version of this module.
45         APIVersion = "2.0.0"
46         // VersionCrc is the CRC of this module.
47         VersionCrc = 0xe0b6c022
48 )
49
50 // MacAddress represents VPP binary API alias 'mac_address'.
51 type MacAddress [6]uint8
52
53 func ParseMAC(mac string) (parsed MacAddress, err error) {
54         var hw net.HardwareAddr
55         if hw, err = net.ParseMAC(mac); err != nil {
56                 return
57         }
58         copy(parsed[:], hw[:])
59         return
60 }
61
62 func (m *MacAddress) ToString() string {
63         return net.HardwareAddr(m[:]).String()
64 }
65
66 // AfPacketCreate represents VPP binary API message 'af_packet_create'.
67 type AfPacketCreate struct {
68         HwAddr          MacAddress `binapi:"mac_address,name=hw_addr" json:"hw_addr,omitempty"`
69         UseRandomHwAddr bool       `binapi:"bool,name=use_random_hw_addr" json:"use_random_hw_addr,omitempty"`
70         HostIfName      string     `binapi:"string[64],name=host_if_name" json:"host_if_name,omitempty" struc:"[64]byte"`
71 }
72
73 func (m *AfPacketCreate) Reset()                        { *m = AfPacketCreate{} }
74 func (*AfPacketCreate) GetMessageName() string          { return "af_packet_create" }
75 func (*AfPacketCreate) GetCrcString() string            { return "a190415f" }
76 func (*AfPacketCreate) GetMessageType() api.MessageType { return api.RequestMessage }
77
78 func (m *AfPacketCreate) Size() int {
79         if m == nil {
80                 return 0
81         }
82         var size int
83         // field[1] m.HwAddr
84         size += 6
85         // field[1] m.UseRandomHwAddr
86         size += 1
87         // field[1] m.HostIfName
88         size += 64
89         return size
90 }
91 func (m *AfPacketCreate) Marshal(b []byte) ([]byte, error) {
92         o := binary.BigEndian
93         _ = o
94         pos := 0
95         _ = pos
96         var buf []byte
97         if b == nil {
98                 buf = make([]byte, m.Size())
99         } else {
100                 buf = b
101         }
102         // field[1] m.HwAddr
103         for i := 0; i < 6; i++ {
104                 var x uint8
105                 if i < len(m.HwAddr) {
106                         x = uint8(m.HwAddr[i])
107                 }
108                 buf[pos] = uint8(x)
109                 pos += 1
110         }
111         // field[1] m.UseRandomHwAddr
112         if m.UseRandomHwAddr {
113                 buf[pos] = 1
114         }
115         pos += 1
116         // field[1] m.HostIfName
117         copy(buf[pos:pos+64], m.HostIfName)
118         pos += 64
119         return buf, nil
120 }
121 func (m *AfPacketCreate) Unmarshal(tmp []byte) error {
122         o := binary.BigEndian
123         _ = o
124         pos := 0
125         _ = pos
126         // field[1] m.HwAddr
127         for i := 0; i < len(m.HwAddr); i++ {
128                 m.HwAddr[i] = uint8(tmp[pos])
129                 pos += 1
130         }
131         // field[1] m.UseRandomHwAddr
132         m.UseRandomHwAddr = tmp[pos] != 0
133         pos += 1
134         // field[1] m.HostIfName
135         {
136                 nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
137                 m.HostIfName = codec.DecodeString(tmp[pos : pos+nul])
138                 pos += 64
139         }
140         return nil
141 }
142
143 // AfPacketCreateReply represents VPP binary API message 'af_packet_create_reply'.
144 type AfPacketCreateReply struct {
145         Retval    int32                          `binapi:"i32,name=retval" json:"retval,omitempty"`
146         SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
147 }
148
149 func (m *AfPacketCreateReply) Reset()                        { *m = AfPacketCreateReply{} }
150 func (*AfPacketCreateReply) GetMessageName() string          { return "af_packet_create_reply" }
151 func (*AfPacketCreateReply) GetCrcString() string            { return "5383d31f" }
152 func (*AfPacketCreateReply) GetMessageType() api.MessageType { return api.ReplyMessage }
153
154 func (m *AfPacketCreateReply) Size() int {
155         if m == nil {
156                 return 0
157         }
158         var size int
159         // field[1] m.Retval
160         size += 4
161         // field[1] m.SwIfIndex
162         size += 4
163         return size
164 }
165 func (m *AfPacketCreateReply) Marshal(b []byte) ([]byte, error) {
166         o := binary.BigEndian
167         _ = o
168         pos := 0
169         _ = pos
170         var buf []byte
171         if b == nil {
172                 buf = make([]byte, m.Size())
173         } else {
174                 buf = b
175         }
176         // field[1] m.Retval
177         o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
178         pos += 4
179         // field[1] m.SwIfIndex
180         o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
181         pos += 4
182         return buf, nil
183 }
184 func (m *AfPacketCreateReply) Unmarshal(tmp []byte) error {
185         o := binary.BigEndian
186         _ = o
187         pos := 0
188         _ = pos
189         // field[1] m.Retval
190         m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
191         pos += 4
192         // field[1] m.SwIfIndex
193         m.SwIfIndex = interface_types.InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
194         pos += 4
195         return nil
196 }
197
198 // AfPacketDelete represents VPP binary API message 'af_packet_delete'.
199 type AfPacketDelete struct {
200         HostIfName string `binapi:"string[64],name=host_if_name" json:"host_if_name,omitempty" struc:"[64]byte"`
201 }
202
203 func (m *AfPacketDelete) Reset()                        { *m = AfPacketDelete{} }
204 func (*AfPacketDelete) GetMessageName() string          { return "af_packet_delete" }
205 func (*AfPacketDelete) GetCrcString() string            { return "863fa648" }
206 func (*AfPacketDelete) GetMessageType() api.MessageType { return api.RequestMessage }
207
208 func (m *AfPacketDelete) Size() int {
209         if m == nil {
210                 return 0
211         }
212         var size int
213         // field[1] m.HostIfName
214         size += 64
215         return size
216 }
217 func (m *AfPacketDelete) Marshal(b []byte) ([]byte, error) {
218         o := binary.BigEndian
219         _ = o
220         pos := 0
221         _ = pos
222         var buf []byte
223         if b == nil {
224                 buf = make([]byte, m.Size())
225         } else {
226                 buf = b
227         }
228         // field[1] m.HostIfName
229         copy(buf[pos:pos+64], m.HostIfName)
230         pos += 64
231         return buf, nil
232 }
233 func (m *AfPacketDelete) Unmarshal(tmp []byte) error {
234         o := binary.BigEndian
235         _ = o
236         pos := 0
237         _ = pos
238         // field[1] m.HostIfName
239         {
240                 nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
241                 m.HostIfName = codec.DecodeString(tmp[pos : pos+nul])
242                 pos += 64
243         }
244         return nil
245 }
246
247 // AfPacketDeleteReply represents VPP binary API message 'af_packet_delete_reply'.
248 type AfPacketDeleteReply struct {
249         Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
250 }
251
252 func (m *AfPacketDeleteReply) Reset()                        { *m = AfPacketDeleteReply{} }
253 func (*AfPacketDeleteReply) GetMessageName() string          { return "af_packet_delete_reply" }
254 func (*AfPacketDeleteReply) GetCrcString() string            { return "e8d4e804" }
255 func (*AfPacketDeleteReply) GetMessageType() api.MessageType { return api.ReplyMessage }
256
257 func (m *AfPacketDeleteReply) Size() int {
258         if m == nil {
259                 return 0
260         }
261         var size int
262         // field[1] m.Retval
263         size += 4
264         return size
265 }
266 func (m *AfPacketDeleteReply) Marshal(b []byte) ([]byte, error) {
267         o := binary.BigEndian
268         _ = o
269         pos := 0
270         _ = pos
271         var buf []byte
272         if b == nil {
273                 buf = make([]byte, m.Size())
274         } else {
275                 buf = b
276         }
277         // field[1] m.Retval
278         o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
279         pos += 4
280         return buf, nil
281 }
282 func (m *AfPacketDeleteReply) Unmarshal(tmp []byte) error {
283         o := binary.BigEndian
284         _ = o
285         pos := 0
286         _ = pos
287         // field[1] m.Retval
288         m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
289         pos += 4
290         return nil
291 }
292
293 // AfPacketDetails represents VPP binary API message 'af_packet_details'.
294 type AfPacketDetails struct {
295         SwIfIndex  interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
296         HostIfName string                         `binapi:"string[64],name=host_if_name" json:"host_if_name,omitempty" struc:"[64]byte"`
297 }
298
299 func (m *AfPacketDetails) Reset()                        { *m = AfPacketDetails{} }
300 func (*AfPacketDetails) GetMessageName() string          { return "af_packet_details" }
301 func (*AfPacketDetails) GetCrcString() string            { return "58c7c042" }
302 func (*AfPacketDetails) GetMessageType() api.MessageType { return api.ReplyMessage }
303
304 func (m *AfPacketDetails) Size() int {
305         if m == nil {
306                 return 0
307         }
308         var size int
309         // field[1] m.SwIfIndex
310         size += 4
311         // field[1] m.HostIfName
312         size += 64
313         return size
314 }
315 func (m *AfPacketDetails) Marshal(b []byte) ([]byte, error) {
316         o := binary.BigEndian
317         _ = o
318         pos := 0
319         _ = pos
320         var buf []byte
321         if b == nil {
322                 buf = make([]byte, m.Size())
323         } else {
324                 buf = b
325         }
326         // field[1] m.SwIfIndex
327         o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
328         pos += 4
329         // field[1] m.HostIfName
330         copy(buf[pos:pos+64], m.HostIfName)
331         pos += 64
332         return buf, nil
333 }
334 func (m *AfPacketDetails) Unmarshal(tmp []byte) error {
335         o := binary.BigEndian
336         _ = o
337         pos := 0
338         _ = pos
339         // field[1] m.SwIfIndex
340         m.SwIfIndex = interface_types.InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
341         pos += 4
342         // field[1] m.HostIfName
343         {
344                 nul := bytes.Index(tmp[pos:pos+64], []byte{0x00})
345                 m.HostIfName = codec.DecodeString(tmp[pos : pos+nul])
346                 pos += 64
347         }
348         return nil
349 }
350
351 // AfPacketDump represents VPP binary API message 'af_packet_dump'.
352 type AfPacketDump struct{}
353
354 func (m *AfPacketDump) Reset()                        { *m = AfPacketDump{} }
355 func (*AfPacketDump) GetMessageName() string          { return "af_packet_dump" }
356 func (*AfPacketDump) GetCrcString() string            { return "51077d14" }
357 func (*AfPacketDump) GetMessageType() api.MessageType { return api.RequestMessage }
358
359 func (m *AfPacketDump) Size() int {
360         if m == nil {
361                 return 0
362         }
363         var size int
364         return size
365 }
366 func (m *AfPacketDump) Marshal(b []byte) ([]byte, error) {
367         o := binary.BigEndian
368         _ = o
369         pos := 0
370         _ = pos
371         var buf []byte
372         if b == nil {
373                 buf = make([]byte, m.Size())
374         } else {
375                 buf = b
376         }
377         return buf, nil
378 }
379 func (m *AfPacketDump) Unmarshal(tmp []byte) error {
380         o := binary.BigEndian
381         _ = o
382         pos := 0
383         _ = pos
384         return nil
385 }
386
387 // AfPacketSetL4CksumOffload represents VPP binary API message 'af_packet_set_l4_cksum_offload'.
388 type AfPacketSetL4CksumOffload struct {
389         SwIfIndex interface_types.InterfaceIndex `binapi:"interface_index,name=sw_if_index" json:"sw_if_index,omitempty"`
390         Set       bool                           `binapi:"bool,name=set" json:"set,omitempty"`
391 }
392
393 func (m *AfPacketSetL4CksumOffload) Reset()                        { *m = AfPacketSetL4CksumOffload{} }
394 func (*AfPacketSetL4CksumOffload) GetMessageName() string          { return "af_packet_set_l4_cksum_offload" }
395 func (*AfPacketSetL4CksumOffload) GetCrcString() string            { return "319cd5c8" }
396 func (*AfPacketSetL4CksumOffload) GetMessageType() api.MessageType { return api.RequestMessage }
397
398 func (m *AfPacketSetL4CksumOffload) Size() int {
399         if m == nil {
400                 return 0
401         }
402         var size int
403         // field[1] m.SwIfIndex
404         size += 4
405         // field[1] m.Set
406         size += 1
407         return size
408 }
409 func (m *AfPacketSetL4CksumOffload) Marshal(b []byte) ([]byte, error) {
410         o := binary.BigEndian
411         _ = o
412         pos := 0
413         _ = pos
414         var buf []byte
415         if b == nil {
416                 buf = make([]byte, m.Size())
417         } else {
418                 buf = b
419         }
420         // field[1] m.SwIfIndex
421         o.PutUint32(buf[pos:pos+4], uint32(m.SwIfIndex))
422         pos += 4
423         // field[1] m.Set
424         if m.Set {
425                 buf[pos] = 1
426         }
427         pos += 1
428         return buf, nil
429 }
430 func (m *AfPacketSetL4CksumOffload) Unmarshal(tmp []byte) error {
431         o := binary.BigEndian
432         _ = o
433         pos := 0
434         _ = pos
435         // field[1] m.SwIfIndex
436         m.SwIfIndex = interface_types.InterfaceIndex(o.Uint32(tmp[pos : pos+4]))
437         pos += 4
438         // field[1] m.Set
439         m.Set = tmp[pos] != 0
440         pos += 1
441         return nil
442 }
443
444 // AfPacketSetL4CksumOffloadReply represents VPP binary API message 'af_packet_set_l4_cksum_offload_reply'.
445 type AfPacketSetL4CksumOffloadReply struct {
446         Retval int32 `binapi:"i32,name=retval" json:"retval,omitempty"`
447 }
448
449 func (m *AfPacketSetL4CksumOffloadReply) Reset() { *m = AfPacketSetL4CksumOffloadReply{} }
450 func (*AfPacketSetL4CksumOffloadReply) GetMessageName() string {
451         return "af_packet_set_l4_cksum_offload_reply"
452 }
453 func (*AfPacketSetL4CksumOffloadReply) GetCrcString() string            { return "e8d4e804" }
454 func (*AfPacketSetL4CksumOffloadReply) GetMessageType() api.MessageType { return api.ReplyMessage }
455
456 func (m *AfPacketSetL4CksumOffloadReply) Size() int {
457         if m == nil {
458                 return 0
459         }
460         var size int
461         // field[1] m.Retval
462         size += 4
463         return size
464 }
465 func (m *AfPacketSetL4CksumOffloadReply) Marshal(b []byte) ([]byte, error) {
466         o := binary.BigEndian
467         _ = o
468         pos := 0
469         _ = pos
470         var buf []byte
471         if b == nil {
472                 buf = make([]byte, m.Size())
473         } else {
474                 buf = b
475         }
476         // field[1] m.Retval
477         o.PutUint32(buf[pos:pos+4], uint32(m.Retval))
478         pos += 4
479         return buf, nil
480 }
481 func (m *AfPacketSetL4CksumOffloadReply) Unmarshal(tmp []byte) error {
482         o := binary.BigEndian
483         _ = o
484         pos := 0
485         _ = pos
486         // field[1] m.Retval
487         m.Retval = int32(o.Uint32(tmp[pos : pos+4]))
488         pos += 4
489         return nil
490 }
491
492 func init() { file_af_packet_binapi_init() }
493 func file_af_packet_binapi_init() {
494         api.RegisterMessage((*AfPacketCreate)(nil), "af_packet.AfPacketCreate")
495         api.RegisterMessage((*AfPacketCreateReply)(nil), "af_packet.AfPacketCreateReply")
496         api.RegisterMessage((*AfPacketDelete)(nil), "af_packet.AfPacketDelete")
497         api.RegisterMessage((*AfPacketDeleteReply)(nil), "af_packet.AfPacketDeleteReply")
498         api.RegisterMessage((*AfPacketDetails)(nil), "af_packet.AfPacketDetails")
499         api.RegisterMessage((*AfPacketDump)(nil), "af_packet.AfPacketDump")
500         api.RegisterMessage((*AfPacketSetL4CksumOffload)(nil), "af_packet.AfPacketSetL4CksumOffload")
501         api.RegisterMessage((*AfPacketSetL4CksumOffloadReply)(nil), "af_packet.AfPacketSetL4CksumOffloadReply")
502 }
503
504 // Messages returns list of all messages in this module.
505 func AllMessages() []api.Message {
506         return []api.Message{
507                 (*AfPacketCreate)(nil),
508                 (*AfPacketCreateReply)(nil),
509                 (*AfPacketDelete)(nil),
510                 (*AfPacketDeleteReply)(nil),
511                 (*AfPacketDetails)(nil),
512                 (*AfPacketDump)(nil),
513                 (*AfPacketSetL4CksumOffload)(nil),
514                 (*AfPacketSetL4CksumOffloadReply)(nil),
515         }
516 }
517
518 // Reference imports to suppress errors if they are not otherwise used.
519 var _ = api.RegisterMessage
520 var _ = codec.DecodeString
521 var _ = bytes.NewBuffer
522 var _ = context.Background
523 var _ = io.Copy
524 var _ = strconv.Itoa
525 var _ = strings.Contains
526 var _ = struc.Pack
527 var _ = binary.BigEndian
528 var _ = math.Float32bits
529 var _ = net.ParseIP
530 var _ = fmt.Errorf