Chip Boling | 934e105 | 2021-09-27 15:12:06 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
| 3 | * Copyright 2020-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | /* |
| 18 | * NOTE: This file was generated, manual edits will be overwritten! |
| 19 | * |
| 20 | * Generated by 'goCodeGenerator.py': |
| 21 | * https://github.com/cboling/OMCI-parser/README.md |
| 22 | */ |
| 23 | |
| 24 | package generated |
| 25 | |
| 26 | import ( |
| 27 | "errors" |
| 28 | ) |
| 29 | |
| 30 | // Custom Go Error messages for relaxed decode error signaling. |
| 31 | // |
| 32 | // gopacket does not provide a way to easily perform relaxed decoding calls |
| 33 | // during the 'DecodeFromBytes' decoding of a layer. It does allow for an error |
| 34 | // code returned and this will be used to allow for relaxed decoding. If a |
| 35 | // particular message type decode can be relaxed, process it as relax and |
| 36 | // return an error derived from the RelaxedDecodeError below and check for |
| 37 | // it as appropriate. |
| 38 | |
| 39 | // IRelaxedDecodeError provides a base interface that can be used to derive |
| 40 | // other decode specific errors that can be relaxed at the application's |
| 41 | // discretion |
| 42 | type IRelaxedDecodeError interface { |
| 43 | // Error interface, so if relaxed decode is not supported, this behaves as |
| 44 | // a normal error |
| 45 | Error() string |
| 46 | GetError() error |
| 47 | |
| 48 | //////////////////////////////// |
| 49 | // Relaxed error specific |
| 50 | |
| 51 | // GetContents returns the octet payload specific to the error if it can be |
| 52 | // determined. Derived relaxed decode errors may provide more specific control |
| 53 | // and information |
| 54 | GetContents() []byte |
| 55 | } |
| 56 | |
| 57 | type RelaxedDecodeError struct { |
| 58 | err string |
| 59 | Contents []byte |
| 60 | } |
| 61 | |
| 62 | func (e *RelaxedDecodeError) GetError() error { |
| 63 | return errors.New(e.err) |
| 64 | } |
| 65 | |
| 66 | func (e *RelaxedDecodeError) Error() string { |
| 67 | return e.err |
| 68 | } |
| 69 | |
| 70 | func (e *RelaxedDecodeError) GetContents() []byte { |
| 71 | return e.Contents |
| 72 | } |
| 73 | |
| 74 | // UnknownAttributeDecodeError is used to convey unknown attributes found in |
| 75 | // a received packet undergoing decode. These will always be trailing attributes |
| 76 | // in packets and are often due to: |
| 77 | // o New versions of ITU G.988 being issued with an existing ME getting new |
| 78 | // attributes, |
| 79 | // |
| 80 | // o An error in the code generated classes in this library where one or more |
| 81 | // attributes were missed, or |
| 82 | // |
| 83 | // o An error in the OLT/ONU that serialized the message |
| 84 | type UnknownAttributeDecodeError struct { |
| 85 | RelaxedDecodeError |
| 86 | AttributeMask uint16 |
| 87 | |
| 88 | EntityClass ClassID // Set by first level handler of the error |
| 89 | EntityInstance uint16 // Set by first level handler of the error |
| 90 | } |
| 91 | |
| 92 | func NewUnknownAttributeDecodeError(msg string, mask uint16, contents []byte) *UnknownAttributeDecodeError { |
| 93 | err := &UnknownAttributeDecodeError{ |
| 94 | RelaxedDecodeError: RelaxedDecodeError{ |
| 95 | err: msg, |
| 96 | }, |
| 97 | AttributeMask: mask, |
| 98 | } |
| 99 | if contents != nil { |
| 100 | err.Contents = make([]byte, len(contents)) |
| 101 | copy(err.Contents, contents) |
| 102 | } |
| 103 | return err |
| 104 | } |