Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DataWrapper.cpp
00001 /** 00002 * @file DataWrapper.cpp 00003 * @brief mbed CoAP Endpoint Resource Data Wrapper 00004 * @author Doug Anson 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #include "mbed-connector-interface/DataWrapper.h" 00024 00025 // constructor 00026 DataWrapper::DataWrapper(uint8_t *data,int data_length) { 00027 this->m_data = data; 00028 this->m_data_length = 0; 00029 this->m_data_length_max = data_length; 00030 this->m_alloced = false; 00031 this->reset(); 00032 } 00033 00034 // constructor (alloc) 00035 DataWrapper::DataWrapper(int data_length) { 00036 this->m_data = (uint8_t *)malloc(data_length+1); 00037 memset(this->m_data,0,data_length+1); 00038 this->m_data_length = 0; 00039 this->m_data_length_max = data_length; 00040 this->m_alloced = true; 00041 } 00042 00043 // copy constructor 00044 DataWrapper::DataWrapper(const DataWrapper &data) { 00045 this->m_data = data.m_data; 00046 this->m_data_length = data.m_data_length; 00047 this->m_data_length_max = data.m_data_length_max; 00048 this->m_alloced = data.m_alloced; 00049 } 00050 00051 // destructor 00052 DataWrapper::~DataWrapper() { 00053 if (this->m_alloced && this->m_data != NULL) free(this->m_data); 00054 } 00055 00056 // wrap 00057 void DataWrapper::wrap(uint8_t *data,int data_length) { 00058 this->reset(); 00059 if (data != NULL && data_length > 0) { 00060 int length = data_length; 00061 if (length > this->m_data_length_max) length = this->m_data_length_max; 00062 memcpy(this->m_data,data,length); 00063 this->m_data_length = length; 00064 } 00065 } 00066 00067 // unwrap 00068 void DataWrapper::unwrap(uint8_t *data,int data_length) { 00069 this->reset(); 00070 if (data != NULL && data_length > 0) { 00071 int length = data_length; 00072 if (length > this->m_data_length_max) length = this->m_data_length_max; 00073 memcpy(this->m_data,data,length); 00074 this->m_data_length = length; 00075 } 00076 } 00077 00078 // reset 00079 void DataWrapper::reset() { 00080 if (this->m_data != NULL && this->m_data_length_max > 0) 00081 memset(this->m_data,0,this->m_data_length_max); 00082 this->m_data_length = 0; 00083 } 00084 00085 // set the app key 00086 void DataWrapper::setAppKey(uint8_t *appkey,int appkey_length) { 00087 // do nothing in the base class 00088 ; 00089 } 00090 00091
Generated on Wed Jul 13 2022 21:59:32 by
1.7.2