blob: 8c1f108cfc6ff72729701cdcedbf09080bd6f54c [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301// Copyright 2019 The GoPacket Authors. All rights reserved.
2
3package gopacket
4
5// Created by gen.go, don't edit manually
6// Generated at 2019-06-18 11:37:31.308731293 +0600 +06 m=+0.000842599
7
8// LayersDecoder returns DecodingLayerFunc for specified
9// DecodingLayerContainer, LayerType value to start decoding with and
10// some DecodeFeedback.
11func LayersDecoder(dl DecodingLayerContainer, first LayerType, df DecodeFeedback) DecodingLayerFunc {
12 firstDec, ok := dl.Decoder(first)
13 if !ok {
14 return func([]byte, *[]LayerType) (LayerType, error) {
15 return first, nil
16 }
17 }
18 if dlc, ok := dl.(DecodingLayerSparse); ok {
19 return func(data []byte, decoded *[]LayerType) (LayerType, error) {
20 *decoded = (*decoded)[:0] // Truncated decoded layers.
21 typ := first
22 decoder := firstDec
23 for {
24 if err := decoder.DecodeFromBytes(data, df); err != nil {
25 return LayerTypeZero, err
26 }
27 *decoded = append(*decoded, typ)
28 typ = decoder.NextLayerType()
29 if data = decoder.LayerPayload(); len(data) == 0 {
30 break
31 }
32 if decoder, ok = dlc.Decoder(typ); !ok {
33 return typ, nil
34 }
35 }
36 return LayerTypeZero, nil
37 }
38 }
39 if dlc, ok := dl.(DecodingLayerArray); ok {
40 return func(data []byte, decoded *[]LayerType) (LayerType, error) {
41 *decoded = (*decoded)[:0] // Truncated decoded layers.
42 typ := first
43 decoder := firstDec
44 for {
45 if err := decoder.DecodeFromBytes(data, df); err != nil {
46 return LayerTypeZero, err
47 }
48 *decoded = append(*decoded, typ)
49 typ = decoder.NextLayerType()
50 if data = decoder.LayerPayload(); len(data) == 0 {
51 break
52 }
53 if decoder, ok = dlc.Decoder(typ); !ok {
54 return typ, nil
55 }
56 }
57 return LayerTypeZero, nil
58 }
59 }
60 if dlc, ok := dl.(DecodingLayerMap); ok {
61 return func(data []byte, decoded *[]LayerType) (LayerType, error) {
62 *decoded = (*decoded)[:0] // Truncated decoded layers.
63 typ := first
64 decoder := firstDec
65 for {
66 if err := decoder.DecodeFromBytes(data, df); err != nil {
67 return LayerTypeZero, err
68 }
69 *decoded = append(*decoded, typ)
70 typ = decoder.NextLayerType()
71 if data = decoder.LayerPayload(); len(data) == 0 {
72 break
73 }
74 if decoder, ok = dlc.Decoder(typ); !ok {
75 return typ, nil
76 }
77 }
78 return LayerTypeZero, nil
79 }
80 }
81 dlc := dl
82 return func(data []byte, decoded *[]LayerType) (LayerType, error) {
83 *decoded = (*decoded)[:0] // Truncated decoded layers.
84 typ := first
85 decoder := firstDec
86 for {
87 if err := decoder.DecodeFromBytes(data, df); err != nil {
88 return LayerTypeZero, err
89 }
90 *decoded = append(*decoded, typ)
91 typ = decoder.NextLayerType()
92 if data = decoder.LayerPayload(); len(data) == 0 {
93 break
94 }
95 if decoder, ok = dlc.Decoder(typ); !ok {
96 return typ, nil
97 }
98 }
99 return LayerTypeZero, nil
100 }
101}