Enhanced SIM for E2AP v1 for TS UC
[sim/e2-interface.git] / e2sim / e2apv1sim / src / ASN1 / asn / ber / opentype.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
25 namespace asn {
26 namespace ber {
27
28 /***************************************************************************************
29 * OpenType
30 ***************************************************************************************/
31 struct OpenType
32 {
33         static tag_value_t decode(DecoderCtx& ctx, size_t& length, tag_value_t const* tag_ptr = nullptr)
34         {
35                 auto & buffer = ctx.refBuffer();
36                 tag_value_t tag = tag_ptr ? *tag_ptr : get_tag(ctx);
37                 length = Length::decode(ctx);
38                 
39                 if(!length)
40                 {
41                         //just return
42                 }
43                 else if(length == indefinite_length)
44                 {
45                         tag_value_t _tag;
46                         size_t _length;
47                         do
48                         {
49                                 _tag = OpenType::decode(ctx, _length);
50
51                         } while(ctx && !(_tag == 0 && _length == 0));
52                 }
53                 else
54                 {
55                         if (buffer.getBytesLeft() < length)
56                         {
57                                 ctx.refErrorCtx().lengthErrorBytes(buffer.getBytesLeft(), length);
58                         }
59                         else
60                         {
61                                 size_t _length;
62                                 DecoderCtx::buf_type::pointer end = buffer.end();
63                                 buffer.set_end(buffer.begin() + length);
64                                 decode(ctx, _length);
65                                 buffer.set_end(end);
66                         }
67                 }
68                 return tag;
69         }
70 };
71
72 } //namespace ber
73 } //namespace asn