Flutter Engine
fl_message_codec.h File Reference
#include <glib-object.h>
#include "fl_value.h"

Go to the source code of this file.

Macros

#define FL_MESSAGE_CODEC_ERROR   fl_message_codec_error_quark()
 

Enumerations

enum  FlMessageCodecError {
  FL_MESSAGE_CODEC_ERROR_FAILED,
  FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA,
  FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA,
  FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
}
 

Functions

GQuark fl_message_codec_error_quark (void) G_GNUC_CONST
 
 G_DECLARE_DERIVABLE_TYPE (FlMessageCodec, fl_message_codec, FL, MESSAGE_CODEC, GObject) struct _FlMessageCodecClass
 
GBytes * fl_message_codec_encode_message (FlMessageCodec *codec, FlValue *message, GError **error)
 
FlValuefl_message_codec_decode_message (FlMessageCodec *codec, GBytes *message, GError **error)
 

Macro Definition Documentation

◆ FL_MESSAGE_CODEC_ERROR

Enumeration Type Documentation

◆ FlMessageCodecError

Enumerator
FL_MESSAGE_CODEC_ERROR_FAILED 
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA 
FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA 
FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE 

Definition at line 31 of file fl_message_codec.h.

Function Documentation

◆ fl_message_codec_decode_message()

FlValue* fl_message_codec_decode_message ( FlMessageCodec *  codec,
GBytes *  message,
GError **  error 
)

fl_message_codec_decode_message: : an #FlMessageCodec. : binary message to decode. : (allow-none): #GError location to store the error occurring, or NULL.

Decodes a message from a binary encoding.

Returns: an FlValue or NULL on error.

Definition at line 36 of file fl_message_codec.cc.

Referenced by decode_error_value(), decode_message(), fl_basic_message_channel_send_finish(), fl_json_method_codec_decode_method_call(), fl_json_method_codec_decode_response(), G_DECLARE_DERIVABLE_TYPE(), message_cb(), and TEST().

38  {
39  g_return_val_if_fail(FL_IS_MESSAGE_CODEC(self), nullptr);
40  g_return_val_if_fail(message != nullptr, nullptr);
41 
42  return FL_MESSAGE_CODEC_GET_CLASS(self)->decode_message(self, message, error);
43 }
FlMethodResponse GError ** error

◆ fl_message_codec_encode_message()

GBytes* fl_message_codec_encode_message ( FlMessageCodec *  codec,
FlValue message,
GError **  error 
)

fl_message_codec_encode_message: : an #FlMessageCodec. : buffer to write to. : message to encode or NULL to encode the null value. : (allow-none): #GError location to store the error occurring, or NULL.

Encodes a message into a binary representation.

Returns: a binary encoded message or NULL on error.

Definition at line 20 of file fl_message_codec.cc.

References fl_value_new_null().

Referenced by encode_message(), encode_message_error(), fl_basic_message_channel_respond(), fl_basic_message_channel_send(), fl_json_method_codec_encode_error_envelope(), fl_json_method_codec_encode_method_call(), fl_json_method_codec_encode_success_envelope(), G_DECLARE_DERIVABLE_TYPE(), and TEST().

22  {
23  g_return_val_if_fail(FL_IS_MESSAGE_CODEC(self), nullptr);
24 
25  // If the user provided NULL, then make a temporary FlValue object for this to
26  // make it simpler for the subclasses.
27  g_autoptr(FlValue) null_value = nullptr;
28  if (message == nullptr) {
29  null_value = fl_value_new_null();
30  message = null_value;
31  }
32 
33  return FL_MESSAGE_CODEC_GET_CLASS(self)->encode_message(self, message, error);
34 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:222

◆ fl_message_codec_error_quark()

GQuark fl_message_codec_error_quark ( void  )

◆ G_DECLARE_DERIVABLE_TYPE()

G_DECLARE_DERIVABLE_TYPE ( FlMessageCodec  ,
fl_message_codec  ,
FL  ,
MESSAGE_CODEC  ,
GObject   
)

FlMessageCodec:

#FlMessageCodec is a message encoding/decoding mechanism that operates on FlValue objects. Both operations returns errors if the conversion fails. Such situations should be treated as programming errors.

#FlMessageCodec matches the MethodCodec class in the Flutter services library.

FlMessageCodec::encode_message: : A #FlMessageCodec. : message to encode or NULL to encode the null value. : (allow-none): #GError location to store the error occurring, or NULL.

Virtual method to encode a message. A subclass must implement this method. If the subclass cannot handle the type of then it must generate a FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE error.

Returns: a binary message or NULL on error.

FlMessageCodec::decode_message: : an #FlMessageCodec. : binary message to decode. : (allow-none): #GError location to store the error occurring, or NULL.

Virtual method to decode a message. A subclass must implement this method. If is too small then a FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA error must be generated. If is too large then a FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA error must be generated.

Returns: an FlValue or NULL on error.

Definition at line 40 of file fl_message_codec.h.

References error, fl_message_codec_decode_message(), and fl_message_codec_encode_message().

57  {
58  GObjectClass parent_class;
59 
60  /**
61  * FlMessageCodec::encode_message:
62  * @codec: A #FlMessageCodec.
63  * @message: message to encode or %NULL to encode the null value.
64  * @error: (allow-none): #GError location to store the error occurring, or
65  * %NULL.
66  *
67  * Virtual method to encode a message. A subclass must implement this method.
68  * If the subclass cannot handle the type of @message then it must generate a
69  * FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE error.
70  *
71  * Returns: a binary message or %NULL on error.
72  */
73  GBytes* (*encode_message)(FlMessageCodec* codec,
74  FlValue* message,
75  GError** error);
76 
77  /**
78  * FlMessageCodec::decode_message:
79  * @codec: an #FlMessageCodec.
80  * @message: binary message to decode.
81  * @error: (allow-none): #GError location to store the error occurring, or
82  * %NULL.
83  *
84  * Virtual method to decode a message. A subclass must implement this method.
85  * If @message is too small then a #FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA error
86  * must be generated. If @message is too large then a
87  * #FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA error must be generated.
88  *
89  * Returns: an #FlValue or %NULL on error.
90  */
91  FlValue* (*decode_message)(FlMessageCodec* codec,
92  GBytes* message,
93  GError** error);
94 };
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error