Flutter Engine
fl_binary_codec.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_codec.h"
6 
7 #include <gmodule.h>
8 
9 G_DEFINE_QUARK(fl_binary_codec_error_quark, fl_binary_codec_error)
10 
12  FlMessageCodec parent_instance;
13 };
14 
15 G_DEFINE_TYPE(FlBinaryCodec, fl_binary_codec, fl_message_codec_get_type())
16 
17 // Implements FlMessageCodec::encode_message.
18 static GBytes* fl_binary_codec_encode_message(FlMessageCodec* codec,
19  FlValue* value,
20  GError** error) {
22  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
24  "Only uint8[] values supported");
25  return nullptr;
26  }
27 
28  return g_bytes_new(fl_value_get_uint8_list(value),
29  fl_value_get_length(value));
30 }
31 
32 // Implements FlMessageCodec::decode_message.
33 static FlValue* fl_binary_codec_decode_message(FlMessageCodec* codec,
34  GBytes* message,
35  GError** error) {
36  gsize data_length;
37  const uint8_t* data =
38  static_cast<const uint8_t*>(g_bytes_get_data(message, &data_length));
39  return fl_value_new_uint8_list(data, data_length);
40 }
41 
42 static void fl_binary_codec_class_init(FlBinaryCodecClass* klass) {
43  FL_MESSAGE_CODEC_CLASS(klass)->encode_message =
45  FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
47 }
48 
49 static void fl_binary_codec_init(FlBinaryCodec* self) {}
50 
51 G_MODULE_EXPORT FlBinaryCodec* fl_binary_codec_new() {
52  return static_cast<FlBinaryCodec*>(
53  g_object_new(fl_binary_codec_get_type(), nullptr));
54 }
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition: fl_value.cc:263
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
static void fl_binary_codec_init(FlBinaryCodec *self)
FlMessageCodec parent_instance
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) struct _FlBinaryMessenger
#define FL_MESSAGE_CODEC_ERROR
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:603
static GBytes * fl_binary_codec_encode_message(FlMessageCodec *codec, FlValue *value, GError **error)
G_MODULE_EXPORT FlBinaryCodec * fl_binary_codec_new()
uint8_t value
static FlValue * fl_binary_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
G_MODULE_EXPORT GType fl_message_codec_get_type()
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
static void fl_binary_codec_class_init(FlBinaryCodecClass *klass)
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:631