diff --git a/engine/src/flutter/shell/platform/common/client_wrapper/encodable_value_unittests.cc b/engine/src/flutter/shell/platform/common/client_wrapper/encodable_value_unittests.cc index 2a4ec5c671..5c1616f0df 100644 --- a/engine/src/flutter/shell/platform/common/client_wrapper/encodable_value_unittests.cc +++ b/engine/src/flutter/shell/platform/common/client_wrapper/encodable_value_unittests.cc @@ -283,4 +283,51 @@ TEST(EncodableValueTest, DeepCopy) { EXPECT_EQ(std::get(innermost_map[EncodableValue("a")]), "b"); } +// Simple class for testing custom encodable values +class TestCustomValue { + public: + TestCustomValue() : x_(0), y_(0) {} + TestCustomValue(int x, int y) : x_(x), y_(y) {} + ~TestCustomValue() = default; + + int x() const { return x_; } + int y() const { return y_; } + + private: + int x_; + int y_; +}; + +TEST(EncodableValueTest, TypeIndexesCorrect) { + // Null + EXPECT_EQ(EncodableValue().index(), 0u); + // Bool + EXPECT_EQ(EncodableValue(true).index(), 1u); + // Int32 + EXPECT_EQ(EncodableValue(100).index(), 2u); + // Int64 + EXPECT_EQ(EncodableValue(INT64_C(100)).index(), 3u); + // Double + EXPECT_EQ(EncodableValue(7.0).index(), 4u); + // String + EXPECT_EQ(EncodableValue("one").index(), 5u); + // ByteList + EXPECT_EQ(EncodableValue(std::vector()).index(), 6u); + // IntList + EXPECT_EQ(EncodableValue(std::vector()).index(), 7u); + // LongList + EXPECT_EQ(EncodableValue(std::vector()).index(), 8u); + // DoubleList + EXPECT_EQ(EncodableValue(std::vector()).index(), 9u); + // List + EXPECT_EQ(EncodableValue(EncodableList()).index(), 10u); + // Map + EXPECT_EQ(EncodableValue(EncodableMap()).index(), 11u); + // Custom type + TestCustomValue customValue; + EXPECT_EQ(((EncodableValue)CustomEncodableValue(customValue)).index(), 12u); + // FloatList + EXPECT_EQ(EncodableValue(std::vector()).index(), 13u); +} // namespace flutter + } // namespace flutter diff --git a/engine/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h b/engine/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h index 297c544b44..4998554e74 100644 --- a/engine/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h +++ b/engine/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h @@ -110,8 +110,8 @@ using EncodableValueVariant = std::variant, EncodableList, EncodableMap, - std::vector, - CustomEncodableValue>; + CustomEncodableValue, + std::vector>; } // namespace internal // An object that can contain any value or collection type supported by @@ -156,10 +156,10 @@ using EncodableValueVariant = std::variant -> Uint8List // std::vector -> Int32List // std::vector -> Int64List +// std::vector -> Float32List // std::vector -> Float64List // EncodableList -> List // EncodableMap -> Map -// std::vector -> Float32List class EncodableValue : public internal::EncodableValueVariant { public: // Rely on std::variant for most of the constructors/operators. diff --git a/engine/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc b/engine/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc index a7725088dd..e37e4a18dc 100644 --- a/engine/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc +++ b/engine/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc @@ -71,7 +71,7 @@ EncodedType EncodedTypeForValue(const EncodableValue& value) { return EncodedType::kList; case 11: return EncodedType::kMap; - case 12: + case 13: return EncodedType::kFloat32List; } assert(false); @@ -153,15 +153,15 @@ void StandardCodecSerializer::WriteValue(const EncodableValue& value, } break; } - case 12: { - WriteVector(std::get>(value), stream); - break; - } - case 13: + case 12: std::cerr << "Unhandled custom type in StandardCodecSerializer::WriteValue. " << "Custom types require codec extensions." << std::endl; break; + case 13: { + WriteVector(std::get>(value), stream); + break; + } } } diff --git a/engine/src/flutter/shell/platform/common/client_wrapper/standard_message_codec_unittests.cc b/engine/src/flutter/shell/platform/common/client_wrapper/standard_message_codec_unittests.cc index a516fe24ff..c7a92427df 100644 --- a/engine/src/flutter/shell/platform/common/client_wrapper/standard_message_codec_unittests.cc +++ b/engine/src/flutter/shell/platform/common/client_wrapper/standard_message_codec_unittests.cc @@ -175,7 +175,7 @@ TEST(StandardMessageCodec, CanEncodeAndDecodeInt64Array) { CheckEncodeDecode(value, bytes); } -TEST(StandradMessageCodec, CanEncodeAndDecodeFloat32Array) { +TEST(StandardMessageCodec, CanEncodeAndDecodeFloat32Array) { std::vector bytes = {0x0e, 0x02, 0x00, 0x00, 0xd8, 0x0f, 0x49, 0x40, 0x00, 0x00, 0x7a, 0x44}; EncodableValue value(std::vector{3.1415920257568359375f, 1000.0f});