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(); }
72 template <class IE, int IE_TYPE>
75 error_context m_errCtx;
80 /********************************************************************************
82 *********************************************************************************/
83 class DecoderCtx : boost::noncopyable
86 typedef buffer<u8 const*> buf_type;
87 typedef allocator alloc_type;
89 DecoderCtx(const void* data = nullptr, size_t size = 0, void* alloc_buffer = nullptr, size_t alloc_buffer_size = 0)
90 : m_buffer{ m_errCtx }
92 reset(data, size, alloc_buffer, alloc_buffer_size);
95 buf_type& refBuffer() { return m_buffer; }
96 alloc_type& refAllocator() { return m_allocator; }
97 error_context& refErrorCtx() { return m_errCtx; }
98 explicit operator bool() const { return static_cast<bool>(m_errCtx); }
100 void reset(const void* data = nullptr, size_t size = 0, void* alloc_buffer = nullptr, size_t alloc_buffer_size = 0)
102 m_allocator.reset(alloc_buffer, alloc_buffer_size);
103 m_buffer.reset(static_cast<u8 const*>(data), size);
107 //Name of the being processed IE
108 void ie_name(const char* name) { m_errCtx.ie_name(name); }
109 char const* ie_name() const { return m_errCtx.ie_name(); }
112 error_context m_errCtx;
114 alloc_type m_allocator;