2 * Copyright (C) 2017 Cisco Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // @author Changxue Deng <chadeng@cisco.com>
38 MBData::MBData(int size, int match_options)
43 buff = static_cast<uint8_t*>(malloc(buff_len + 1));
58 options = match_options;
61 // Caller must free data.
62 int MBData::TransferValueTo(uint8_t* &data, int &dlen)
64 if(buff == NULL || data_len <= 0)
68 return MBError::INVALID_ARG;
81 data = (uint8_t *) malloc(data_len + 1);
83 return MBError::NO_MEMORY;
84 memcpy(data, buff, data_len);
88 return MBError::SUCCESS;
91 // Data must be allocated using malloc or calloc.
92 int MBData::TransferValueFrom(uint8_t* &data, int dlen)
95 return MBError::INVALID_ARG;
97 if(free_buffer && buff != NULL)
105 return MBError::SUCCESS;
114 // This function is for prefix match only.
122 int MBData::Resize(int size)
136 buff = static_cast<uint8_t*>(malloc(buff_len + 1));
141 return MBError::NO_MEMORY;
145 return MBError::SUCCESS;