DataTypeDescriptor, DataTypeHash

This commit is contained in:
Pavel Kirienko
2014-02-06 15:50:14 +04:00
parent 544940fd6b
commit 7ed9c43e95
3 changed files with 68 additions and 6 deletions
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#include <algorithm>
namespace uavcan
{
enum DataTypeKind
{
DATA_TYPE_KIND_SERVICE,
DATA_TYPE_KIND_MESSAGE,
NUM_DATA_TYPE_KINDS
};
struct DataTypeHash
{
enum { BYTES = 16 };
uint8_t value[BYTES];
DataTypeHash()
{
std::fill(value, value + BYTES, 0);
}
DataTypeHash(const uint8_t source[BYTES])
{
std::copy(source, source + BYTES, value);
}
bool operator!=(const DataTypeHash& rhs) const { return !operator==(rhs); }
bool operator==(const DataTypeHash& rhs) const
{
return std::equal(value, value + BYTES, rhs.value);
}
};
struct DataTypeDescriptor
{
DataTypeKind kind;
uint16_t id;
DataTypeHash hash;
DataTypeDescriptor()
: kind(DataTypeKind(0))
, id(0)
{ }
DataTypeDescriptor(DataTypeKind kind, uint16_t id, const DataTypeHash& hash)
: kind(kind)
, id(id)
, hash(hash)
{ }
bool operator!=(const DataTypeDescriptor& rhs) const { return !operator==(rhs); }
bool operator==(const DataTypeDescriptor& rhs) const
{
return (kind == rhs.kind) && (id == rhs.id) && (hash == rhs.hash);
}
};
}
@@ -27,12 +27,6 @@ enum TransferType
NUM_TRANSFER_TYPES = 4
};
enum DataTypeKind
{
DATA_TYPE_KIND_SERVICE,
DATA_TYPE_KIND_MESSAGE,
NUM_DATA_TYPE_KINDS
};
class TransferID
{
@@ -7,6 +7,7 @@
#include <cassert>
#include <stdint.h>
#include <uavcan/internal/transport/transfer.hpp>
#include <uavcan/internal/data_type.hpp>
#include <uavcan/internal/linked_list.hpp>
#include <uavcan/internal/impl_constants.hpp>
#include <uavcan/internal/dynamic_memory.hpp>