blob: 896283886c58af95e177b27bf7f69491a03ba530 [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "encodable_value.h"
#include "message_codec.h"
#include "standard_codec_serializer.h"
namespace standard_message_codec {
// A binary message encoding/decoding mechanism for communications to/from the
// Flutter engine via message channels.
class StandardMessageCodec : public MessageCodec<EncodableValue> {
// Returns an instance of the codec, optionally using a custom serializer to
// add support for more types.
// If provided, |serializer| must be long-lived. If no serializer is provided,
// the default will be used.
// The instance returned for a given |serializer| will be shared, and
// any instance returned from this will be long-lived, and can be safely
// passed to, e.g., channel constructors.
static const StandardMessageCodec& GetInstance(
const StandardCodecSerializer* serializer = nullptr);
// Prevent copying.
StandardMessageCodec(StandardMessageCodec const&) = delete;
StandardMessageCodec& operator=(StandardMessageCodec const&) = delete;
// |flutter::MessageCodec|
std::unique_ptr<EncodableValue> DecodeMessageInternal(const uint8_t* binary_message,
const size_t message_size) const override;
// |flutter::MessageCodec|
std::unique_ptr<std::vector<uint8_t>> EncodeMessageInternal(
const EncodableValue& message) const override;
// Instances should be obtained via GetInstance.
explicit StandardMessageCodec(const StandardCodecSerializer* serializer);
const StandardCodecSerializer* serializer_;
} // namespace standard_message_codec