2 /******************************************************************************
4 * Copyright (c) 2019 AT&T Intellectual Property.
5 * Copyright (c) 2018-2019 Nokia.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************************/
21 // Standard Includes: ANSI C/C++, MSA, and Third-Party Libraries
23 // Local Includes: Application specific classes, functions, and libraries
24 #include "asn/per/common.hpp"
29 template <class IE, class Enable = void>
33 template <class IE, class Enabler = void>
34 struct SequenceOfNoExt
36 static void inline run(IE const& ie, EncoderCtx& ctx)
38 LengthDeterminant<typename IE::constraint_t>::run(ctx, ie.size());
40 static void inline run(IE& ie, DecoderCtx& ctx)
42 size_t len = LengthDeterminant<typename IE::constraint_t>::run(ctx, false);
43 for (size_t i = 0; i < len; ++i)
45 u8* data = ctx.refAllocator().alloc_bytes(sizeof(typename IE::value_type));
48 typename IE::value_type * v = new (data) typename IE::value_type;
54 ctx.refErrorCtx().allocatorNoMem(0, sizeof(typename IE::value_type));
63 struct SequenceOfNoExt<IE, std::enable_if_t<
64 ((IE::constraint_t::upper_bound == IE::constraint_t::lower_bound) && (IE::constraint_t::upper_bound < 65536))
67 static void inline run(IE const& ie, EncoderCtx& ctx) {/*do nothing*/ }
68 static void inline run(IE& ie, DecoderCtx& ctx)
70 for (size_t i = 0; i < IE::constraint_t::upper_bound; ++i)
72 u8* data = ctx.refAllocator().alloc_bytes(sizeof(typename IE::value_type));
75 typename IE::value_type * v = new (data) typename IE::value_type;
81 ctx.refErrorCtx().allocatorNoMem(0, sizeof(typename IE::value_type));
88 /**************************************************/
90 //19.4 Extension present
92 struct SequenceOf<IE, std::enable_if_t< (IE::constraint_t::extended == true)> >
94 static void inline run(IE const& ie, EncoderCtx& ctx)
96 if (ie.size() <= IE::constraint_t::upper_bound && ie.size() >= IE::constraint_t::lower_bound)
98 Tools::bit_accessor::put(0, 1, ctx.refBuffer());
99 SequenceOfNoExt<IE>::run(ie, ctx);
103 Tools::bit_accessor::put(1, 1, ctx.refBuffer());
104 LengthDeterminant<typename IE::constraint_t>::run(ctx, ie.size());
107 static void inline run(IE& ie, DecoderCtx& ctx)
109 u8 ext = Tools::bit_accessor::get(1, ctx.refBuffer());
112 size_t len = LengthDeterminant<typename IE::constraint_t>::run(ctx, true);
113 for (size_t i = 0; i < len; ++i)
115 u8* data = ctx.refAllocator().alloc_bytes(sizeof(typename IE::value_type));
118 typename IE::value_type * v = new (data) typename IE::value_type;
124 ctx.refErrorCtx().allocatorNoMem(0, sizeof(typename IE::value_type));
130 SequenceOfNoExt<IE>::run(ie, ctx);
134 //19.5-6 No extension
136 struct SequenceOf<IE, std::enable_if_t< (IE::constraint_t::extended == false)> >
138 static void inline run(IE const& ie, EncoderCtx& ctx)
140 if (IE::constraint_t::lower_bound >= 0 && ie.size() < size_t(IE::constraint_t::lower_bound))
142 ctx.refErrorCtx().sizeRangeError(ie.size(), size_t(IE::constraint_t::lower_bound));
146 SequenceOfNoExt<IE>::run(ie, ctx);
149 static void inline run(IE& ie, DecoderCtx& ctx)
151 SequenceOfNoExt<IE>::run(ie, ctx);