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