Skip to content

Commit

Permalink
Removes unnecessary error message: "Invalid read in StandardCodecByte…
Browse files Browse the repository at this point in the history
…StreamReader" for cpp BasicMessageChannel (flutter#26956)
  • Loading branch information
HakkyuKim authored Jul 22, 2021
1 parent c13fdb8 commit 39f9a27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shell/platform/common/client_wrapper/standard_codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ StandardMessageCodec::~StandardMessageCodec() = default;
std::unique_ptr<EncodableValue> StandardMessageCodec::DecodeMessageInternal(
const uint8_t* binary_message,
size_t message_size) const {
if (!binary_message) {
return std::make_unique<EncodableValue>();
}
ByteBufferStreamReader stream(binary_message, message_size);
return std::make_unique<EncodableValue>(serializer_->ReadValue(&stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@
#include <vector>

#include "flutter/shell/platform/common/client_wrapper/testing/test_codec_extensions.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

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
// encoded value matches |expected_encoding|.
//
Expand Down Expand Up @@ -68,6 +81,18 @@ TEST(StandardMessageCodec, CanEncodeAndDecodeNull) {
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) {
std::vector<uint8_t> bytes = {0x01};
CheckEncodeDecode(EncodableValue(true), bytes);
Expand Down

0 comments on commit 39f9a27

Please sign in to comment.