Removes unnecessary error message: "Invalid read in StandardCodecByteStreamReader" for cpp BasicMessageChannel (flutter/engine#26956)
This commit is contained in:
@@ -318,6 +318,9 @@ StandardMessageCodec::~StandardMessageCodec() = default;
|
|||||||
std::unique_ptr<EncodableValue> StandardMessageCodec::DecodeMessageInternal(
|
std::unique_ptr<EncodableValue> StandardMessageCodec::DecodeMessageInternal(
|
||||||
const uint8_t* binary_message,
|
const uint8_t* binary_message,
|
||||||
size_t message_size) const {
|
size_t message_size) const {
|
||||||
|
if (!binary_message) {
|
||||||
|
return std::make_unique<EncodableValue>();
|
||||||
|
}
|
||||||
ByteBufferStreamReader stream(binary_message, message_size);
|
ByteBufferStreamReader stream(binary_message, message_size);
|
||||||
return std::make_unique<EncodableValue>(serializer_->ReadValue(&stream));
|
return std::make_unique<EncodableValue>(serializer_->ReadValue(&stream));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,23 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "flutter/shell/platform/common/client_wrapper/testing/test_codec_extensions.h"
|
#include "flutter/shell/platform/common/client_wrapper/testing/test_codec_extensions.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
namespace flutter {
|
namespace flutter {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class MockStandardCodecSerializer : public StandardCodecSerializer {
|
||||||
|
public:
|
||||||
|
MOCK_CONST_METHOD2(WriteValue,
|
||||||
|
void(const EncodableValue& value,
|
||||||
|
ByteStreamWriter* stream));
|
||||||
|
MOCK_CONST_METHOD2(ReadValueOfType,
|
||||||
|
EncodableValue(uint8_t type, ByteStreamReader* stream));
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
// Validates round-trip encoding and decoding of |value|, and checks that the
|
// Validates round-trip encoding and decoding of |value|, and checks that the
|
||||||
// encoded value matches |expected_encoding|.
|
// encoded value matches |expected_encoding|.
|
||||||
//
|
//
|
||||||
@@ -68,6 +81,18 @@ TEST(StandardMessageCodec, CanEncodeAndDecodeNull) {
|
|||||||
CheckEncodeDecode(EncodableValue(), bytes);
|
CheckEncodeDecode(EncodableValue(), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(StandardMessageCodec, CanDecodeEmptyBytesAsNullWithoutCallingSerializer) {
|
||||||
|
std::vector<uint8_t> bytes = {};
|
||||||
|
const MockStandardCodecSerializer serializer;
|
||||||
|
const StandardMessageCodec& codec =
|
||||||
|
StandardMessageCodec::GetInstance(&serializer);
|
||||||
|
|
||||||
|
auto decoded = codec.DecodeMessage(bytes);
|
||||||
|
|
||||||
|
EXPECT_EQ(EncodableValue(), *decoded);
|
||||||
|
EXPECT_CALL(serializer, ReadValueOfType(::testing::_, ::testing::_)).Times(0);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(StandardMessageCodec, CanEncodeAndDecodeTrue) {
|
TEST(StandardMessageCodec, CanEncodeAndDecodeTrue) {
|
||||||
std::vector<uint8_t> bytes = {0x01};
|
std::vector<uint8_t> bytes = {0x01};
|
||||||
CheckEncodeDecode(EncodableValue(true), bytes);
|
CheckEncodeDecode(EncodableValue(true), bytes);
|
||||||
|
|||||||
Reference in New Issue
Block a user