layers_decoder.go 2.8 KB

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