Enhanced SIM for E2AP v1 for TS UC
[sim/e2-interface.git] / e2sim / e2apv1sim / src / ASN1 / asn / per / oid.hpp
1 #pragma once
2 /******************************************************************************
3 *
4 *   Copyright (c) 2019 AT&T Intellectual Property.
5 *   Copyright (c) 2018-2019 Nokia.
6 *
7 *   Licensed under the Apache License, Version 2.0 (the "License");
8 *   you may not use this file except in compliance with the License.
9 *   You may obtain a copy of the License at
10 *
11 *       http://www.apache.org/licenses/LICENSE-2.0
12 *
13 *   Unless required by applicable law or agreed to in writing, software
14 *   distributed under the License is distributed on an "AS IS" BASIS,
15 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 *   See the License for the specific language governing permissions and
17 *   limitations under the License.
18 *
19 ******************************************************************************/
20
21 // Standard Includes: ANSI C/C++, MSA, and Third-Party Libraries
22
23 // Local Includes: Application specific classes, functions, and libraries
24 #include "asn/per/common.hpp"
25
26 namespace asn {
27 namespace per {
28
29 template <class IE>
30 struct Oid
31 {
32         static void inline run(IE const& ie, EncoderCtx& ctx)
33         {
34                 size_t len = ie.get().size();
35                 
36                 if (len > 255)
37                 {
38                         ctx.refErrorCtx().valueError(len, 0, 0);
39                 }
40                 else
41                 {
42                         Tools::bit_accessor::padByte(ctx.refBuffer());
43                         ctx.refBuffer().putBytes(reinterpret_cast<uint8_t*>(&len), 1);
44                         ctx.refBuffer().putBytes(ie.get().data(), len);
45                 }
46         }
47         
48         static void inline run(IE& ie, DecoderCtx& ctx)
49         {
50                 Tools::bit_accessor::padByte(ctx.refBuffer());
51                 
52                 uint8_t const* data_in = ctx.refBuffer().getBytes(1); // length
53                 
54                 if(data_in)
55                 {
56                         size_t len = *data_in;
57                         data_in = ctx.refBuffer().getBytes(len);
58                         
59                         if (data_in)
60                         {
61                                 ie.set(len, data_in);
62                         }
63                 }
64         }
65 };
66
67 } //namespace per
68 } //namespace asn