mbed Connector Endpoint interface. This interface permits a mbed endpoint to easily setup MDS resources and emit those resources to an MDS server.

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

api/DataWrapper.h

Committer:
ansond
Date:
2015-03-20
Revision:
25:1fc958ac14d1
Parent:
24:a6915e19814e
Child:
26:b06a19916f05

File content as of revision 25:1fc958ac14d1:

/**
 * @file    DataWrapper.h
 * @brief   mbed CoAP Endpoint Data Wrapper class
 * @author  Doug Anson
 * @version 1.0
 * @see
 *
 * Copyright (c) 2014
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __DATA_WRAPPER_H__
#define __DATA_WRAPPER_H__

// mbed support
#include "mbed.h"

class DataWrapper {
    public:
        /**
        Default constructor
        */
        DataWrapper(uint8_t *data,int data_length);
        
        /**
        Default constructor (alloc)
        */
        DataWrapper(int data_length);
        
        /**
        Default copy constructor
        */
        DataWrapper(const DataWrapper &data);
        
        /**
        Destructor
        */
        virtual ~DataWrapper();
        
        /**
        Wrap the data
        */
        virtual void wrap(uint8_t *data,int data_length);
        
        /**
        Unwrap the data
        */
        virtual void unwrap(uint8_t *data,int data_length);
        
        /**
        Get the wrap/unwrap result
        @return pointer to the data buffer of DataWrapper containing the wrap/unwrap result
        */
        uint8_t *get() { return this->m_data; }
        
        /**
        Get the wrap/unwrap result length
        @return length of the wrap/unwrap data result
        */
        int length() { return this->m_data_length; }
        
        /**
        Reset the wrapper
        */
        void reset();
    protected:
        uint8_t *m_data;
        
    private:
        bool     m_alloced;
        int      m_data_length;
        int      m_data_length_max;
};

#endif // __DATA_WRAPPER_H__