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"
25 #include "asn/per/whole_number.hpp"
26 #include "asn/per/binary_integer.hpp"
31 template<class IE, class Enable = void>
35 struct Enumerated<IE, std::enable_if_t<(IE::constraint_t::type == constraint_type::CONSTRAINED)> >
37 static void inline run(IE const& ie, EncoderCtx& ctx)
39 if (ie.get() > IE::constraint_t::upper_bound)
41 ctx.refErrorCtx().valueRangeError(static_cast<size_t>(ie.get()));
44 ConstrainedWholeNumber<typename IE::constraint_t, typename IE::value_type>::run(ctx, ie.get());
46 static void inline run(IE& ie, DecoderCtx& ctx)
48 ie.set(ConstrainedWholeNumber<typename IE::constraint_t, typename IE::value_type>::run(ctx));
53 struct Enumerated<IE, std::enable_if_t<(IE::constraint_t::type == constraint_type::CONSTRAINED_EXTENDED)> >
55 static void inline run(IE const& ie, EncoderCtx& ctx)
57 if (ie.get() <= IE::constraint_t::upper_bound)
59 Tools::bit_accessor::put(0, 1, ctx.refBuffer());
60 ConstrainedWholeNumber<typename IE::constraint_t, typename IE::value_type>::run(ctx, ie.get());
64 Tools::bit_accessor::put(1, 1, ctx.refBuffer());
65 NormallySmallNonnegativeBinaryInteger<IE>::run(ie, ctx, ie.get() - IE::constraint_t::upper_bound - 1);
68 static void inline run(IE& ie, DecoderCtx& ctx)
70 u8 ext = Tools::bit_accessor::get(1, ctx.refBuffer());
72 ie.set(IE::constraint_t::upper_bound + 1 + NormallySmallNonnegativeBinaryInteger<IE>::run(ctx));
74 ie.set(ConstrainedWholeNumber<typename IE::constraint_t, typename IE::value_type>::run(ctx));