Skip to content

Commit

Permalink
Add support for the uint64 and int64 data types to the RDM messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewman committed Sep 19, 2024
1 parent f7afc58 commit 5bd4759
Show file tree
Hide file tree
Showing 33 changed files with 277 additions and 27 deletions.
36 changes: 30 additions & 6 deletions common/messaging/DescriptorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ using std::vector;
using ola::messaging::BoolFieldDescriptor;
using ola::messaging::FieldDescriptor;
using ola::messaging::FieldDescriptorGroup;
using ola::messaging::Int16FieldDescriptor;
using ola::messaging::Int32FieldDescriptor;
using ola::messaging::Int64FieldDescriptor;
using ola::messaging::Int8FieldDescriptor;
using ola::messaging::IPV4FieldDescriptor;
using ola::messaging::IPV6FieldDescriptor;
using ola::messaging::MACFieldDescriptor;
using ola::messaging::StringFieldDescriptor;
using ola::messaging::UIDFieldDescriptor;
using ola::messaging::UInt16FieldDescriptor;
using ola::messaging::UInt32FieldDescriptor;
using ola::messaging::UInt64FieldDescriptor;
using ola::messaging::UInt8FieldDescriptor;

class DescriptorTest: public CppUnit::TestFixture {
Expand Down Expand Up @@ -113,7 +118,7 @@ void DescriptorTest::testFieldDescriptors() {
OLA_ASSERT_EQ(1u, uint8_descriptor.MaxSize());
OLA_ASSERT_FALSE(uint8_descriptor.IsLittleEndian());
OLA_ASSERT_EQ(static_cast<int8_t>(10),
uint8_descriptor.Multiplier());
uint8_descriptor.Multiplier());
OLA_ASSERT_TRUE(uint8_descriptor.FixedSize());
OLA_ASSERT_TRUE(uint8_descriptor.LimitedSize());

Expand All @@ -122,7 +127,7 @@ void DescriptorTest::testFieldDescriptors() {
OLA_ASSERT_EQ(1u, uint8_descriptor2.MaxSize());
OLA_ASSERT_TRUE(uint8_descriptor2.IsLittleEndian());
OLA_ASSERT_EQ(static_cast<int8_t>(-1),
uint8_descriptor2.Multiplier());
uint8_descriptor2.Multiplier());
OLA_ASSERT_TRUE(uint8_descriptor2.FixedSize());
OLA_ASSERT_TRUE(uint8_descriptor2.LimitedSize());

Expand All @@ -132,7 +137,7 @@ void DescriptorTest::testFieldDescriptors() {
OLA_ASSERT_EQ(2u, uint16_descriptor.MaxSize());
OLA_ASSERT_FALSE(uint16_descriptor.IsLittleEndian());
OLA_ASSERT_EQ(static_cast<int8_t>(10),
uint16_descriptor.Multiplier());
uint16_descriptor.Multiplier());
OLA_ASSERT_TRUE(uint16_descriptor.FixedSize());
OLA_ASSERT_TRUE(uint16_descriptor.LimitedSize());

Expand All @@ -141,7 +146,7 @@ void DescriptorTest::testFieldDescriptors() {
OLA_ASSERT_EQ(2u, uint16_descriptor2.MaxSize());
OLA_ASSERT_TRUE(uint16_descriptor2.IsLittleEndian());
OLA_ASSERT_EQ(static_cast<int8_t>(-1),
uint16_descriptor2.Multiplier());
uint16_descriptor2.Multiplier());
OLA_ASSERT_TRUE(uint16_descriptor2.FixedSize());
OLA_ASSERT_TRUE(uint16_descriptor2.LimitedSize());

Expand All @@ -151,7 +156,7 @@ void DescriptorTest::testFieldDescriptors() {
OLA_ASSERT_EQ(4u, uint32_descriptor.MaxSize());
OLA_ASSERT_FALSE(uint32_descriptor.IsLittleEndian());
OLA_ASSERT_EQ(static_cast<int8_t>(10),
uint32_descriptor.Multiplier());
uint32_descriptor.Multiplier());
OLA_ASSERT_TRUE(uint32_descriptor.FixedSize());
OLA_ASSERT_TRUE(uint32_descriptor.LimitedSize());

Expand All @@ -160,9 +165,28 @@ void DescriptorTest::testFieldDescriptors() {
OLA_ASSERT_EQ(4u, uint32_descriptor2.MaxSize());
OLA_ASSERT_TRUE(uint32_descriptor2.IsLittleEndian());
OLA_ASSERT_EQ(static_cast<int8_t>(-1),
uint32_descriptor2.Multiplier());
uint32_descriptor2.Multiplier());
OLA_ASSERT_TRUE(uint32_descriptor2.FixedSize());
OLA_ASSERT_TRUE(uint32_descriptor2.LimitedSize());

// uint64_t
UInt64FieldDescriptor uint64_descriptor("uint64", false, 10);
OLA_ASSERT_EQ(string("uint64"), uint64_descriptor.Name());
OLA_ASSERT_EQ(8u, uint64_descriptor.MaxSize());
OLA_ASSERT_FALSE(uint64_descriptor.IsLittleEndian());
OLA_ASSERT_EQ(static_cast<int8_t>(10),
uint64_descriptor.Multiplier());
OLA_ASSERT_TRUE(uint64_descriptor.FixedSize());
OLA_ASSERT_TRUE(uint64_descriptor.LimitedSize());

UInt64FieldDescriptor uint64_descriptor2("uint64", true, -1);
OLA_ASSERT_EQ(string("uint64"), uint64_descriptor2.Name());
OLA_ASSERT_EQ(8u, uint64_descriptor2.MaxSize());
OLA_ASSERT_TRUE(uint64_descriptor2.IsLittleEndian());
OLA_ASSERT_EQ(static_cast<int8_t>(-1),
uint64_descriptor2.Multiplier());
OLA_ASSERT_TRUE(uint64_descriptor2.FixedSize());
OLA_ASSERT_TRUE(uint64_descriptor2.LimitedSize());
}


Expand Down
22 changes: 20 additions & 2 deletions common/messaging/MessagePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ void GenericMessagePrinter::Visit(const BasicMessageField<uint32_t> *message) {
}


void GenericMessagePrinter::Visit(const BasicMessageField<uint64_t> *message) {
const UInt64FieldDescriptor *descriptor = message->GetDescriptor();
AppendUInt(descriptor->Name(),
message->Value(),
descriptor->LookupValue(message->Value()),
descriptor->Multiplier());
}


void GenericMessagePrinter::Visit(const BasicMessageField<int8_t> *message) {
const Int8FieldDescriptor *descriptor = message->GetDescriptor();
AppendInt(descriptor->Name(),
Expand Down Expand Up @@ -140,6 +149,15 @@ void GenericMessagePrinter::Visit(const BasicMessageField<int32_t> *message) {
}


void GenericMessagePrinter::Visit(const BasicMessageField<int64_t> *message) {
const Int64FieldDescriptor *descriptor = message->GetDescriptor();
AppendInt(descriptor->Name(),
message->Value(),
descriptor->LookupValue(message->Value()),
descriptor->Multiplier());
}


void GenericMessagePrinter::Visit(const GroupMessageField *message) {
Stream() << string(m_indent, ' ')
<< TransformLabel(message->GetDescriptor()->Name()) << " {" << endl;
Expand All @@ -155,7 +173,7 @@ void GenericMessagePrinter::PostVisit(const GroupMessageField *message) {


void GenericMessagePrinter::AppendUInt(const string &name,
unsigned int value,
uint64_t value,
const string &label,
int8_t multiplier) {
Stream() << string(m_indent, ' ') << TransformLabel(name) << ": ";
Expand All @@ -170,7 +188,7 @@ void GenericMessagePrinter::AppendUInt(const string &name,


void GenericMessagePrinter::AppendInt(const string &name,
int value,
int64_t value,
const string &label,
int8_t multiplier) {
Stream() << string(m_indent, ' ') << TransformLabel(name) << ": ";
Expand Down
7 changes: 6 additions & 1 deletion common/messaging/MessagePrinterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ using ola::messaging::UIDFieldDescriptor;
using ola::messaging::UIDMessageField;
using ola::messaging::UInt32FieldDescriptor;
using ola::messaging::UInt32MessageField;
using ola::messaging::UInt64FieldDescriptor;
using ola::messaging::UInt64MessageField;
using ola::messaging::UInt8FieldDescriptor;
using ola::messaging::UInt8MessageField;

Expand Down Expand Up @@ -101,6 +103,7 @@ void GenericMessagePrinterTest::testSimplePrinter() {
UInt8FieldDescriptor uint8_descriptor("Count", false, -3);
Int8FieldDescriptor int8_descriptor("Delta", false, 1);
Int16FieldDescriptor int16_descriptor("Rate", false, -1);
UInt64FieldDescriptor uint64_descriptor("Data");

// try a simple print first
vector<const ola::messaging::MessageFieldInterface*> fields;
Expand All @@ -120,12 +123,14 @@ void GenericMessagePrinterTest::testSimplePrinter() {
fields.push_back(new UInt8MessageField(&uint8_descriptor, 4));
fields.push_back(new Int8MessageField(&int8_descriptor, 10));
fields.push_back(new Int16MessageField(&int16_descriptor, 10));
fields.push_back(new UInt64MessageField(&uint64_descriptor, 424242424242));

Message message(fields);
string expected = (
"On/Off: false\nip: 10.0.0.1\nipv6: ::ffff:192.168.0.1\n"
"mac: 01:23:45:67:89:ab\nuid: 7a70:00000001\nName: foobar\nId: 42\n"
"Count: 4 x 10 ^ -3\nDelta: 10 x 10 ^ 1\nRate: 10 x 10 ^ -1\n");
"Count: 4 x 10 ^ -3\nDelta: 10 x 10 ^ 1\nRate: 10 x 10 ^ -1\n"
"Data: 424242424242\n");
OLA_ASSERT_EQ(expected, m_printer.AsString(&message));
}

Expand Down
17 changes: 17 additions & 0 deletions common/messaging/SchemaPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ void SchemaPrinter::Visit(const UInt32FieldDescriptor *descriptor) {
}


void SchemaPrinter::Visit(const UInt64FieldDescriptor *descriptor) {
AppendHeading(descriptor->Name(), "uint64");
MaybeAppendIntervals(descriptor->Intervals());
MaybeAppendLabels(descriptor->Labels());
m_str << endl;
}


void SchemaPrinter::Visit(const Int8FieldDescriptor *descriptor) {
AppendHeading(descriptor->Name(), "int8");
MaybeAppendIntervals(descriptor->Intervals());
Expand All @@ -112,6 +120,15 @@ void SchemaPrinter::Visit(const Int32FieldDescriptor *descriptor) {
m_str << endl;
}


void SchemaPrinter::Visit(const Int64FieldDescriptor *descriptor) {
AppendHeading(descriptor->Name(), "int64");
MaybeAppendIntervals(descriptor->Intervals());
MaybeAppendLabels(descriptor->Labels());
m_str << endl;
}


void SchemaPrinter::Visit(const FieldDescriptorGroup *descriptor) {
m_str << string(m_indent, ' ') << descriptor->Name() << " {" << endl;
m_indent += m_indent_size;
Expand Down
5 changes: 5 additions & 0 deletions common/messaging/SchemaPrinterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ using ola::messaging::SchemaPrinter;
using ola::messaging::StringFieldDescriptor;
using ola::messaging::UInt16FieldDescriptor;
using ola::messaging::UInt32FieldDescriptor;
using ola::messaging::UInt64FieldDescriptor;
using ola::messaging::UInt8FieldDescriptor;
using ola::messaging::Int16FieldDescriptor;
using ola::messaging::Int32FieldDescriptor;
using ola::messaging::Int64FieldDescriptor;
using ola::messaging::Int8FieldDescriptor;
using ola::messaging::UIDFieldDescriptor;

Expand Down Expand Up @@ -235,5 +237,8 @@ void SchemaPrinterTest::testIntervalTypes() {
OLA_ASSERT_EQ(
string("Count: int32: (-70000, 82560)\n"),
GenerateIntervalString<Int32FieldDescriptor>(-70000, 82560));
OLA_ASSERT_EQ(
string("Count: int64: (-7000000000, 8256123456)\n"),
GenerateIntervalString<Int64FieldDescriptor>(-7000000000, 8256123456));
}

10 changes: 10 additions & 0 deletions common/rdm/DescriptorConsistencyChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ void DescriptorConsistencyChecker::Visit(
}


void DescriptorConsistencyChecker::Visit(
const ola::messaging::UInt64FieldDescriptor*) {
}


void DescriptorConsistencyChecker::Visit(
const ola::messaging::Int8FieldDescriptor*) {
}
Expand All @@ -94,6 +99,11 @@ void DescriptorConsistencyChecker::Visit(
}


void DescriptorConsistencyChecker::Visit(
const ola::messaging::Int64FieldDescriptor*) {
}


void DescriptorConsistencyChecker::Visit(
const ola::messaging::FieldDescriptorGroup *descriptor) {
if (!descriptor->FixedSize())
Expand Down
2 changes: 2 additions & 0 deletions common/rdm/DescriptorConsistencyChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ class DescriptorConsistencyChecker
void Visit(const ola::messaging::UInt8FieldDescriptor*);
void Visit(const ola::messaging::UInt16FieldDescriptor*);
void Visit(const ola::messaging::UInt32FieldDescriptor*);
void Visit(const ola::messaging::UInt64FieldDescriptor*);
void Visit(const ola::messaging::Int8FieldDescriptor*);
void Visit(const ola::messaging::Int16FieldDescriptor*);
void Visit(const ola::messaging::Int32FieldDescriptor*);
void Visit(const ola::messaging::Int64FieldDescriptor*);
void Visit(const ola::messaging::FieldDescriptorGroup*);
void PostVisit(const ola::messaging::FieldDescriptorGroup*);

Expand Down
24 changes: 24 additions & 0 deletions common/rdm/GroupSizeCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ void GroupSizeCalculator::Visit(
}


void GroupSizeCalculator::Visit(
const ola::messaging::UInt64FieldDescriptor *descriptor) {
m_non_groups.push_back(descriptor);
}


void GroupSizeCalculator::Visit(
const ola::messaging::Int8FieldDescriptor *descriptor) {
m_non_groups.push_back(descriptor);
Expand All @@ -191,6 +197,12 @@ void GroupSizeCalculator::Visit(
}


void GroupSizeCalculator::Visit(
const ola::messaging::Int64FieldDescriptor *descriptor) {
m_non_groups.push_back(descriptor);
}


void GroupSizeCalculator::Visit(
const ola::messaging::FieldDescriptorGroup *descriptor) {
m_groups.push_back(descriptor);
Expand Down Expand Up @@ -294,6 +306,12 @@ void StaticGroupTokenCalculator::Visit(
}


void StaticGroupTokenCalculator::Visit(
OLA_UNUSED const ola::messaging::UInt64FieldDescriptor *descriptor) {
m_token_count.top()++;
}


void StaticGroupTokenCalculator::Visit(
OLA_UNUSED const ola::messaging::Int8FieldDescriptor *descriptor) {
m_token_count.top()++;
Expand All @@ -312,6 +330,12 @@ void StaticGroupTokenCalculator::Visit(
}


void StaticGroupTokenCalculator::Visit(
OLA_UNUSED const ola::messaging::Int64FieldDescriptor *descriptor) {
m_token_count.top()++;
}


void StaticGroupTokenCalculator::Visit(
const ola::messaging::FieldDescriptorGroup *descriptor) {
m_token_count.push(0);
Expand Down
4 changes: 4 additions & 0 deletions common/rdm/GroupSizeCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ class StaticGroupTokenCalculator
void Visit(const ola::messaging::UInt8FieldDescriptor*);
void Visit(const ola::messaging::UInt16FieldDescriptor*);
void Visit(const ola::messaging::UInt32FieldDescriptor*);
void Visit(const ola::messaging::UInt64FieldDescriptor*);
void Visit(const ola::messaging::Int8FieldDescriptor*);
void Visit(const ola::messaging::Int16FieldDescriptor*);
void Visit(const ola::messaging::Int32FieldDescriptor*);
void Visit(const ola::messaging::Int64FieldDescriptor*);
void Visit(const ola::messaging::FieldDescriptorGroup*);
void PostVisit(const ola::messaging::FieldDescriptorGroup*);

Expand Down Expand Up @@ -106,9 +108,11 @@ class GroupSizeCalculator: public ola::messaging::FieldDescriptorVisitor {
void Visit(const ola::messaging::UInt8FieldDescriptor*);
void Visit(const ola::messaging::UInt16FieldDescriptor*);
void Visit(const ola::messaging::UInt32FieldDescriptor*);
void Visit(const ola::messaging::UInt64FieldDescriptor*);
void Visit(const ola::messaging::Int8FieldDescriptor*);
void Visit(const ola::messaging::Int16FieldDescriptor*);
void Visit(const ola::messaging::Int32FieldDescriptor*);
void Visit(const ola::messaging::Int64FieldDescriptor*);
void Visit(const ola::messaging::FieldDescriptorGroup*);
void PostVisit(const ola::messaging::FieldDescriptorGroup*);

Expand Down
Loading

0 comments on commit 5bd4759

Please sign in to comment.