Flutter Engine
FlValueHandler Struct Reference

Public Member Functions

 FlValueHandler ()
 
 ~FlValueHandler ()
 
FlValueget_head ()
 
void push (FlValue *value)
 
void pop ()
 
bool add (FlValue *value)
 
bool Null ()
 
bool Bool (bool b)
 
bool Int (int i)
 
bool Uint (unsigned i)
 
bool Int64 (int64_t i)
 
bool Uint64 (uint64_t i)
 
bool Double (double d)
 
bool RawNumber (const char *str, rapidjson::SizeType length, bool copy)
 
bool String (const char *str, rapidjson::SizeType length, bool copy)
 
bool StartObject ()
 
bool Key (const char *str, rapidjson::SizeType length, bool copy)
 
bool EndObject (rapidjson::SizeType memberCount)
 
bool StartArray ()
 
bool EndArray (rapidjson::SizeType elementCount)
 

Public Attributes

GPtrArray * stack
 
FlValuekey
 
GError * error
 

Detailed Description

Definition at line 124 of file fl_json_message_codec.cc.

Constructor & Destructor Documentation

◆ FlValueHandler()

FlValueHandler::FlValueHandler ( )
inline

Definition at line 129 of file fl_json_message_codec.cc.

References fl_value_unref().

129  {
130  stack = g_ptr_array_new_with_free_func(
131  reinterpret_cast<GDestroyNotify>(fl_value_unref));
132  key = nullptr;
133  error = nullptr;
134  }
G_MODULE_EXPORT void fl_value_unref(FlValue *self)
Definition: fl_value.cc:341

◆ ~FlValueHandler()

FlValueHandler::~FlValueHandler ( )
inline

Definition at line 136 of file fl_json_message_codec.cc.

References fl_value_unref().

136  {
137  g_ptr_array_unref(stack);
138  if (key != nullptr) {
140  }
141  if (error != nullptr) {
142  g_error_free(error);
143  }
144  }
G_MODULE_EXPORT void fl_value_unref(FlValue *self)
Definition: fl_value.cc:341

Member Function Documentation

◆ add()

bool FlValueHandler::add ( FlValue value)
inline

Definition at line 161 of file fl_json_message_codec.cc.

References FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_value_append(), fl_value_get_type(), fl_value_ref(), fl_value_set_take(), FL_VALUE_TYPE_LIST, FL_VALUE_TYPE_MAP, get_head(), push(), and value.

Referenced by Bool(), Double(), Int(), Int64(), Null(), StartArray(), StartObject(), String(), Uint(), and Uint64().

161  {
162  g_autoptr(FlValue) owned_value = value;
163  FlValue* head = get_head();
164  if (head == nullptr) {
165  push(owned_value);
166  } else if (fl_value_get_type(head) == FL_VALUE_TYPE_LIST) {
167  fl_value_append(head, owned_value);
168  } else if (fl_value_get_type(head) == FL_VALUE_TYPE_MAP) {
169  fl_value_set_take(head, key, fl_value_ref(owned_value));
170  key = nullptr;
171  } else {
173  "Can't add value to non container");
174  return false;
175  }
176 
177  if (fl_value_get_type(owned_value) == FL_VALUE_TYPE_LIST ||
178  fl_value_get_type(owned_value) == FL_VALUE_TYPE_MAP) {
179  push(value);
180  }
181 
182  return true;
183  }
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
#define FL_MESSAGE_CODEC_ERROR
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition: fl_value.cc:506
uint8_t value
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:532
void push(FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition: fl_value.cc:335

◆ Bool()

bool FlValueHandler::Bool ( bool  b)
inline

Definition at line 189 of file fl_json_message_codec.cc.

References add(), and fl_value_new_bool().

189 { return add(fl_value_new_bool(b)); }
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:226
bool add(FlValue *value)

◆ Double()

bool FlValueHandler::Double ( double  d)
inline

Definition at line 206 of file fl_json_message_codec.cc.

References add(), and fl_value_new_float().

206 { return add(fl_value_new_float(d)); }
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:240
bool add(FlValue *value)

◆ EndArray()

bool FlValueHandler::EndArray ( rapidjson::SizeType  elementCount)
inline

Definition at line 236 of file fl_json_message_codec.cc.

References pop().

236  {
237  pop();
238  return true;
239  }

◆ EndObject()

bool FlValueHandler::EndObject ( rapidjson::SizeType  memberCount)
inline

Definition at line 229 of file fl_json_message_codec.cc.

References pop().

229  {
230  pop();
231  return true;
232  }

◆ get_head()

FlValue* FlValueHandler::get_head ( )
inline

Definition at line 147 of file fl_json_message_codec.cc.

Referenced by add(), and fl_json_message_codec_decode_message().

147  {
148  if (stack->len == 0) {
149  return nullptr;
150  }
151  return static_cast<FlValue*>(g_ptr_array_index(stack, stack->len - 1));
152  }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39

◆ Int()

bool FlValueHandler::Int ( int  i)
inline

Definition at line 191 of file fl_json_message_codec.cc.

References add(), and fl_value_new_int().

191 { return add(fl_value_new_int(i)); }
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
bool add(FlValue *value)

◆ Int64()

bool FlValueHandler::Int64 ( int64_t  i)
inline

Definition at line 195 of file fl_json_message_codec.cc.

References add(), and fl_value_new_int().

195 { return add(fl_value_new_int(i)); }
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
bool add(FlValue *value)

◆ Key()

bool FlValueHandler::Key ( const char *  str,
rapidjson::SizeType  length,
bool  copy 
)
inline

Definition at line 221 of file fl_json_message_codec.cc.

References fl_value_new_string_sized(), and fl_value_unref().

221  {
222  if (key != nullptr) {
224  }
226  return true;
227  }
G_MODULE_EXPORT void fl_value_unref(FlValue *self)
Definition: fl_value.cc:341
size_t length
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:254

◆ Null()

bool FlValueHandler::Null ( )
inline

Definition at line 187 of file fl_json_message_codec.cc.

References add(), and fl_value_new_null().

187 { return add(fl_value_new_null()); }
bool add(FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:222

◆ pop()

void FlValueHandler::pop ( )
inline

Definition at line 158 of file fl_json_message_codec.cc.

Referenced by EndArray(), and EndObject().

158 { g_ptr_array_remove_index(stack, stack->len - 1); }

◆ push()

void FlValueHandler::push ( FlValue value)
inline

Definition at line 155 of file fl_json_message_codec.cc.

References fl_value_ref().

Referenced by add().

155 { g_ptr_array_add(stack, fl_value_ref(value)); }
uint8_t value
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition: fl_value.cc:335

◆ RawNumber()

bool FlValueHandler::RawNumber ( const char *  str,
rapidjson::SizeType  length,
bool  copy 
)
inline

Definition at line 208 of file fl_json_message_codec.cc.

References FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

208  {
210  "RawNumber not supported");
211  return false;
212  }
#define FL_MESSAGE_CODEC_ERROR

◆ StartArray()

bool FlValueHandler::StartArray ( )
inline

Definition at line 234 of file fl_json_message_codec.cc.

References add(), and fl_value_new_list().

234 { return add(fl_value_new_list()); }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
bool add(FlValue *value)

◆ StartObject()

bool FlValueHandler::StartObject ( )
inline

Definition at line 219 of file fl_json_message_codec.cc.

References add(), and fl_value_new_map().

219 { return add(fl_value_new_map()); }
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:327
bool add(FlValue *value)

◆ String()

bool FlValueHandler::String ( const char *  str,
rapidjson::SizeType  length,
bool  copy 
)
inline

Definition at line 214 of file fl_json_message_codec.cc.

References add(), and fl_value_new_string_sized().

214  {
216  return add(v);
217  }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
size_t length
bool add(FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:254

◆ Uint()

bool FlValueHandler::Uint ( unsigned  i)
inline

Definition at line 193 of file fl_json_message_codec.cc.

References add(), and fl_value_new_int().

193 { return add(fl_value_new_int(i)); }
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
bool add(FlValue *value)

◆ Uint64()

bool FlValueHandler::Uint64 ( uint64_t  i)
inline

Definition at line 197 of file fl_json_message_codec.cc.

References add(), fl_value_new_float(), and fl_value_new_int().

197  {
198  // For some reason (bug in rapidjson?) this is not returned in Int64.
199  if (i == G_MAXINT64) {
200  return add(fl_value_new_int(i));
201  } else {
202  return add(fl_value_new_float(i));
203  }
204  }
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:240
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
bool add(FlValue *value)

Member Data Documentation

◆ error

GError* FlValueHandler::error

Definition at line 127 of file fl_json_message_codec.cc.

Referenced by fl_json_message_codec_decode_message().

◆ key

FlValue* FlValueHandler::key

Definition at line 126 of file fl_json_message_codec.cc.

◆ stack

GPtrArray* FlValueHandler::stack

Definition at line 125 of file fl_json_message_codec.cc.


The documentation for this struct was generated from the following file: