1 //--------------------------------------------------------------------------
2 // Copyright (C) 2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // buffer_data.cc author Amarnath Nayak <amarnaya@cisco.com>
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include "buffer_data.h"
24 
25 namespace snort
26 {
BufferData(int32_t length,const uint8_t * data_,bool own_the_buffer_=false)27 BufferData::BufferData(int32_t length, const uint8_t* data_, bool own_the_buffer_ = false) :
28             len(length), data(data_), own_the_buffer(own_the_buffer_){}
29 
~BufferData()30 BufferData::~BufferData()
31 {
32     if (own_the_buffer)
33         delete[] data;
34 }
35 
length() const36 int32_t BufferData::length() const
37 {
38     return len;
39 }
40 
data_ptr() const41 const uint8_t* BufferData::data_ptr() const
42 {
43     return data;
44 }
45 
set(int32_t length,const uint8_t * data_,bool own_the_buffer_)46 void BufferData::set(int32_t length, const uint8_t* data_, bool own_the_buffer_)
47 {
48     len = length;
49     data = data_;
50     own_the_buffer = own_the_buffer_;
51 }
52 
reset()53 void BufferData::reset()
54 {
55     if (own_the_buffer)
56         delete[] data;
57 
58     len = 0;
59     data = nullptr;
60     own_the_buffer = false;
61 }
62 }
63