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 |
Chip Boling | 8cdd639 | 2022-01-27 08:43:37 -0600 | [diff] [blame] | 4 | * |
Chip Boling | 934e105 | 2021-09-27 15:12:06 -0500 | [diff] [blame] | 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 |
Chip Boling | 8cdd639 | 2022-01-27 08:43:37 -0600 | [diff] [blame] | 8 | * |
Chip Boling | 934e105 | 2021-09-27 15:12:06 -0500 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Chip Boling | 8cdd639 | 2022-01-27 08:43:37 -0600 | [diff] [blame] | 10 | * |
Chip Boling | 934e105 | 2021-09-27 15:12:06 -0500 | [diff] [blame] | 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 | */ |
Chip Boling | 8cdd639 | 2022-01-27 08:43:37 -0600 | [diff] [blame] | 23 | |
Chip Boling | 934e105 | 2021-09-27 15:12:06 -0500 | [diff] [blame] | 24 | package generated |
| 25 | |
| 26 | import ( |
| 27 | "fmt" |
| 28 | ) |
| 29 | |
| 30 | var relaxedDecode map[int]bool |
| 31 | |
| 32 | func init() { |
| 33 | relaxedDecode = make(map[int]bool) |
| 34 | |
| 35 | // Default for relaxed decode is True if there is relaxed decode support available |
| 36 | // relaxedDecode[mkRelaxedKey(Get, false)] = true |
| 37 | relaxedDecode[mkRelaxedKey(MibUploadNext, false)] = true |
| 38 | } |
| 39 | |
| 40 | func mkRelaxedKey(msgType MsgType, request bool) int { |
| 41 | if request { |
| 42 | return int(msgType) |
| 43 | } |
| 44 | return 100 + int(msgType) |
| 45 | } |
| 46 | |
| 47 | func SetRelaxedDecode(msgType MsgType, request bool, relax bool) error { |
| 48 | key := mkRelaxedKey(msgType, request) |
| 49 | |
| 50 | if _, ok := relaxedDecode[key]; !ok { |
| 51 | return fmt.Errorf("relax decode of '%v' is not supported", msgType) |
| 52 | } |
| 53 | relaxedDecode[key] = relax |
| 54 | return nil |
| 55 | } |
| 56 | |
| 57 | func GetRelaxedDecode(msgType MsgType, request bool) bool { |
| 58 | key := mkRelaxedKey(msgType, request) |
| 59 | |
| 60 | relaxed, ok := relaxedDecode[key] |
| 61 | return ok && relaxed |
| 62 | } |
| 63 | |
| 64 | // GetRelaxedDecodeByOctetType decodes the payload message-type value and determine if |
| 65 | // relaxed decode is enabled |
| 66 | func GetRelaxedDecodeByOctetType(value byte) bool { |
| 67 | msgType := MsgType(value & MsgTypeMask) |
| 68 | var request bool |
| 69 | |
| 70 | if msgType != AlarmNotification && msgType != AttributeValueChange && msgType != TestResult { |
| 71 | request = value&AR == AR || value&AK == 0 |
| 72 | } |
| 73 | return GetRelaxedDecode(msgType, request) |
| 74 | } |