blob: ff9c778ef777f17265304bf4642422276cbf90ff [file] [log] [blame]
kalnagy45114752019-06-18 14:40:39 +02001/*
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
20package control
21
22import (
23 "encoding/gob"
24 "bytes"
25 "errors"
26)
27
28type E2ap struct {
29}
30
31func (c *E2ap) GetSubscriptionSequenceNumber(payload []byte) (int, error) {
32 asn1 := new(Asn1)
33 message, err := asn1.Decode(payload)
34 if err != nil {
35 return 0, errors.New("Unable to decode payload due to "+ err.Error())
36 }
37 return message.SubscriptionId, nil
38}
39
40func (c *E2ap) SetSubscriptionSequenceNumber(payload []byte, newSubscriptionid int) ([]byte ,error) {
41 asn1 := new(Asn1)
42 message, err := asn1.Decode(payload)
43 if err != nil {
44 return make([]byte,0), errors.New("Unable to decode payload due to "+ err.Error())
45 }
46 message.SubscriptionId = newSubscriptionid
47 payload, err = asn1.Encode(message)
48 if err != nil {
49 return make([]byte,0), errors.New("Unable to encode message due to "+ err.Error())
50 }
51 return payload, nil
52}
53
54
55func (c *E2ap) GetPayloadContent(payload []byte) (content string, err error) {
56 asn1 := new(Asn1)
57 message, err := asn1.Decode(payload)
58 content = message.Content
59 return
60}
61/*
62Serialize and Deserialize message using this until real ASN1 GO wrapper is not in place
63*/
64type Asn1 struct {
65}
66
67func (a *Asn1) Encode(message RmrPayload) ([]byte, error) {
68 buffer := new(bytes.Buffer)
69 asn1 := gob.NewEncoder(buffer)
70 if err := asn1.Encode(message); err != nil {
71 return nil, err
72 }
73 return buffer.Bytes(), nil
74}
75
76func (a *Asn1) Decode(data []byte) (RmrPayload, error) {
77 message := new(RmrPayload)
78 buffer := bytes.NewBuffer(data)
79 asn1 := gob.NewDecoder(buffer)
80 if err := asn1.Decode(message); err != nil {
81 return RmrPayload{}, err
82 }
83 return *message, nil
84}