#ifndef MESHCOP_DATASET_HPP_
#define MESHCOP_DATASET_HPP_
#include "openthread-core-config.h"
#include <openthread/dataset.h>
#include "common/locator.hpp"
#include "common/message.hpp"
#include "common/timer.hpp"
#include "meshcop/meshcop_tlvs.hpp"
namespace ot {
namespace MeshCoP {
class Dataset
{
friend class DatasetLocal;
public:
enum
{
kMaxSize = 256, kMaxValueSize = 16, kMaxGetTypes = 64, };
enum Type
{
kActive, kPending, };
explicit Dataset(Type aType);
void Clear(void);
bool IsValid(void) const;
Tlv *GetTlv(Tlv::Type aType) { return const_cast<Tlv *>(const_cast<const Dataset *>(this)->GetTlv(aType)); }
const Tlv *GetTlv(Tlv::Type aType) const;
template <typename TlvType> TlvType *GetTlv(void)
{
return static_cast<TlvType *>(GetTlv(static_cast<Tlv::Type>(TlvType::kType)));
}
template <typename TlvType> const TlvType *GetTlv(void) const
{
return static_cast<const TlvType *>(GetTlv(static_cast<Tlv::Type>(TlvType::kType)));
}
uint8_t *GetBytes(void) { return mTlvs; }
const uint8_t *GetBytes(void) const { return mTlvs; }
void ConvertTo(otOperationalDataset &aDataset) const;
uint16_t GetSize(void) const { return mLength; }
void SetSize(uint16_t aSize) { mLength = aSize; }
TimeMilli GetUpdateTime(void) const { return mUpdateTime; }
const Timestamp *GetTimestamp(void) const;
void SetTimestamp(const Timestamp &aTimestamp);
otError SetTlv(const Tlv &aTlv);
otError SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength);
otError SetUint16Tlv(Tlv::Type aType, uint16_t aValue);
otError SetUint32Tlv(Tlv::Type aType, uint32_t aValue);
otError Set(const Message &aMessage, uint16_t aOffset, uint8_t aLength);
void Set(const Dataset &aDataset);
otError SetFrom(const otOperationalDataset &aDataset);
void RemoveTlv(Tlv::Type aType);
otError AppendMleDatasetTlv(Message &aMessage) const;
otError ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdated = NULL) const;
void ConvertToActive(void);
Tlv *GetTlvsStart(void) { return reinterpret_cast<Tlv *>(mTlvs); }
const Tlv *GetTlvsStart(void) const { return reinterpret_cast<const Tlv *>(mTlvs); }
Tlv *GetTlvsEnd(void) { return reinterpret_cast<Tlv *>(mTlvs + mLength); }
const Tlv *GetTlvsEnd(void) const { return reinterpret_cast<const Tlv *>(mTlvs + mLength); }
static const char *TypeToString(Type aType);
private:
void RemoveTlv(Tlv *aTlv);
uint8_t mTlvs[kMaxSize]; TimeMilli mUpdateTime; uint16_t mLength; Type mType; };
} }
#endif