| Flutter Linux Embedder |

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
11 struct _FlBinaryCodec {
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) {
21 if (fl_value_get_type(value) != FL_VALUE_TYPE_UINT8_LIST) {
22 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
23 FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE,
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 =
44 fl_binary_codec_encode_message;
45 FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
46 fl_binary_codec_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_DEFINE_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)
Definition: fl_basic_message_channel.cc:37
fl_binary_codec_new
G_MODULE_EXPORT FlBinaryCodec * fl_binary_codec_new()
Definition: fl_binary_codec.cc:51
fl_binary_codec_decode_message
static FlValue * fl_binary_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
Definition: fl_binary_codec.cc:33
fl_binary_codec_init
static void fl_binary_codec_init(FlBinaryCodec *self)
Definition: fl_binary_codec.cc:49
fl_binary_codec_class_init
static void fl_binary_codec_class_init(FlBinaryCodecClass *klass)
Definition: fl_binary_codec.cc:42
fl_binary_codec_encode_message
static GBytes * fl_binary_codec_encode_message(FlMessageCodec *codec, FlValue *value, GError **error)
Definition: fl_binary_codec.cc:18
fl_binary_codec.h
G_DEFINE_QUARK
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
Definition: fl_message_codec.h:36
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_value_get_uint8_list
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:689
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_new_uint8_list
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition: fl_value.cc:292
fl_value_get_length
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:724
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
FL_VALUE_TYPE_UINT8_LIST
@ FL_VALUE_TYPE_UINT8_LIST
Definition: fl_value.h:69
_FlBinaryCodec
Definition: fl_binary_codec.cc:11
_FlBinaryCodec::parent_instance
FlMessageCodec parent_instance
Definition: fl_binary_codec.cc:12