blob: d733c912b4bb0d9f725c9a000fc9cb2e142466a6 [file] [log] [blame]
Andrea Campanella10426e22021-10-15 17:58:04 +02001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
3 * Copyright 2020-present Open Networking Foundation
Elia Battiston9bfe1102022-02-03 10:38:03 +01004 *
Andrea Campanella10426e22021-10-15 17:58:04 +02005 * 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
Elia Battiston9bfe1102022-02-03 10:38:03 +01008 *
Andrea Campanella10426e22021-10-15 17:58:04 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Elia Battiston9bfe1102022-02-03 10:38:03 +010010 *
Andrea Campanella10426e22021-10-15 17:58:04 +020011 * 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 */
Elia Battiston9bfe1102022-02-03 10:38:03 +010023
Andrea Campanella10426e22021-10-15 17:58:04 +020024package generated
25
26import (
27 "fmt"
28)
29
30var relaxedDecode map[int]bool
31
32func 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
40func mkRelaxedKey(msgType MsgType, request bool) int {
41 if request {
42 return int(msgType)
43 }
44 return 100 + int(msgType)
45}
46
47func 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
57func 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
66func 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}