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
24 // Local Includes: Application specific classes, functions, and libraries
25 #include "asn/utility.hpp"
26 #include "asn/buffer.hpp"
27 #include "asn/error_context.hpp"
32 /********************************************************************************
34 *********************************************************************************/
35 class EncoderCtx : boost::noncopyable
38 typedef buffer<u8*> buf_type;
40 EncoderCtx(u8* data, size_t size)
41 : m_buffer{ m_errCtx }
46 template <size_t SIZE>
47 explicit EncoderCtx(u8(&buff)[SIZE])
48 : EncoderCtx(buff, SIZE)
53 : EncoderCtx(nullptr, 0)
57 buf_type& refBuffer() { return m_buffer; }
58 error_context& refErrorCtx() { return m_errCtx; }
59 explicit operator bool() const { return static_cast<bool>(m_errCtx); }
61 void Reset(void* data = nullptr, size_t size = 0)
63 m_buffer.reset(static_cast<u8*>(data), size);
67 //Name of the being processed IE
68 void ie_name(const char* name) { m_errCtx.ie_name(name); }
69 char const* ie_name() const { return m_errCtx.ie_name(); }
71 void container_name(const char* name) { m_errCtx.container_name(name); }
72 char const* container_name() const { return m_errCtx.container_name(); }
75 template <class IE, int IE_TYPE>
78 error_context m_errCtx;
83 /********************************************************************************
85 *********************************************************************************/
86 class DecoderCtx : boost::noncopyable
89 typedef buffer<u8 const*> buf_type;
90 typedef allocator alloc_type;
93 DecoderCtx(const void* data = nullptr, size_t size = 0, void* alloc_buffer = nullptr, size_t alloc_buffer_size = 0)
94 : m_buffer{ m_errCtx }
96 reset(data, size, alloc_buffer, alloc_buffer_size);
99 buf_type& refBuffer() { return m_buffer; }
100 alloc_type& refAllocator() { return m_allocator; }
101 error_context& refErrorCtx() { return m_errCtx; }
102 explicit operator bool() const { return static_cast<bool>(m_errCtx); }
104 void reset(const void* data = nullptr, size_t size = 0, void* alloc_buffer = nullptr, size_t alloc_buffer_size = 0)
106 m_allocator.reset(alloc_buffer, alloc_buffer_size);
107 m_buffer.reset(static_cast<u8 const*>(data), size);
110 m_container = nullptr;
115 //m_map = (m_map << 1) | (m_map >> (sizeof(m_map)*CHAR_BIT - 1));
118 constexpr map_type mask = ((map_type)1) << (sizeof(map_type)*CHAR_BIT - 1);
120 bool rv = m_map & mask;
126 map_type set_map(map_type map)
128 map_type rval = m_map;
133 map_type get_map() const {return m_map;}
135 //Pointer to container (SEQ | CHO)
136 void* m_container{ nullptr };
138 //Name of the being processed IE
139 void ie_name(const char* name) { m_errCtx.ie_name(name); }
140 char const* ie_name() const { return m_errCtx.ie_name(); }
142 void container_name(const char* name) { m_errCtx.container_name(name); }
143 char const* container_name() const { return m_errCtx.container_name(); }
146 //Optional or Extension elements' presence bitmap. Used in sequences
148 error_context m_errCtx;
150 alloc_type m_allocator;