Clean packing. Removing packer layer.
[ric-plt/submgr.git] / pkg / control / e2ap.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20 package control
21
22 /*
23 #include <wrapper.h>
24
25 #cgo LDFLAGS: -le2ap_wrapper -le2ap
26 */
27 import "C"
28
29 import (
30         "encoding/hex"
31         "fmt"
32         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
33         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
34         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
35 )
36
37 var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
38
39 type E2ap struct {
40 }
41
42 //-----------------------------------------------------------------------------
43 //
44 //-----------------------------------------------------------------------------
45 func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) {
46         e2SubReq := packerif.NewPackerSubscriptionRequest()
47         err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload})
48         if err != nil {
49                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
50         }
51         return subReq, nil
52 }
53
54 func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *e2ap.PackedData, error) {
55         e2SubReq := packerif.NewPackerSubscriptionRequest()
56         err, packedData := e2SubReq.Pack(req)
57         if err != nil {
58                 return 0, nil, err
59         }
60         return xapp.RIC_SUB_REQ, packedData, nil
61 }
62
63 //-----------------------------------------------------------------------------
64 //
65 //-----------------------------------------------------------------------------
66 func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) {
67         e2SubResp := packerif.NewPackerSubscriptionResponse()
68         err, subResp := e2SubResp.UnPack(&e2ap.PackedData{payload})
69         if err != nil {
70                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
71         }
72         return subResp, nil
73 }
74
75 func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *e2ap.PackedData, error) {
76         e2SubResp := packerif.NewPackerSubscriptionResponse()
77         err, packedData := e2SubResp.Pack(req)
78         if err != nil {
79                 return 0, nil, err
80         }
81         return xapp.RIC_SUB_RESP, packedData, nil
82 }
83
84 //-----------------------------------------------------------------------------
85 //
86 //-----------------------------------------------------------------------------
87 func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) {
88         e2SubFail := packerif.NewPackerSubscriptionFailure()
89         err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload})
90         if err != nil {
91                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
92         }
93         return subFail, nil
94 }
95
96 func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *e2ap.PackedData, error) {
97         e2SubFail := packerif.NewPackerSubscriptionFailure()
98         err, packedData := e2SubFail.Pack(req)
99         if err != nil {
100                 return 0, nil, err
101         }
102         return xapp.RIC_SUB_FAILURE, packedData, nil
103 }
104
105 //-----------------------------------------------------------------------------
106 //
107 //-----------------------------------------------------------------------------
108 func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) {
109         e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
110         err, subDelReq := e2SubDelReq.UnPack(&e2ap.PackedData{payload})
111         if err != nil {
112                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
113         }
114         return subDelReq, nil
115 }
116
117 func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *e2ap.PackedData, error) {
118         e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
119         err, packedData := e2SubDelReq.Pack(req)
120         if err != nil {
121                 return 0, nil, err
122         }
123         return xapp.RIC_SUB_DEL_REQ, packedData, nil
124 }
125
126 //-----------------------------------------------------------------------------
127 //
128 //-----------------------------------------------------------------------------
129 func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) {
130         e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
131         err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload})
132         if err != nil {
133                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
134         }
135         return subDelResp, nil
136 }
137
138 func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *e2ap.PackedData, error) {
139         e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
140         err, packedData := e2SubDelResp.Pack(req)
141         if err != nil {
142                 return 0, nil, err
143         }
144         return xapp.RIC_SUB_DEL_RESP, packedData, nil
145 }
146
147 //-----------------------------------------------------------------------------
148 //
149 //-----------------------------------------------------------------------------
150 func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) {
151         e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
152         err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload})
153         if err != nil {
154                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
155         }
156         return subDelFail, nil
157 }
158
159 func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *e2ap.PackedData, error) {
160         e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
161         err, packedData := e2SubDelFail.Pack(req)
162         if err != nil {
163                 return 0, nil, err
164         }
165         return xapp.RIC_SUB_DEL_FAILURE, packedData, nil
166 }