Flutter Engine
 
Loading...
Searching...
No Matches
fl_message_codec.h
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#ifndef FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_MESSAGE_CODEC_H_
6#define FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_MESSAGE_CODEC_H_
7
8#if !defined(__FLUTTER_LINUX_INSIDE__) && !defined(FLUTTER_LINUX_COMPILATION)
9#error "Only <flutter_linux/flutter_linux.h> can be included directly."
10#endif
11
12#include <glib-object.h>
13#include <gmodule.h>
14
15#include "fl_value.h"
16
17G_BEGIN_DECLS
18
19/**
20 * FlMessageCodecError:
21 * @FL_MESSAGE_CODEC_ERROR_FAILED: Codec failed due to an unspecified error.
22 * @FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA: Codec ran out of data reading a value.
23 * @FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA: Additional data encountered in
24 * message.
25 * @FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE: Codec encountered an unsupported
26 * #FlValue.
27 *
28 * Errors for #FlMessageCodec objects to set on failures.
29 */
30#define FL_MESSAGE_CODEC_ERROR fl_message_codec_error_quark()
31
38
39G_MODULE_EXPORT
40GQuark fl_message_codec_error_quark(void) G_GNUC_CONST;
41
42G_MODULE_EXPORT
44 fl_message_codec,
45 FL,
46 MESSAGE_CODEC,
47 GObject)
48
49/**
50 * FlMessageCodec:
51 *
52 * #FlMessageCodec is a message encoding/decoding mechanism that operates on
53 * #FlValue objects. Both operations returns errors if the conversion fails.
54 * Such situations should be treated as programming errors.
55 *
56 * #FlMessageCodec matches the MethodCodec class in the Flutter services
57 * library.
58 */
59
60struct _FlMessageCodecClass {
61 GObjectClass parent_class;
62
63 /**
64 * FlMessageCodec::encode_message:
65 * @codec: an #FlMessageCodec.
66 * @message: message to encode or %NULL to encode the null value.
67 * @error: (allow-none): #GError location to store the error occurring, or
68 * %NULL.
69 *
70 * Virtual method to encode a message. A subclass must implement this method.
71 * If the subclass cannot handle the type of @message then it must generate a
72 * FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE error.
73 *
74 * Returns: a binary message or %NULL on error.
75 */
76 GBytes* (*encode_message)(FlMessageCodec* codec,
78 GError** error);
79
80 /**
81 * FlMessageCodec::decode_message:
82 * @codec: an #FlMessageCodec.
83 * @message: binary message to decode.
84 * @error: (allow-none): #GError location to store the error occurring, or
85 * %NULL.
86 *
87 * Virtual method to decode a message. A subclass must implement this method.
88 * If @message is too small then a #FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA error
89 * must be generated. If @message is too large then a
90 * #FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA error must be generated.
91 *
92 * Returns: an #FlValue or %NULL on error.
93 */
94 FlValue* (*decode_message)(FlMessageCodec* codec,
95 GBytes* message,
96 GError** error);
97};
98
99/**
100 * fl_message_codec_encode_message:
101 * @codec: an #FlMessageCodec.
102 * @buffer: buffer to write to.
103 * @message: message to encode or %NULL to encode the null value.
104 * @error: (allow-none): #GError location to store the error occurring, or
105 * %NULL.
106 *
107 * Encodes a message into a binary representation.
108 *
109 * Returns: a binary encoded message or %NULL on error.
110 */
111GBytes* fl_message_codec_encode_message(FlMessageCodec* codec,
113 GError** error);
114
115/**
116 * fl_message_codec_decode_message:
117 * @codec: an #FlMessageCodec.
118 * @message: binary message to decode.
119 * @error: (allow-none): #GError location to store the error occurring, or
120 * %NULL.
121 *
122 * Decodes a message from a binary encoding.
123 *
124 * Returns: an #FlValue or %NULL on error.
125 */
126FlValue* fl_message_codec_decode_message(FlMessageCodec* codec,
127 GBytes* message,
128 GError** error);
129
130G_END_DECLS
131
132#endif // FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_MESSAGE_CODEC_H_
FlMessageCodecError
@ FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
@ FL_MESSAGE_CODEC_ERROR_FAILED
@ FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA
FlValue * fl_message_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
GBytes * fl_message_codec_encode_message(FlMessageCodec *codec, FlValue *message, GError **error)
G_MODULE_EXPORT G_DECLARE_DERIVABLE_TYPE(FlMessageCodec, fl_message_codec, FL, MESSAGE_CODEC, GObject) struct _FlMessageCodecClass
G_MODULE_EXPORT GQuark fl_message_codec_error_quark(void) G_GNUC_CONST
G_BEGIN_DECLS GBytes * message
const uint8_t uint32_t uint32_t GError ** error
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42