diff --git a/common/messaging/DescriptorTest.cpp b/common/messaging/DescriptorTest.cpp index 37cce39c97..ea86378dbd 100644 --- a/common/messaging/DescriptorTest.cpp +++ b/common/messaging/DescriptorTest.cpp @@ -33,6 +33,10 @@ 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; @@ -40,6 +44,7 @@ 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 { @@ -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(10), - uint8_descriptor.Multiplier()); + uint8_descriptor.Multiplier()); OLA_ASSERT_TRUE(uint8_descriptor.FixedSize()); OLA_ASSERT_TRUE(uint8_descriptor.LimitedSize()); @@ -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(-1), - uint8_descriptor2.Multiplier()); + uint8_descriptor2.Multiplier()); OLA_ASSERT_TRUE(uint8_descriptor2.FixedSize()); OLA_ASSERT_TRUE(uint8_descriptor2.LimitedSize()); @@ -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(10), - uint16_descriptor.Multiplier()); + uint16_descriptor.Multiplier()); OLA_ASSERT_TRUE(uint16_descriptor.FixedSize()); OLA_ASSERT_TRUE(uint16_descriptor.LimitedSize()); @@ -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(-1), - uint16_descriptor2.Multiplier()); + uint16_descriptor2.Multiplier()); OLA_ASSERT_TRUE(uint16_descriptor2.FixedSize()); OLA_ASSERT_TRUE(uint16_descriptor2.LimitedSize()); @@ -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(10), - uint32_descriptor.Multiplier()); + uint32_descriptor.Multiplier()); OLA_ASSERT_TRUE(uint32_descriptor.FixedSize()); OLA_ASSERT_TRUE(uint32_descriptor.LimitedSize()); @@ -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(-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(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(-1), + uint64_descriptor2.Multiplier()); + OLA_ASSERT_TRUE(uint64_descriptor2.FixedSize()); + OLA_ASSERT_TRUE(uint64_descriptor2.LimitedSize()); } diff --git a/common/messaging/MessagePrinter.cpp b/common/messaging/MessagePrinter.cpp index 7123c15782..86286bcd6e 100644 --- a/common/messaging/MessagePrinter.cpp +++ b/common/messaging/MessagePrinter.cpp @@ -113,6 +113,15 @@ void GenericMessagePrinter::Visit(const BasicMessageField *message) { } +void GenericMessagePrinter::Visit(const BasicMessageField *message) { + const UInt64FieldDescriptor *descriptor = message->GetDescriptor(); + AppendUInt(descriptor->Name(), + message->Value(), + descriptor->LookupValue(message->Value()), + descriptor->Multiplier()); +} + + void GenericMessagePrinter::Visit(const BasicMessageField *message) { const Int8FieldDescriptor *descriptor = message->GetDescriptor(); AppendInt(descriptor->Name(), @@ -140,6 +149,15 @@ void GenericMessagePrinter::Visit(const BasicMessageField *message) { } +void GenericMessagePrinter::Visit(const BasicMessageField *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; @@ -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) << ": "; @@ -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) << ": "; diff --git a/common/messaging/MessagePrinterTest.cpp b/common/messaging/MessagePrinterTest.cpp index 5484370aa0..03179d971b 100644 --- a/common/messaging/MessagePrinterTest.cpp +++ b/common/messaging/MessagePrinterTest.cpp @@ -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; @@ -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 fields; @@ -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)); } diff --git a/common/messaging/SchemaPrinter.cpp b/common/messaging/SchemaPrinter.cpp index 62b07146b2..bd8b436c9d 100644 --- a/common/messaging/SchemaPrinter.cpp +++ b/common/messaging/SchemaPrinter.cpp @@ -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()); @@ -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; diff --git a/common/messaging/SchemaPrinterTest.cpp b/common/messaging/SchemaPrinterTest.cpp index 0eda1f5a36..f3bcd4ada1 100644 --- a/common/messaging/SchemaPrinterTest.cpp +++ b/common/messaging/SchemaPrinterTest.cpp @@ -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; @@ -235,5 +237,8 @@ void SchemaPrinterTest::testIntervalTypes() { OLA_ASSERT_EQ( string("Count: int32: (-70000, 82560)\n"), GenerateIntervalString(-70000, 82560)); + OLA_ASSERT_EQ( + string("Count: int64: (-7000000000, 8256123456)\n"), + GenerateIntervalString(-7000000000, 8256123456)); } diff --git a/common/network/NetworkUtils.cpp b/common/network/NetworkUtils.cpp index 4815c6c8f6..fa1511e23e 100644 --- a/common/network/NetworkUtils.cpp +++ b/common/network/NetworkUtils.cpp @@ -106,6 +106,17 @@ inline bool IsBigEndian() { #endif // defined(HAVE_ENDIAN_H) && defined(__BIG_ENDIAN) } +inline uint64_t ByteSwap64(uint64_t value) { + return ((value & 0x00000000000000ff) << 56) | + ((value & 0x000000000000ff00) << 40) | + ((value & 0x0000000000ff0000) << 24) | + ((value & 0x00000000ff000000) << 8) | + ((value & 0x000000ff00000000) >> 8) | + ((value & 0x0000ff0000000000) >> 24) | + ((value & 0x00ff000000000000) >> 40) | + ((value & 0xff00000000000000) >> 56); +} + inline uint32_t ByteSwap32(uint32_t value) { return ((value & 0x000000ff) << 24) | ((value & 0x0000ff00) << 8) | @@ -148,6 +159,14 @@ uint32_t NetworkToHost(uint32_t value) { return ntohl(value); } +uint64_t NetworkToHost(uint64_t value) { +#ifdef HAVE_ENDIAN_H + return be64toh(value); +#else +#error "No be64toh for NetworkToHost, please report this." +#endif // HAVE_ENDIAN_H +} + int16_t NetworkToHost(int16_t value) { return ntohs(value); } @@ -156,6 +175,14 @@ int32_t NetworkToHost(int32_t value) { return ntohl(value); } +int64_t NetworkToHost(int64_t value) { +#ifdef HAVE_ENDIAN_H + return be64toh(value); +#else +#error "No be64toh for NetworkToHost, please report this." +#endif // HAVE_ENDIAN_H +} + uint16_t HostToNetwork(uint16_t value) { return htons(value); } @@ -172,6 +199,22 @@ int32_t HostToNetwork(int32_t value) { return htonl(value); } +uint64_t HostToNetwork(uint64_t value) { +#ifdef HAVE_ENDIAN_H + return htobe64(value); +#else +#error "No htobe64 for HostToNetwork, please report this." +#endif // HAVE_ENDIAN_H +} + +int64_t HostToNetwork(int64_t value) { +#ifdef HAVE_ENDIAN_H + return htobe64(value); +#else +#error "No htobe64 for HostToNetwork, please report this." +#endif // HAVE_ENDIAN_H +} + uint16_t HostToLittleEndian(uint16_t value) { if (IsBigEndian()) { return ByteSwap16(value); @@ -204,6 +247,22 @@ int32_t HostToLittleEndian(int32_t value) { } } +uint64_t HostToLittleEndian(uint64_t value) { + if (IsBigEndian()) { + return ByteSwap64(value); + } else { + return value; + } +} + +int64_t HostToLittleEndian(int64_t value) { + if (IsBigEndian()) { + return ByteSwap64(value); + } else { + return value; + } +} + uint16_t LittleEndianToHost(uint16_t value) { if (IsBigEndian()) { return ByteSwap16(value); @@ -239,6 +298,24 @@ int32_t LittleEndianToHost(int32_t value) { } } + +uint64_t LittleEndianToHost(uint64_t value) { + if (IsBigEndian()) { + return ByteSwap64(value); + } else { + return value; + } +} + + +int64_t LittleEndianToHost(int64_t value) { + if (IsBigEndian()) { + return ByteSwap64(value); + } else { + return value; + } +} + string HostnameFromFQDN(const string &fqdn) { string::size_type first_dot = fqdn.find_first_of("."); if (first_dot == string::npos) { diff --git a/common/network/NetworkUtilsTest.cpp b/common/network/NetworkUtilsTest.cpp index 86b70d8d72..cd037af3b0 100644 --- a/common/network/NetworkUtilsTest.cpp +++ b/common/network/NetworkUtilsTest.cpp @@ -88,6 +88,7 @@ void NetworkUtilsTest::tearDown() { #endif // _WIN32 } + /* * Check that we can convert to/from network byte order */ @@ -101,6 +102,9 @@ void NetworkUtilsTest::testToFromNetwork() { uint32_t v3 = 0x01020304; OLA_ASSERT_EQ(v3, NetworkToHost(HostToNetwork(v3))); + + uint64_t v4 = 0x0102030405060708; + OLA_ASSERT_EQ(v4, NetworkToHost(HostToNetwork(v4))); } @@ -118,15 +122,21 @@ void NetworkUtilsTest::testToFromLittleEndian() { uint32_t v3 = 0x01020304; OLA_ASSERT_EQ(v3, LittleEndianToHost(HostToLittleEndian(v3))); - int8_t v4 = -10; - OLA_ASSERT_EQ(v4, HostToLittleEndian(v4)); + uint64_t v4 = 0x0102030405060708; OLA_ASSERT_EQ(v4, LittleEndianToHost(HostToLittleEndian(v4))); - int16_t v5 = -0x0102; + int8_t v5 = -10; + OLA_ASSERT_EQ(v5, HostToLittleEndian(v5)); OLA_ASSERT_EQ(v5, LittleEndianToHost(HostToLittleEndian(v5))); - int32_t v6 = -0x01020304; + int16_t v6 = -0x0102; OLA_ASSERT_EQ(v6, LittleEndianToHost(HostToLittleEndian(v6))); + + int32_t v7 = -0x01020304; + OLA_ASSERT_EQ(v7, LittleEndianToHost(HostToLittleEndian(v7))); + + int64_t v8 = -0x0102030405060708; + OLA_ASSERT_EQ(v8, LittleEndianToHost(HostToLittleEndian(v8))); } diff --git a/common/rdm/DescriptorConsistencyChecker.cpp b/common/rdm/DescriptorConsistencyChecker.cpp index e947d6d14e..4d9ef68b9b 100644 --- a/common/rdm/DescriptorConsistencyChecker.cpp +++ b/common/rdm/DescriptorConsistencyChecker.cpp @@ -79,6 +79,11 @@ void DescriptorConsistencyChecker::Visit( } +void DescriptorConsistencyChecker::Visit( + const ola::messaging::UInt64FieldDescriptor*) { +} + + void DescriptorConsistencyChecker::Visit( const ola::messaging::Int8FieldDescriptor*) { } @@ -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()) diff --git a/common/rdm/DescriptorConsistencyChecker.h b/common/rdm/DescriptorConsistencyChecker.h index a1ed804841..711453196f 100644 --- a/common/rdm/DescriptorConsistencyChecker.h +++ b/common/rdm/DescriptorConsistencyChecker.h @@ -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*); diff --git a/common/rdm/GroupSizeCalculator.cpp b/common/rdm/GroupSizeCalculator.cpp index 18eb334a0f..b6ad1d288d 100644 --- a/common/rdm/GroupSizeCalculator.cpp +++ b/common/rdm/GroupSizeCalculator.cpp @@ -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); @@ -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); @@ -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()++; @@ -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); diff --git a/common/rdm/GroupSizeCalculator.h b/common/rdm/GroupSizeCalculator.h index c15ec07cda..23d2c5d2b0 100644 --- a/common/rdm/GroupSizeCalculator.h +++ b/common/rdm/GroupSizeCalculator.h @@ -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*); @@ -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*); diff --git a/common/rdm/GroupSizeCalculatorTest.cpp b/common/rdm/GroupSizeCalculatorTest.cpp index c86dd1dc18..3717e0fa02 100644 --- a/common/rdm/GroupSizeCalculatorTest.cpp +++ b/common/rdm/GroupSizeCalculatorTest.cpp @@ -37,12 +37,14 @@ using ola::messaging::IPV4FieldDescriptor; using ola::messaging::IPV6FieldDescriptor; using ola::messaging::Int16FieldDescriptor; using ola::messaging::Int32FieldDescriptor; +using ola::messaging::Int64FieldDescriptor; using ola::messaging::Int8FieldDescriptor; 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; using ola::rdm::GroupSizeCalculator; using std::vector; @@ -82,9 +84,11 @@ void GroupSizeCalculatorTest::testSimpleCases() { fields.push_back(new UInt8FieldDescriptor("uint8")); fields.push_back(new UInt16FieldDescriptor("uint16")); fields.push_back(new UInt32FieldDescriptor("uint32")); + fields.push_back(new UInt64FieldDescriptor("uint64")); fields.push_back(new Int8FieldDescriptor("int8")); fields.push_back(new Int16FieldDescriptor("int16")); fields.push_back(new Int32FieldDescriptor("int32")); + fields.push_back(new Int64FieldDescriptor("int64")); fields.push_back(new StringFieldDescriptor("string", 0, 32)); fields.push_back(new IPV4FieldDescriptor("address")); fields.push_back(new IPV6FieldDescriptor("addressv6")); @@ -95,7 +99,7 @@ void GroupSizeCalculatorTest::testSimpleCases() { unsigned int token_count, group_repeat_count; OLA_ASSERT_TRUE( m_static_calculator.CalculateTokensRequired(&descriptor, &token_count)); - OLA_ASSERT_EQ(12u, token_count); // Actual token count + OLA_ASSERT_EQ(14u, token_count); // Actual token count OLA_ASSERT_EQ( @@ -108,21 +112,21 @@ void GroupSizeCalculatorTest::testSimpleCases() { OLA_ASSERT_EQ( GroupSizeCalculator::INSUFFICIENT_TOKENS, m_calculator.CalculateGroupSize( - 11, // Actual token count - 1 + 13, // Actual token count - 1 &descriptor, &group_repeat_count)); OLA_ASSERT_EQ( GroupSizeCalculator::NO_VARIABLE_GROUPS, m_calculator.CalculateGroupSize( - 12, // Actual token count + 14, // Actual token count &descriptor, &group_repeat_count)); OLA_ASSERT_EQ( GroupSizeCalculator::EXTRA_TOKENS, m_calculator.CalculateGroupSize( - 13, // Actual token count + 1 + 15, // Actual token count + 1 &descriptor, &group_repeat_count)); } diff --git a/common/rdm/MessageDeserializer.cpp b/common/rdm/MessageDeserializer.cpp index a3e6ec3360..fe4745c8ee 100644 --- a/common/rdm/MessageDeserializer.cpp +++ b/common/rdm/MessageDeserializer.cpp @@ -214,6 +214,12 @@ void MessageDeserializer::Visit( } +void MessageDeserializer::Visit( + const ola::messaging::IntegerFieldDescriptor *descriptor) { + IntVisit(descriptor); +} + + void MessageDeserializer::Visit( const ola::messaging::IntegerFieldDescriptor *descriptor) { IntVisit(descriptor); @@ -232,6 +238,12 @@ void MessageDeserializer::Visit( } +void MessageDeserializer::Visit( + const ola::messaging::IntegerFieldDescriptor *descriptor) { + IntVisit(descriptor); +} + + /** * @brief Visit a group field */ diff --git a/common/rdm/MessageDeserializerTest.cpp b/common/rdm/MessageDeserializerTest.cpp index d674b2c2f8..30e218031c 100644 --- a/common/rdm/MessageDeserializerTest.cpp +++ b/common/rdm/MessageDeserializerTest.cpp @@ -39,6 +39,7 @@ 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; @@ -48,6 +49,7 @@ using ola::messaging::GenericMessagePrinter; using ola::messaging::StringFieldDescriptor; using ola::messaging::UInt16FieldDescriptor; using ola::messaging::UInt32FieldDescriptor; +using ola::messaging::UInt64FieldDescriptor; using ola::messaging::UInt8FieldDescriptor; using ola::messaging::UIDFieldDescriptor; using ola::rdm::MessageDeserializer; @@ -130,12 +132,17 @@ void MessageDeserializerTest::testSimpleBigEndian() { fields.push_back(new Int16FieldDescriptor("int16")); fields.push_back(new UInt32FieldDescriptor("uint32")); fields.push_back(new Int32FieldDescriptor("int32")); + fields.push_back(new UInt64FieldDescriptor("uint64")); + fields.push_back(new Int64FieldDescriptor("int64")); Descriptor descriptor("Test Descriptor", fields); // now setup the data const uint8_t big_endian_data[] = { 0, 10, 246, 1, 0x2c, 0xfe, 10, - 1, 2, 3, 4, 0xfe, 6, 7, 8}; + 1, 2, 3, 4, 0xfe, 6, 7, 8, + 0, 0, 0, 17, 237, 142, 194, 0, + 255, 255, 255, 238, 18, 113, 62, 0 +}; // try to inflate with no data OLA_ASSERT_NULL(m_deserializer.InflateMessage( @@ -161,11 +168,12 @@ void MessageDeserializerTest::testSimpleBigEndian() { big_endian_data, sizeof(big_endian_data))); OLA_ASSERT_NOT_NULL(message.get()); - OLA_ASSERT_EQ(7u, message->FieldCount()); + OLA_ASSERT_EQ(9u, message->FieldCount()); const string expected = ( "bool: false\nuint8: 10\nint8: -10\nuint16: 300\nint16: -502\n" - "uint32: 16909060\nint32: -33159416\n"); + "uint32: 16909060\nint32: -33159416\n" + "uint64: 77000000000\nint64: -77000000000\n"); OLA_ASSERT_EQ(expected, m_printer.AsString(message.get())); } @@ -183,12 +191,17 @@ void MessageDeserializerTest::testSimpleLittleEndian() { fields.push_back(new Int16FieldDescriptor("int16", true)); fields.push_back(new UInt32FieldDescriptor("uint32", true)); fields.push_back(new Int32FieldDescriptor("int32", true)); + fields.push_back(new UInt64FieldDescriptor("uint64", true)); + fields.push_back(new Int64FieldDescriptor("int64", true)); Descriptor descriptor("Test Descriptor", fields); // now setup the data const uint8_t little_endian_data[] = { 1, 10, 246, 0x2c, 1, 10, 0xfe, - 4, 3, 2, 1, 8, 7, 6, 0xfe}; + 4, 3, 2, 1, 8, 7, 6, 0xfe, + 0, 194, 142, 237, 17, 0, 0, 0, + 0, 62, 113, 18, 238, 255, 255, 255 +}; // try to inflate with no data OLA_ASSERT_NULL(m_deserializer.InflateMessage( @@ -214,11 +227,12 @@ void MessageDeserializerTest::testSimpleLittleEndian() { little_endian_data, sizeof(little_endian_data))); OLA_ASSERT_NOT_NULL(message.get()); - OLA_ASSERT_EQ(7u, message->FieldCount()); + OLA_ASSERT_EQ(9u, message->FieldCount()); const string expected = ( "bool: true\nuint8: 10\nint8: -10\nuint16: 300\nint16: -502\n" - "uint32: 16909060\nint32: -33159416\n"); + "uint32: 16909060\nint32: -33159416\n" + "uint64: 77000000000\nint64: -77000000000\n"); OLA_ASSERT_EQ(expected, m_printer.AsString(message.get())); } diff --git a/common/rdm/MessageSerializer.cpp b/common/rdm/MessageSerializer.cpp index 8181157642..fa59738c10 100644 --- a/common/rdm/MessageSerializer.cpp +++ b/common/rdm/MessageSerializer.cpp @@ -137,6 +137,12 @@ void MessageSerializer::Visit( } +void MessageSerializer::Visit( + const ola::messaging::BasicMessageField *message) { + IntVisit(message); +} + + void MessageSerializer::Visit( const ola::messaging::BasicMessageField *message) { IntVisit(message); @@ -155,6 +161,12 @@ void MessageSerializer::Visit( } +void MessageSerializer::Visit( + const ola::messaging::BasicMessageField *message) { + IntVisit(message); +} + + void MessageSerializer::Visit( const ola::messaging::GroupMessageField *message) { (void) message; diff --git a/common/rdm/MessageSerializerTest.cpp b/common/rdm/MessageSerializerTest.cpp index 2eca076471..cc07156ac6 100644 --- a/common/rdm/MessageSerializerTest.cpp +++ b/common/rdm/MessageSerializerTest.cpp @@ -39,6 +39,7 @@ 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; @@ -47,6 +48,7 @@ using ola::messaging::Message; using ola::messaging::StringFieldDescriptor; using ola::messaging::UInt16FieldDescriptor; using ola::messaging::UInt32FieldDescriptor; +using ola::messaging::UInt64FieldDescriptor; using ola::messaging::UInt8FieldDescriptor; using ola::messaging::UIDFieldDescriptor; using ola::rdm::StringMessageBuilder; @@ -111,6 +113,8 @@ void MessageSerializerTest::testSimple() { fields.push_back(new Int16FieldDescriptor("int16")); fields.push_back(new UInt32FieldDescriptor("uint32")); fields.push_back(new Int32FieldDescriptor("int32")); + fields.push_back(new UInt64FieldDescriptor("uint64")); + fields.push_back(new Int64FieldDescriptor("int64")); fields.push_back(new IPV4FieldDescriptor("ip")); fields.push_back(new IPV6FieldDescriptor("ipv6")); fields.push_back(new MACFieldDescriptor("mac")); @@ -126,6 +130,8 @@ void MessageSerializerTest::testSimple() { inputs.push_back("-400"); inputs.push_back("66000"); inputs.push_back("-66000"); + inputs.push_back("77000000000"); + inputs.push_back("-77000000000"); inputs.push_back("10.0.0.1"); inputs.push_back("::ffff:192.168.0.1"); inputs.push_back("01:23:45:67:89:ab"); @@ -140,11 +146,13 @@ void MessageSerializerTest::testSimple() { const uint8_t *data = serializer.SerializeMessage(message.get(), &packed_length); OLA_ASSERT_NOT_NULL(data); - OLA_ASSERT_EQ(44u, packed_length); + OLA_ASSERT_EQ(60u, packed_length); uint8_t expected[] = { 1, 1, 253, 1, 44, 254, 112, 0, 1, 1, 208, 255, 254, 254, 48, + 0, 0, 0, 17, 237, 142, 194, 0, + 255, 255, 255, 238, 18, 113, 62, 0, 10, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 192, 168, 0, 1, 1, 35, 69, 103, 137, 171, @@ -227,6 +235,8 @@ void MessageSerializerTest::testLittleEndian() { fields.push_back(new Int16FieldDescriptor("int16", true)); fields.push_back(new UInt32FieldDescriptor("uint32", true)); fields.push_back(new Int32FieldDescriptor("int32", true)); + fields.push_back(new UInt64FieldDescriptor("uint64", true)); + fields.push_back(new Int64FieldDescriptor("int64", true)); Descriptor descriptor("Test Descriptor", fields); // now setup the inputs @@ -237,6 +247,8 @@ void MessageSerializerTest::testLittleEndian() { inputs.push_back("-400"); inputs.push_back("66000"); inputs.push_back("-66000"); + inputs.push_back("77000000000"); + inputs.push_back("-77000000000"); auto_ptr message(BuildMessage(descriptor, inputs)); @@ -247,11 +259,14 @@ void MessageSerializerTest::testLittleEndian() { const uint8_t *data = serializer.SerializeMessage(message.get(), &packed_length); OLA_ASSERT_NOT_NULL(data); - OLA_ASSERT_EQ(14u, packed_length); + OLA_ASSERT_EQ(30u, packed_length); uint8_t expected[] = { 1, 253, 44, 1, 112, 254, - 208, 1, 1, 0, 48, 254, 254, 255}; + 208, 1, 1, 0, 48, 254, 254, 255, + 0, 194, 142, 237, 17, 0, 0, 0, + 0, 62, 113, 18, 238, 255, 255, 255 +}; OLA_ASSERT_DATA_EQUALS(expected, sizeof(expected), data, packed_length); } diff --git a/common/rdm/PidStoreLoader.cpp b/common/rdm/PidStoreLoader.cpp index adf5594e6b..c1424260d9 100644 --- a/common/rdm/PidStoreLoader.cpp +++ b/common/rdm/PidStoreLoader.cpp @@ -448,6 +448,11 @@ const FieldDescriptor *PidStoreLoader::FieldToFieldDescriptor( IntegerFieldToFieldDescriptor( field); break; + case ola::rdm::pid::UINT64: + descriptor = + IntegerFieldToFieldDescriptor( + field); + break; case ola::rdm::pid::INT8: descriptor = IntegerFieldToFieldDescriptor( @@ -463,6 +468,11 @@ const FieldDescriptor *PidStoreLoader::FieldToFieldDescriptor( IntegerFieldToFieldDescriptor( field); break; + case ola::rdm::pid::INT64: + descriptor = + IntegerFieldToFieldDescriptor( + field); + break; case ola::rdm::pid::STRING: descriptor = StringFieldToFieldDescriptor(field); break; diff --git a/common/rdm/Pids.proto b/common/rdm/Pids.proto index 19010f7ad8..9c3fdcbe03 100644 --- a/common/rdm/Pids.proto +++ b/common/rdm/Pids.proto @@ -43,6 +43,8 @@ enum FieldType { UID = 11; MAC = 12; IPV6 = 13; + UINT64 = 14; + INT64 = 15; } // A value which has a label applied diff --git a/common/rdm/RDMAPI.cpp b/common/rdm/RDMAPI.cpp index 89d3c525c5..481eba8301 100644 --- a/common/rdm/RDMAPI.cpp +++ b/common/rdm/RDMAPI.cpp @@ -33,6 +33,7 @@ #include "ola/rdm/RDMAPIImplInterface.h" #include "ola/rdm/RDMEnums.h" #include "ola/rdm/UID.h" +#include "ola/strings/Format.h" namespace ola { namespace rdm { @@ -45,6 +46,7 @@ using ola::SingleUseCallback2; using ola::SingleUseCallback4; using ola::network::HostToNetwork; using ola::network::NetworkToHost; +using ola::strings::IntToString; /* diff --git a/common/rdm/StringMessageBuilder.cpp b/common/rdm/StringMessageBuilder.cpp index da6fad314e..00daaac9aa 100644 --- a/common/rdm/StringMessageBuilder.cpp +++ b/common/rdm/StringMessageBuilder.cpp @@ -294,6 +294,12 @@ void StringMessageBuilder::Visit( } +void StringMessageBuilder::Visit( + const ola::messaging::UInt64FieldDescriptor *descriptor) { + VisitInt(descriptor); +} + + void StringMessageBuilder::Visit( const ola::messaging::Int8FieldDescriptor *descriptor) { VisitInt(descriptor); @@ -312,6 +318,12 @@ void StringMessageBuilder::Visit( } +void StringMessageBuilder::Visit( + const ola::messaging::Int64FieldDescriptor *descriptor) { + VisitInt(descriptor); +} + + /** * Visit a group */ diff --git a/common/rdm/StringMessageBuilderTest.cpp b/common/rdm/StringMessageBuilderTest.cpp index 6ee21f16e8..187cf64af1 100644 --- a/common/rdm/StringMessageBuilderTest.cpp +++ b/common/rdm/StringMessageBuilderTest.cpp @@ -41,12 +41,14 @@ using ola::messaging::IPV4FieldDescriptor; using ola::messaging::IPV6FieldDescriptor; using ola::messaging::Int16FieldDescriptor; using ola::messaging::Int32FieldDescriptor; +using ola::messaging::Int64FieldDescriptor; using ola::messaging::Int8FieldDescriptor; using ola::messaging::MACFieldDescriptor; using ola::messaging::Message; using ola::messaging::StringFieldDescriptor; using ola::messaging::UInt16FieldDescriptor; using ola::messaging::UInt32FieldDescriptor; +using ola::messaging::UInt64FieldDescriptor; using ola::messaging::UInt8FieldDescriptor; using ola::rdm::StringMessageBuilder; using std::auto_ptr; @@ -142,9 +144,11 @@ void StringBuilderTest::testSimpleBuilder() { fields.push_back(new UInt8FieldDescriptor("uint8")); fields.push_back(new UInt16FieldDescriptor("uint16")); fields.push_back(new UInt32FieldDescriptor("uint32")); + fields.push_back(new UInt64FieldDescriptor("uint64")); fields.push_back(new Int8FieldDescriptor("int8")); fields.push_back(new Int16FieldDescriptor("int16")); fields.push_back(new Int32FieldDescriptor("int32")); + fields.push_back(new Int64FieldDescriptor("int64")); fields.push_back(new StringFieldDescriptor("string", 0, 32)); fields.push_back(new UInt16FieldDescriptor("hex uint16")); Descriptor descriptor("Test Descriptor", fields); @@ -163,9 +167,11 @@ void StringBuilderTest::testSimpleBuilder() { inputs.push_back("255"); inputs.push_back("300"); inputs.push_back("66000"); + inputs.push_back("77000000000"); inputs.push_back("-128"); inputs.push_back("-300"); inputs.push_back("-66000"); + inputs.push_back("-77000000000"); inputs.push_back("foo"); inputs.push_back("0x400"); @@ -180,8 +186,8 @@ void StringBuilderTest::testSimpleBuilder() { "bool1: true\nbool2: false\nbool3: true\nbool4: false\nbool5: true\n" "bool6: false\nip1: 10.0.0.1\nipv61: ::ffff:192.168.0.1\n" "mac1: 01:23:45:67:89:ab\nuint8: 255\nuint16: 300\nuint32: 66000\n" - "int8: -128\nint16: -300\nint32: -66000\nstring: foo\n" - "hex uint16: 1024\n"); + "uint64: 77000000000\nint8: -128\nint16: -300\nint32: -66000\n" + "int64: -77000000000\nstring: foo\nhex uint16: 1024\n"); OLA_ASSERT_EQ(expected, m_printer.AsString(message.get())); } diff --git a/common/rdm/VariableFieldSizeCalculator.cpp b/common/rdm/VariableFieldSizeCalculator.cpp index f30c55f4ed..2487d10cce 100644 --- a/common/rdm/VariableFieldSizeCalculator.cpp +++ b/common/rdm/VariableFieldSizeCalculator.cpp @@ -169,6 +169,12 @@ void VariableFieldSizeCalculator::Visit( } +void VariableFieldSizeCalculator::Visit( + const ola::messaging::UInt64FieldDescriptor *descriptor) { + m_fixed_size_sum += descriptor->MaxSize(); +} + + void VariableFieldSizeCalculator::Visit( const ola::messaging::Int8FieldDescriptor *descriptor) { m_fixed_size_sum += descriptor->MaxSize(); @@ -187,6 +193,12 @@ void VariableFieldSizeCalculator::Visit( } +void VariableFieldSizeCalculator::Visit( + const ola::messaging::Int64FieldDescriptor *descriptor) { + m_fixed_size_sum += descriptor->MaxSize(); +} + + void VariableFieldSizeCalculator::Visit( const ola::messaging::FieldDescriptorGroup *descriptor) { if (descriptor->FixedSize()) diff --git a/common/rdm/VariableFieldSizeCalculator.h b/common/rdm/VariableFieldSizeCalculator.h index 4e224b0afa..d4ef1e0973 100644 --- a/common/rdm/VariableFieldSizeCalculator.h +++ b/common/rdm/VariableFieldSizeCalculator.h @@ -70,9 +70,11 @@ class VariableFieldSizeCalculator 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*) {} diff --git a/common/strings/Format.cpp b/common/strings/Format.cpp index 46f9382b86..565b0a8ebf 100644 --- a/common/strings/Format.cpp +++ b/common/strings/Format.cpp @@ -31,13 +31,13 @@ using std::endl; using std::ostringstream; using std::string; -string IntToString(int i) { +string IntToString(int64_t i) { ostringstream str; str << i; return str.str(); } -string IntToString(unsigned int i) { +string IntToString(uint64_t i) { ostringstream str; str << i; return str.str(); diff --git a/common/utils/StringUtils.cpp b/common/utils/StringUtils.cpp index bc27b623fb..9068743bf6 100644 --- a/common/utils/StringUtils.cpp +++ b/common/utils/StringUtils.cpp @@ -152,14 +152,15 @@ bool StringToBoolTolerant(const string &value, bool *output) { return false; } -bool StringToInt(const string &value, unsigned int *output, bool strict) { +bool StringToInt(const string &value, uint64_t *output, bool strict) { if (value.empty()) { return false; } char *end_ptr; errno = 0; - long long l = strtoll(value.data(), &end_ptr, 10); // NOLINT(runtime/int) - if (l < 0 || (l == 0 && errno != 0)) { + unsigned long long l = strtoull( // NOLINT(runtime/int) + value.data(), &end_ptr, 10); + if (l == 0 && errno != 0) { return false; } if (value == end_ptr) { @@ -168,15 +169,27 @@ bool StringToInt(const string &value, unsigned int *output, bool strict) { if (strict && *end_ptr != 0) { return false; } - if (l > static_cast(UINT32_MAX)) { // NOLINT(runtime/int) + if (l > static_cast(UINT64_MAX)) { // NOLINT(runtime/int) + return false; + } + *output = static_cast(l); + return true; +} + +bool StringToInt(const string &value, unsigned int *output, bool strict) { + uint64_t v; + if (!StringToInt(value, &v, strict)) { + return false; + } + if (v > UINT32_MAX) { return false; } - *output = static_cast(l); + *output = static_cast(v); return true; } bool StringToInt(const string &value, uint16_t *output, bool strict) { - unsigned int v; + uint64_t v; if (!StringToInt(value, &v, strict)) { return false; } @@ -188,7 +201,7 @@ bool StringToInt(const string &value, uint16_t *output, bool strict) { } bool StringToInt(const string &value, uint8_t *output, bool strict) { - unsigned int v; + uint64_t v; if (!StringToInt(value, &v, strict)) { return false; } @@ -199,7 +212,7 @@ bool StringToInt(const string &value, uint8_t *output, bool strict) { return true; } -bool StringToInt(const string &value, int *output, bool strict) { +bool StringToInt(const string &value, int64_t *output, bool strict) { if (value.empty()) { return false; } @@ -215,15 +228,27 @@ bool StringToInt(const string &value, int *output, bool strict) { if (strict && *end_ptr != 0) { return false; } - if (l < INT32_MIN || l > INT32_MAX) { + if (l < INT64_MIN || l > INT64_MAX) { return false; } - *output = static_cast(l); + *output = static_cast(l); + return true; +} + +bool StringToInt(const string &value, int *output, bool strict) { + int64_t v; + if (!StringToInt(value, &v, strict)) { + return false; + } + if (v < INT32_MIN || v > INT32_MAX) { + return false; + } + *output = static_cast(v); return true; } bool StringToInt(const string &value, int16_t *output, bool strict) { - int v; + int64_t v; if (!StringToInt(value, &v, strict)) { return false; } @@ -235,7 +260,7 @@ bool StringToInt(const string &value, int16_t *output, bool strict) { } bool StringToInt(const string &value, int8_t *output, bool strict) { - int v; + int64_t v; if (!StringToInt(value, &v, strict)) { return false; } @@ -364,6 +389,19 @@ bool HexStringToInt(const string &value, uint32_t *output) { return true; } +bool HexStringToInt(const string &value, uint64_t *output) { + if (value.empty()) { + return false; + } + + size_t found = value.find_first_not_of("ABCDEFabcdef0123456789"); + if (found != string::npos) { + return false; + } + *output = strtoull(value.data(), NULL, 16); + return true; +} + bool HexStringToInt(const string &value, int8_t *output) { int32_t temp; if (!HexStringToInt(value, &temp)) { @@ -401,6 +439,19 @@ bool HexStringToInt(const string &value, int32_t *output) { return true; } +bool HexStringToInt(const string &value, int64_t *output) { + if (value.empty()) { + return false; + } + + size_t found = value.find_first_not_of("ABCDEFabcdef0123456789"); + if (found != string::npos) { + return false; + } + *output = strtoll(value.data(), NULL, 16); + return true; +} + void ToLower(string *s) { std::transform(s->begin(), s->end(), s->begin(), std::ptr_fun(std::tolower)); diff --git a/common/utils/StringUtilsTest.cpp b/common/utils/StringUtilsTest.cpp index 189427dacd..be32cbf2c6 100644 --- a/common/utils/StringUtilsTest.cpp +++ b/common/utils/StringUtilsTest.cpp @@ -351,6 +351,7 @@ void StringUtilsTest::testIntToHexString() { OLA_ASSERT_EQ(string("0x0001"), IntToHexString((uint16_t)0x0001)); OLA_ASSERT_EQ(string("0xabcd"), IntToHexString((uint16_t)0xABCD)); OLA_ASSERT_EQ(string("0xdeadbeef"), IntToHexString((uint32_t)0xDEADBEEF)); + // Deliberately no IntToHexString(uint64_t) or test as its deprecated unsigned int i = 0x42; OLA_ASSERT_EQ(string("0x00000042"), IntToHexString(i)); @@ -381,6 +382,10 @@ void StringUtilsTest::testIntToHexString() { OLA_ASSERT_EQ(string("0xdeadbeef"), str.str()); str.str(""); + str << ToHex((uint64_t)0xDEADBEEFFEEDFACE); + OLA_ASSERT_EQ(string("0xdeadbeeffeedface"), str.str()); + str.str(""); + str << ToHex(i); OLA_ASSERT_EQ(string("0x00000042"), str.str()); str.str(""); @@ -552,6 +557,9 @@ void StringUtilsTest::testStringToUInt() { OLA_ASSERT_EQ(65537u, value); OLA_ASSERT_TRUE(StringToInt("4294967295", &value)); OLA_ASSERT_EQ(4294967295U, value); + uint64_t value2; + OLA_ASSERT_TRUE(StringToInt("77000000000", &value2)); + OLA_ASSERT_EQ((uint64_t) 77000000000, value2); OLA_ASSERT_FALSE(StringToInt("4294967296", &value)); OLA_ASSERT_FALSE(StringToInt("foo", &value)); @@ -569,7 +577,9 @@ void StringUtilsTest::testStringToUIntOrDefault() { OLA_ASSERT_EQ(0u, StringToIntOrDefault("0", 42u)); OLA_ASSERT_EQ(1u, StringToIntOrDefault("1", 42u)); OLA_ASSERT_EQ(65537u, StringToIntOrDefault("65537", 42u)); - OLA_ASSERT_EQ(4294967295U, StringToIntOrDefault("4294967295", 42u)); + OLA_ASSERT_EQ(4294967295U, StringToIntOrDefault("4294967295", 42U)); + OLA_ASSERT_EQ((uint64_t) 77000000000, + StringToIntOrDefault("77000000000", (uint64_t) 42)); OLA_ASSERT_EQ(42u, StringToIntOrDefault("4294967296", 42u)); OLA_ASSERT_EQ(42u, StringToIntOrDefault("foo", 42u)); @@ -648,63 +658,35 @@ void StringUtilsTest::testHexStringToInt() { OLA_ASSERT_FALSE(HexStringToInt("zfff", &value2)); OLA_ASSERT_FALSE(HexStringToInt("0xf", &value2)); - // int8_t - int8_t value3; - OLA_ASSERT_FALSE(HexStringToInt("", &value3)); - OLA_ASSERT_FALSE(HexStringToInt("-1", &value3)); - - OLA_ASSERT_TRUE(HexStringToInt("0", &value3)); - OLA_ASSERT_EQ((int8_t) 0, value3); - OLA_ASSERT_TRUE(HexStringToInt("1", &value3)); - OLA_ASSERT_EQ((int8_t) 1, value3); - OLA_ASSERT_TRUE(HexStringToInt("a", &value3)); - OLA_ASSERT_EQ((int8_t) 10, value3); - OLA_ASSERT_TRUE(HexStringToInt("f", &value3)); - OLA_ASSERT_EQ((int8_t) 15, value3); - OLA_ASSERT_TRUE(HexStringToInt("7f", &value3)); - OLA_ASSERT_EQ((int8_t) 127, value3); - OLA_ASSERT_TRUE(HexStringToInt("a1", &value3)); - OLA_ASSERT_EQ((int8_t) -95, value3); - OLA_ASSERT_TRUE(HexStringToInt("80", &value3)); - OLA_ASSERT_EQ((int8_t) -128, value3); - OLA_ASSERT_TRUE(HexStringToInt("ff", &value3)); - OLA_ASSERT_EQ((int8_t) -1, value3); - - OLA_ASSERT_FALSE(HexStringToInt("ffff", &value3)); - OLA_ASSERT_FALSE(HexStringToInt("fff0", &value3)); - OLA_ASSERT_FALSE(HexStringToInt("ffffff", &value3)); - OLA_ASSERT_FALSE(HexStringToInt("ffffffff", &value3)); - OLA_ASSERT_FALSE(HexStringToInt("ef123456", &value3)); - OLA_ASSERT_FALSE(HexStringToInt("fz", &value3)); - OLA_ASSERT_FALSE(HexStringToInt("zfff", &value3)); - OLA_ASSERT_FALSE(HexStringToInt("0xf", &value3)); + // uint64_t + uint64_t value3; + OLA_ASSERT_TRUE(HexStringToInt("11ed8ec200", &value3)); + OLA_ASSERT_EQ((uint64_t) 77000000000, value3); - // int16_t - int16_t value4; + // int8_t + int8_t value4; OLA_ASSERT_FALSE(HexStringToInt("", &value4)); OLA_ASSERT_FALSE(HexStringToInt("-1", &value4)); OLA_ASSERT_TRUE(HexStringToInt("0", &value4)); - OLA_ASSERT_EQ((int16_t) 0, value4); + OLA_ASSERT_EQ((int8_t) 0, value4); OLA_ASSERT_TRUE(HexStringToInt("1", &value4)); - OLA_ASSERT_EQ((int16_t) 1, value4); + OLA_ASSERT_EQ((int8_t) 1, value4); OLA_ASSERT_TRUE(HexStringToInt("a", &value4)); - OLA_ASSERT_EQ((int16_t) 10, value4); + OLA_ASSERT_EQ((int8_t) 10, value4); OLA_ASSERT_TRUE(HexStringToInt("f", &value4)); - OLA_ASSERT_EQ((int16_t) 15, value4); + OLA_ASSERT_EQ((int8_t) 15, value4); + OLA_ASSERT_TRUE(HexStringToInt("7f", &value4)); + OLA_ASSERT_EQ((int8_t) 127, value4); OLA_ASSERT_TRUE(HexStringToInt("a1", &value4)); - OLA_ASSERT_EQ((int16_t) 161, value4); + OLA_ASSERT_EQ((int8_t) -95, value4); + OLA_ASSERT_TRUE(HexStringToInt("80", &value4)); + OLA_ASSERT_EQ((int8_t) -128, value4); OLA_ASSERT_TRUE(HexStringToInt("ff", &value4)); - OLA_ASSERT_EQ((int16_t) 255, value4); - OLA_ASSERT_TRUE(HexStringToInt("7fff", &value4)); - OLA_ASSERT_EQ((int16_t) 32767, value4); - OLA_ASSERT_TRUE(HexStringToInt("ffff", &value4)); - OLA_ASSERT_EQ((int16_t) -1, value4); - OLA_ASSERT_TRUE(HexStringToInt("fff0", &value4)); - OLA_ASSERT_EQ((int16_t) -16, value4); - OLA_ASSERT_TRUE(HexStringToInt("8000", &value4)); - OLA_ASSERT_EQ((int16_t) -32768, value4); + OLA_ASSERT_EQ((int8_t) -1, value4); + OLA_ASSERT_FALSE(HexStringToInt("ffff", &value4)); + OLA_ASSERT_FALSE(HexStringToInt("fff0", &value4)); OLA_ASSERT_FALSE(HexStringToInt("ffffff", &value4)); OLA_ASSERT_FALSE(HexStringToInt("ffffffff", &value4)); OLA_ASSERT_FALSE(HexStringToInt("ef123456", &value4)); @@ -712,33 +694,66 @@ void StringUtilsTest::testHexStringToInt() { OLA_ASSERT_FALSE(HexStringToInt("zfff", &value4)); OLA_ASSERT_FALSE(HexStringToInt("0xf", &value4)); - // int32 - int32_t value5; + // int16_t + int16_t value5; OLA_ASSERT_FALSE(HexStringToInt("", &value5)); OLA_ASSERT_FALSE(HexStringToInt("-1", &value5)); OLA_ASSERT_TRUE(HexStringToInt("0", &value5)); - OLA_ASSERT_EQ((int32_t) 0, value5); + OLA_ASSERT_EQ((int16_t) 0, value5); OLA_ASSERT_TRUE(HexStringToInt("1", &value5)); - OLA_ASSERT_EQ((int32_t) 1, value5); + OLA_ASSERT_EQ((int16_t) 1, value5); OLA_ASSERT_TRUE(HexStringToInt("a", &value5)); - OLA_ASSERT_EQ((int32_t) 10, value5); + OLA_ASSERT_EQ((int16_t) 10, value5); OLA_ASSERT_TRUE(HexStringToInt("f", &value5)); - OLA_ASSERT_EQ((int32_t) 15, value5); + OLA_ASSERT_EQ((int16_t) 15, value5); OLA_ASSERT_TRUE(HexStringToInt("a1", &value5)); - OLA_ASSERT_EQ((int32_t) 161, value5); + OLA_ASSERT_EQ((int16_t) 161, value5); OLA_ASSERT_TRUE(HexStringToInt("ff", &value5)); - OLA_ASSERT_EQ((int32_t) 255, value5); + OLA_ASSERT_EQ((int16_t) 255, value5); OLA_ASSERT_TRUE(HexStringToInt("7fff", &value5)); - OLA_ASSERT_EQ((int32_t) 32767, value5); + OLA_ASSERT_EQ((int16_t) 32767, value5); OLA_ASSERT_TRUE(HexStringToInt("ffff", &value5)); - OLA_ASSERT_EQ((int32_t) 65535, value5); - OLA_ASSERT_TRUE(HexStringToInt("ffffffff", &value5)); - OLA_ASSERT_EQ((int32_t) -1, value5); - OLA_ASSERT_TRUE(HexStringToInt("fffffff0", &value5)); - OLA_ASSERT_EQ((int32_t) -16, value5); - OLA_ASSERT_TRUE(HexStringToInt("80000000", &value5)); - OLA_ASSERT_EQ((int32_t) -2147483647 - 1, value5); + OLA_ASSERT_EQ((int16_t) -1, value5); + OLA_ASSERT_TRUE(HexStringToInt("fff0", &value5)); + OLA_ASSERT_EQ((int16_t) -16, value5); + OLA_ASSERT_TRUE(HexStringToInt("8000", &value5)); + OLA_ASSERT_EQ((int16_t) -32768, value5); + + OLA_ASSERT_FALSE(HexStringToInt("ffffff", &value5)); + OLA_ASSERT_FALSE(HexStringToInt("ffffffff", &value5)); + OLA_ASSERT_FALSE(HexStringToInt("ef123456", &value5)); + OLA_ASSERT_FALSE(HexStringToInt("fz", &value5)); + OLA_ASSERT_FALSE(HexStringToInt("zfff", &value5)); + OLA_ASSERT_FALSE(HexStringToInt("0xf", &value5)); + + // int32 + int32_t value6; + OLA_ASSERT_FALSE(HexStringToInt("", &value6)); + OLA_ASSERT_FALSE(HexStringToInt("-1", &value6)); + + OLA_ASSERT_TRUE(HexStringToInt("0", &value6)); + OLA_ASSERT_EQ((int32_t) 0, value6); + OLA_ASSERT_TRUE(HexStringToInt("1", &value6)); + OLA_ASSERT_EQ((int32_t) 1, value6); + OLA_ASSERT_TRUE(HexStringToInt("a", &value6)); + OLA_ASSERT_EQ((int32_t) 10, value6); + OLA_ASSERT_TRUE(HexStringToInt("f", &value6)); + OLA_ASSERT_EQ((int32_t) 15, value6); + OLA_ASSERT_TRUE(HexStringToInt("a1", &value6)); + OLA_ASSERT_EQ((int32_t) 161, value6); + OLA_ASSERT_TRUE(HexStringToInt("ff", &value6)); + OLA_ASSERT_EQ((int32_t) 255, value6); + OLA_ASSERT_TRUE(HexStringToInt("7fff", &value6)); + OLA_ASSERT_EQ((int32_t) 32767, value6); + OLA_ASSERT_TRUE(HexStringToInt("ffff", &value6)); + OLA_ASSERT_EQ((int32_t) 65535, value6); + OLA_ASSERT_TRUE(HexStringToInt("ffffffff", &value6)); + OLA_ASSERT_EQ((int32_t) -1, value6); + OLA_ASSERT_TRUE(HexStringToInt("fffffff0", &value6)); + OLA_ASSERT_EQ((int32_t) -16, value6); + OLA_ASSERT_TRUE(HexStringToInt("80000000", &value6)); + OLA_ASSERT_EQ((int32_t) -2147483647 - 1, value6); } diff --git a/include/ola/StringUtils.h b/include/ola/StringUtils.h index 3ae2d4b504..c1bd47ca07 100644 --- a/include/ola/StringUtils.h +++ b/include/ola/StringUtils.h @@ -183,6 +183,8 @@ inline std::string IntToHexString(uint32_t i) { return str.str(); } +// Deliberately no IntToHexString(uint64_t) as its deprecated + /** * @brief Escape a string with \\ . * @@ -257,6 +259,18 @@ bool StringToBool(const std::string &value, bool *output); */ bool StringToBoolTolerant(const std::string &value, bool *output); +/** + * @brief Convert a string to a uint64_t. + * @param[in] value the string to convert + * @param[out] output a pointer where the value will be stored. + * @param[in] strict this controls if trailing characters produce an error. + * @returns true if the value was converted, false if the string was not an int + * or the value was too large / small for the type. + */ +bool StringToInt(const std::string &value, + uint64_t *output, + bool strict = false); + /** * @brief Convert a string to a unsigned int. * @param[in] value the string to convert @@ -295,6 +309,19 @@ bool StringToInt(const std::string &value, uint8_t *output, bool strict = false); +/** + * @brief Convert a string to a int64_t. + * @param[in] value the string to convert + * @param[out] output a pointer where the value will be stored. + * @param[in] strict this controls if trailing characters produce an error. + * @returns true if the value was converted, false if the string was not an int + * or the value was too large / small for the type. + * @sa StringToInt. + */ +bool StringToInt(const std::string &value, + int64_t *output, + bool strict = false); + /** * @brief Convert a string to a int. * @param[in] value the string to convert @@ -380,6 +407,17 @@ bool HexStringToInt(const std::string &value, uint16_t *output); */ bool HexStringToInt(const std::string &value, uint32_t *output); +/** + * @brief Convert a hex string to a uint64_t. + * + * The string can contain upper or lower case hex characters. + * @param[in] value the string to convert. + * @param[out] output a pointer to the store the converted value in. + * @returns true if the value was converted, false if the string was not an int + * or the value was too large / small for the type. + */ +bool HexStringToInt(const std::string &value, uint64_t *output); + /** * @brief Convert a hex string to a int8_t. * @param[in] value the string to convert. @@ -413,6 +451,17 @@ bool HexStringToInt(const std::string &value, int16_t *output); */ bool HexStringToInt(const std::string &value, int32_t *output); +/** + * @brief Convert a hex string to a int64_t. + * + * The string can contain upper or lower case hex characters. + * @param[in] value the string to convert. + * @param[out] output a pointer to the store the converted value in. + * @returns true if the value was converted, false if the string was not an int + * or the value was too large / small for the type. + */ +bool HexStringToInt(const std::string &value, int64_t *output); + /** * @brief Convert a string to lower case. * @param s the string to convert to lower case. diff --git a/include/ola/messaging/Descriptor.h b/include/ola/messaging/Descriptor.h index f997a9a00d..68bd4c8890 100644 --- a/include/ola/messaging/Descriptor.h +++ b/include/ola/messaging/Descriptor.h @@ -287,9 +287,11 @@ class IntegerFieldDescriptor: public FieldDescriptor { typedef IntegerFieldDescriptor UInt8FieldDescriptor; typedef IntegerFieldDescriptor UInt16FieldDescriptor; typedef IntegerFieldDescriptor UInt32FieldDescriptor; +typedef IntegerFieldDescriptor UInt64FieldDescriptor; typedef IntegerFieldDescriptor Int8FieldDescriptor; typedef IntegerFieldDescriptor Int16FieldDescriptor; typedef IntegerFieldDescriptor Int32FieldDescriptor; +typedef IntegerFieldDescriptor Int64FieldDescriptor; /** diff --git a/include/ola/messaging/DescriptorVisitor.h b/include/ola/messaging/DescriptorVisitor.h index 5b5820d588..37ae615f1d 100644 --- a/include/ola/messaging/DescriptorVisitor.h +++ b/include/ola/messaging/DescriptorVisitor.h @@ -57,9 +57,11 @@ class FieldDescriptorVisitor { virtual void Visit(const IntegerFieldDescriptor*) = 0; virtual void Visit(const IntegerFieldDescriptor*) = 0; virtual void Visit(const IntegerFieldDescriptor*) = 0; + virtual void Visit(const IntegerFieldDescriptor*) = 0; virtual void Visit(const IntegerFieldDescriptor*) = 0; virtual void Visit(const IntegerFieldDescriptor*) = 0; virtual void Visit(const IntegerFieldDescriptor*) = 0; + virtual void Visit(const IntegerFieldDescriptor*) = 0; virtual void Visit(const FieldDescriptorGroup*) = 0; virtual void PostVisit(const FieldDescriptorGroup*) = 0; }; diff --git a/include/ola/messaging/Message.h b/include/ola/messaging/Message.h index ecc56bd2a2..d12da39f78 100644 --- a/include/ola/messaging/Message.h +++ b/include/ola/messaging/Message.h @@ -258,9 +258,11 @@ class BasicMessageField: public MessageFieldInterface { typedef BasicMessageField UInt8MessageField; typedef BasicMessageField UInt16MessageField; typedef BasicMessageField UInt32MessageField; +typedef BasicMessageField UInt64MessageField; typedef BasicMessageField Int8MessageField; typedef BasicMessageField Int16MessageField; typedef BasicMessageField Int32MessageField; +typedef BasicMessageField Int64MessageField; /** diff --git a/include/ola/messaging/MessagePrinter.h b/include/ola/messaging/MessagePrinter.h index 2f2f363664..c1ee1bd440 100644 --- a/include/ola/messaging/MessagePrinter.h +++ b/include/ola/messaging/MessagePrinter.h @@ -47,9 +47,11 @@ class MessagePrinter: public MessageVisitor { virtual void Visit(const BasicMessageField*) {} virtual void Visit(const BasicMessageField*) {} virtual void Visit(const BasicMessageField*) {} + virtual void Visit(const BasicMessageField*) {} virtual void Visit(const BasicMessageField*) {} virtual void Visit(const BasicMessageField*) {} virtual void Visit(const BasicMessageField*) {} + virtual void Visit(const BasicMessageField*) {} virtual void Visit(const GroupMessageField*) {} virtual void PostVisit(const GroupMessageField*) {} @@ -86,9 +88,11 @@ class GenericMessagePrinter: public MessagePrinter { virtual void Visit(const BasicMessageField*); virtual void Visit(const BasicMessageField*); virtual void Visit(const BasicMessageField*); + virtual void Visit(const BasicMessageField*); virtual void Visit(const BasicMessageField*); virtual void Visit(const BasicMessageField*); virtual void Visit(const BasicMessageField*); + virtual void Visit(const BasicMessageField*); virtual void Visit(const GroupMessageField*); virtual void PostVisit(const GroupMessageField*); @@ -98,11 +102,11 @@ class GenericMessagePrinter: public MessagePrinter { unsigned int m_indent, m_indent_size; void AppendUInt(const std::string &name, - unsigned int value, + uint64_t value, const std::string &label, int8_t multiplier); void AppendInt(const std::string &name, - int value, + int64_t value, const std::string &label, int8_t multiplier); void AppendMultiplier(int8_t multiplier); diff --git a/include/ola/messaging/MessageVisitor.h b/include/ola/messaging/MessageVisitor.h index 81b55ed965..f5cf16d457 100644 --- a/include/ola/messaging/MessageVisitor.h +++ b/include/ola/messaging/MessageVisitor.h @@ -54,9 +54,11 @@ class MessageVisitor { virtual void Visit(const BasicMessageField*) = 0; virtual void Visit(const BasicMessageField*) = 0; virtual void Visit(const BasicMessageField*) = 0; + virtual void Visit(const BasicMessageField*) = 0; virtual void Visit(const BasicMessageField*) = 0; virtual void Visit(const BasicMessageField*) = 0; virtual void Visit(const BasicMessageField*) = 0; + virtual void Visit(const BasicMessageField*) = 0; virtual void Visit(const GroupMessageField*) = 0; virtual void PostVisit(const GroupMessageField*) = 0; }; diff --git a/include/ola/messaging/SchemaPrinter.h b/include/ola/messaging/SchemaPrinter.h index 95aa7c9e6b..0d789a769c 100644 --- a/include/ola/messaging/SchemaPrinter.h +++ b/include/ola/messaging/SchemaPrinter.h @@ -57,9 +57,11 @@ class SchemaPrinter: public FieldDescriptorVisitor { void Visit(const UInt8FieldDescriptor*); void Visit(const UInt16FieldDescriptor*); void Visit(const UInt32FieldDescriptor*); + void Visit(const UInt64FieldDescriptor*); void Visit(const Int8FieldDescriptor*); void Visit(const Int16FieldDescriptor*); void Visit(const Int32FieldDescriptor*); + void Visit(const Int64FieldDescriptor*); void Visit(const FieldDescriptorGroup*); void PostVisit(const FieldDescriptorGroup*); diff --git a/include/ola/messaging/StringMessageBuilder.h b/include/ola/messaging/StringMessageBuilder.h index 12b7273fd3..ab7343d197 100644 --- a/include/ola/messaging/StringMessageBuilder.h +++ b/include/ola/messaging/StringMessageBuilder.h @@ -49,9 +49,11 @@ class StringMessageBuilder: public FieldDescriptorVisitor { void Visit(const IntegerFieldDescriptor*); void Visit(const IntegerFieldDescriptor*); void Visit(const IntegerFieldDescriptor*); + void Visit(const IntegerFieldDescriptor*); void Visit(const IntegerFieldDescriptor*); void Visit(const IntegerFieldDescriptor*); void Visit(const IntegerFieldDescriptor*); + void Visit(const IntegerFieldDescriptor*); void Visit(const FieldDescriptorGroup*); void PostVisit(const FieldDescriptorGroup*); diff --git a/include/ola/network/NetworkUtils.h b/include/ola/network/NetworkUtils.h index d5aaccd47b..1afe2824c1 100644 --- a/include/ola/network/NetworkUtils.h +++ b/include/ola/network/NetworkUtils.h @@ -46,6 +46,11 @@ uint16_t NetworkToHost(uint16_t value); */ uint32_t NetworkToHost(uint32_t value); +/** + * @brief 64-bit unsigned network to host conversion. + */ +uint64_t NetworkToHost(uint64_t value); + /** * @brief 8-bit signed network to host conversion. */ @@ -61,6 +66,11 @@ int16_t NetworkToHost(int16_t value); */ int32_t NetworkToHost(int32_t value); +/** + * @brief 64-bit signed network to host conversion. + */ +int64_t NetworkToHost(int64_t value); + /** * @brief 8-bit unsigned host to network conversion. */ @@ -76,6 +86,11 @@ uint16_t HostToNetwork(uint16_t value); */ uint32_t HostToNetwork(uint32_t value); +/** + * @brief 64-bit unsigned host to network conversion. + */ +uint64_t HostToNetwork(uint64_t value); + /** * @brief 8-bit signed host to network conversion. */ @@ -91,6 +106,11 @@ int16_t HostToNetwork(int16_t value); */ int32_t HostToNetwork(int32_t value); +/** + * @brief 64-bit signed host to network conversion. + */ +int64_t HostToNetwork(int64_t value); + /** * @brief 8-bit unsigned host to little endian conversion. */ @@ -106,6 +126,11 @@ uint16_t HostToLittleEndian(uint16_t value); */ uint32_t HostToLittleEndian(uint32_t value); +/** + * @brief 64-bit unsigned host to little endian conversion. + */ +uint64_t HostToLittleEndian(uint64_t value); + /** * @brief 8-bit signed host to little endian conversion. */ @@ -121,6 +146,11 @@ int16_t HostToLittleEndian(int16_t value); */ int32_t HostToLittleEndian(int32_t value); +/** + * @brief 64-bit signed host to little endian conversion. + */ +int64_t HostToLittleEndian(int64_t value); + /** * @brief 8-bit unsigned little endian to host conversion. */ @@ -136,6 +166,11 @@ uint16_t LittleEndianToHost(uint16_t value); */ uint32_t LittleEndianToHost(uint32_t value); +/** + * @brief 64-bit unsigned little endian to host conversion. + */ +uint64_t LittleEndianToHost(uint64_t value); + /** * @brief 8-bit signed little endian to host conversion. */ @@ -151,6 +186,11 @@ int16_t LittleEndianToHost(int16_t value); */ int32_t LittleEndianToHost(int32_t value); +/** + * @brief 64-bit signed little endian to host conversion. + */ +int64_t LittleEndianToHost(int64_t value); + /** * Convert a FQDN to a hostname * @param fqdn a fully qualified domain name diff --git a/include/ola/rdm/MessageDeserializer.h b/include/ola/rdm/MessageDeserializer.h index 5e320653af..ec75dddf47 100644 --- a/include/ola/rdm/MessageDeserializer.h +++ b/include/ola/rdm/MessageDeserializer.h @@ -64,9 +64,11 @@ class MessageDeserializer: public ola::messaging::FieldDescriptorVisitor { void Visit(const ola::messaging::IntegerFieldDescriptor*); void Visit(const ola::messaging::IntegerFieldDescriptor*); void Visit(const ola::messaging::IntegerFieldDescriptor*); + void Visit(const ola::messaging::IntegerFieldDescriptor*); void Visit(const ola::messaging::IntegerFieldDescriptor*); void Visit(const ola::messaging::IntegerFieldDescriptor*); void Visit(const ola::messaging::IntegerFieldDescriptor*); + void Visit(const ola::messaging::IntegerFieldDescriptor*); void Visit(const ola::messaging::FieldDescriptorGroup*); void PostVisit(const ola::messaging::FieldDescriptorGroup*) {} diff --git a/include/ola/rdm/MessageSerializer.h b/include/ola/rdm/MessageSerializer.h index cf6f51f86e..e0d30c06a6 100644 --- a/include/ola/rdm/MessageSerializer.h +++ b/include/ola/rdm/MessageSerializer.h @@ -55,9 +55,11 @@ class MessageSerializer: public ola::messaging::MessageVisitor { void Visit(const ola::messaging::BasicMessageField*); void Visit(const ola::messaging::BasicMessageField*); void Visit(const ola::messaging::BasicMessageField*); + void Visit(const ola::messaging::BasicMessageField*); void Visit(const ola::messaging::BasicMessageField*); void Visit(const ola::messaging::BasicMessageField*); void Visit(const ola::messaging::BasicMessageField*); + void Visit(const ola::messaging::BasicMessageField*); void Visit(const ola::messaging::GroupMessageField*); void PostVisit(const ola::messaging::GroupMessageField*); diff --git a/include/ola/rdm/StringMessageBuilder.h b/include/ola/rdm/StringMessageBuilder.h index ed2bfbdc49..8d00dd6677 100644 --- a/include/ola/rdm/StringMessageBuilder.h +++ b/include/ola/rdm/StringMessageBuilder.h @@ -69,9 +69,11 @@ class StringMessageBuilder: 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*); diff --git a/include/ola/strings/Format.h b/include/ola/strings/Format.h index 8251b7165e..e4ea77cc59 100644 --- a/include/ola/strings/Format.h +++ b/include/ola/strings/Format.h @@ -43,14 +43,22 @@ namespace strings { * @param i the int to convert * @return the string representation of the int */ -std::string IntToString(int i); +std::string IntToString(int64_t i); /** * @brief Convert an unsigned int to a string. * @param i the unsigned int to convert * @return The string representation of the unsigned int */ -std::string IntToString(unsigned int i); +std::string IntToString(uint64_t i); + +inline std::string IntToString(int i) { + return ola::strings::IntToString(static_cast(i)); +} + +inline std::string IntToString(unsigned int i) { + return ola::strings::IntToString(static_cast(i)); +} /** * @brief Convert a value to a hex string. diff --git a/include/ola/strings/FormatPrivate.h b/include/ola/strings/FormatPrivate.h index d4b6068d6e..804b84d0ad 100644 --- a/include/ola/strings/FormatPrivate.h +++ b/include/ola/strings/FormatPrivate.h @@ -62,6 +62,8 @@ inline uint16_t _HexCast(uint16_t v) { return v; } inline uint16_t _HexCast(int16_t v) { return static_cast(v); } inline uint32_t _HexCast(uint32_t v) { return v; } inline uint32_t _HexCast(int32_t v) { return static_cast(v); } +inline uint64_t _HexCast(uint64_t v) { return v; } +inline uint64_t _HexCast(int64_t v) { return static_cast(v); } } // namespace strings } // namespace ola diff --git a/python/ola/PidStore.py b/python/ola/PidStore.py index 5742b35e92..c1dacbf4de 100644 --- a/python/ola/PidStore.py +++ b/python/ola/PidStore.py @@ -528,6 +528,18 @@ def __init__(self, name, **kwargs): super(UInt32, self).__init__(name, 'I', 0xffffffff, **kwargs) +class Int64(IntAtom): + """An eight-byte signed field.""" + def __init__(self, name, **kwargs): + super(Int64, self).__init__(name, 'q', 0xffffffffffffffff, **kwargs) + + +class UInt64(IntAtom): + """An eight-byte unsigned field.""" + def __init__(self, name, **kwargs): + super(UInt64, self).__init__(name, 'Q', 0xffffffffffffffff, **kwargs) + + class IPV4(IntAtom): """A four-byte IPV4 address.""" def __init__(self, name, **kwargs): @@ -1292,6 +1304,10 @@ def _FieldToAtom(self, field): return Int32(field_name, **args) elif field.type == Pids_pb2.UINT32: return UInt32(field_name, **args) + elif field.type == Pids_pb2.INT64: + return Int64(field_name, **args) + elif field.type == Pids_pb2.UINT64: + return UInt64(field_name, **args) elif field.type == Pids_pb2.IPV4: return IPV4(field_name, **args) elif field.type == Pids_pb2.IPV6: diff --git a/python/ola/PidStoreTest.py b/python/ola/PidStoreTest.py index e09226f1fd..410b557acd 100755 --- a/python/ola/PidStoreTest.py +++ b/python/ola/PidStoreTest.py @@ -176,7 +176,7 @@ def testCmp(self): g1setreq = PidStore.Group("srg", [PidStore.MACAtom("mac"), PidStore.IPV4("ipv4"), PidStore.IPV6Atom("ipv6"), - PidStore.Int8("i32")]) + PidStore.Int8("i8")]) p1b = PidStore.Pid("base", 42, None, None, g1getreq, g1setreq)