| // Autogenerated from Pigeon (v29.0.1), do not edit directly. |
| // See also: https://pub.dev/packages/pigeon |
| |
| #include <cmath> |
| |
| #include <string.h> |
| #include "messages.g.h" |
| static guint G_GNUC_UNUSED flpigeon_hash_double(double v) { |
| if (std::isnan(v)) { |
| return static_cast<guint>(0x7FF80000); |
| } |
| if (v == 0.0) { |
| v = 0.0; |
| } |
| union { double d; uint64_t u; } u; |
| u.d = v; |
| return static_cast<guint>(u.u ^ (u.u >> 32)); |
| } |
| static gboolean G_GNUC_UNUSED flpigeon_equals_double(double a, double b) { |
| return (a == b) || (std::isnan(a) && std::isnan(b)); |
| } |
| static gboolean G_GNUC_UNUSED flpigeon_deep_equals(FlValue* a, FlValue* b) { |
| if (a == b) { |
| return TRUE; |
| } |
| if (a == nullptr || b == nullptr) { |
| return FALSE; |
| } |
| if (fl_value_get_type(a) != fl_value_get_type(b)) { |
| return FALSE; |
| } |
| switch (fl_value_get_type(a)) { |
| case FL_VALUE_TYPE_NULL: |
| return TRUE; |
| case FL_VALUE_TYPE_BOOL: |
| return fl_value_get_bool(a) == fl_value_get_bool(b); |
| case FL_VALUE_TYPE_INT: |
| return fl_value_get_int(a) == fl_value_get_int(b); |
| case FL_VALUE_TYPE_FLOAT: { |
| return flpigeon_equals_double(fl_value_get_float(a), fl_value_get_float(b)); |
| } |
| case FL_VALUE_TYPE_STRING: |
| return g_strcmp0(fl_value_get_string(a), fl_value_get_string(b)) == 0; |
| case FL_VALUE_TYPE_UINT8_LIST: |
| return fl_value_get_length(a) == fl_value_get_length(b) && |
| memcmp(fl_value_get_uint8_list(a), fl_value_get_uint8_list(b), fl_value_get_length(a)) == 0; |
| case FL_VALUE_TYPE_INT32_LIST: |
| return fl_value_get_length(a) == fl_value_get_length(b) && |
| memcmp(fl_value_get_int32_list(a), fl_value_get_int32_list(b), fl_value_get_length(a) * sizeof(int32_t)) == 0; |
| case FL_VALUE_TYPE_INT64_LIST: |
| return fl_value_get_length(a) == fl_value_get_length(b) && |
| memcmp(fl_value_get_int64_list(a), fl_value_get_int64_list(b), fl_value_get_length(a) * sizeof(int64_t)) == 0; |
| case FL_VALUE_TYPE_FLOAT_LIST: { |
| size_t len = fl_value_get_length(a); |
| if (len != fl_value_get_length(b)) { |
| return FALSE; |
| } |
| const double* a_data = fl_value_get_float_list(a); |
| const double* b_data = fl_value_get_float_list(b); |
| for (size_t i = 0; i < len; i++) { |
| if (!flpigeon_equals_double(a_data[i], b_data[i])) { |
| return FALSE; |
| } |
| } |
| return TRUE; |
| } |
| case FL_VALUE_TYPE_LIST: { |
| size_t len = fl_value_get_length(a); |
| if (len != fl_value_get_length(b)) { |
| return FALSE; |
| } |
| for (size_t i = 0; i < len; i++) { |
| if (!flpigeon_deep_equals(fl_value_get_list_value(a, i), fl_value_get_list_value(b, i))) { |
| return FALSE; |
| } |
| } |
| return TRUE; |
| } |
| case FL_VALUE_TYPE_MAP: { |
| size_t len = fl_value_get_length(a); |
| if (len != fl_value_get_length(b)) { |
| return FALSE; |
| } |
| for (size_t i = 0; i < len; i++) { |
| FlValue* key = fl_value_get_map_key(a, i); |
| FlValue* val = fl_value_get_map_value(a, i); |
| gboolean found = FALSE; |
| for (size_t j = 0; j < len; j++) { |
| FlValue* b_key = fl_value_get_map_key(b, j); |
| if (flpigeon_deep_equals(key, b_key)) { |
| FlValue* b_val = fl_value_get_map_value(b, j); |
| if (flpigeon_deep_equals(val, b_val)) { |
| found = TRUE; |
| break; |
| } else { |
| return FALSE; |
| } |
| } |
| } |
| if (!found) { |
| return FALSE; |
| } |
| } |
| return TRUE; |
| } |
| default: |
| return FALSE; |
| } |
| return FALSE; |
| } |
| static guint G_GNUC_UNUSED flpigeon_deep_hash(FlValue* value) { |
| if (value == nullptr) { |
| return 0; |
| } |
| switch (fl_value_get_type(value)) { |
| case FL_VALUE_TYPE_NULL: |
| return 0; |
| case FL_VALUE_TYPE_BOOL: |
| return fl_value_get_bool(value) ? 1231 : 1237; |
| case FL_VALUE_TYPE_INT: { |
| int64_t v = fl_value_get_int(value); |
| return static_cast<guint>(v ^ (v >> 32)); |
| } |
| case FL_VALUE_TYPE_FLOAT: |
| return flpigeon_hash_double(fl_value_get_float(value)); |
| case FL_VALUE_TYPE_STRING: |
| return g_str_hash(fl_value_get_string(value)); |
| case FL_VALUE_TYPE_UINT8_LIST: { |
| guint result = 1; |
| size_t len = fl_value_get_length(value); |
| const uint8_t* data = fl_value_get_uint8_list(value); |
| for (size_t i = 0; i < len; i++) { |
| result = result * 31 + data[i]; |
| } |
| return result; |
| } |
| case FL_VALUE_TYPE_INT32_LIST: { |
| guint result = 1; |
| size_t len = fl_value_get_length(value); |
| const int32_t* data = fl_value_get_int32_list(value); |
| for (size_t i = 0; i < len; i++) { |
| result = result * 31 + static_cast<guint>(data[i]); |
| } |
| return result; |
| } |
| case FL_VALUE_TYPE_INT64_LIST: { |
| guint result = 1; |
| size_t len = fl_value_get_length(value); |
| const int64_t* data = fl_value_get_int64_list(value); |
| for (size_t i = 0; i < len; i++) { |
| result = result * 31 + static_cast<guint>(data[i] ^ (data[i] >> 32)); |
| } |
| return result; |
| } |
| case FL_VALUE_TYPE_FLOAT_LIST: { |
| guint result = 1; |
| size_t len = fl_value_get_length(value); |
| const double* data = fl_value_get_float_list(value); |
| for (size_t i = 0; i < len; i++) { |
| result = result * 31 + flpigeon_hash_double(data[i]); |
| } |
| return result; |
| } |
| case FL_VALUE_TYPE_LIST: { |
| guint result = 1; |
| size_t len = fl_value_get_length(value); |
| for (size_t i = 0; i < len; i++) { |
| result = result * 31 + flpigeon_deep_hash(fl_value_get_list_value(value, i)); |
| } |
| return result; |
| } |
| case FL_VALUE_TYPE_MAP: { |
| guint result = 0; |
| size_t len = fl_value_get_length(value); |
| for (size_t i = 0; i < len; i++) { |
| result += ((flpigeon_deep_hash(fl_value_get_map_key(value, i)) * 31) ^ flpigeon_deep_hash(fl_value_get_map_value(value, i))); |
| } |
| return result; |
| } |
| default: |
| return static_cast<guint>(fl_value_get_type(value)); |
| } |
| return 0; |
| } |
| static gchar* G_GNUC_UNUSED flpigeon_to_string(FlValue* value) { |
| if (value == nullptr) { |
| return g_strdup("null"); |
| } |
| switch (fl_value_get_type(value)) { |
| case FL_VALUE_TYPE_NULL: |
| return g_strdup("null"); |
| case FL_VALUE_TYPE_BOOL: |
| return g_strdup(fl_value_get_bool(value) ? "true" : "false"); |
| case FL_VALUE_TYPE_INT: |
| return g_strdup_printf("%" G_GINT64_FORMAT, fl_value_get_int(value)); |
| case FL_VALUE_TYPE_FLOAT: |
| return g_strdup_printf("%g", fl_value_get_float(value)); |
| case FL_VALUE_TYPE_STRING: |
| return g_strdup_printf("\"%s\"", fl_value_get_string(value)); |
| case FL_VALUE_TYPE_UINT8_LIST: { |
| GString* str = g_string_new("["); |
| size_t len = fl_value_get_length(value); |
| const uint8_t* data = fl_value_get_uint8_list(value); |
| for (size_t i = 0; i < len; i++) { |
| if (i > 0) { |
| g_string_append(str, ", "); |
| } |
| g_string_append_printf(str, "%d", data[i]); |
| } |
| g_string_append(str, "]"); |
| return g_string_free(str, FALSE); |
| } |
| case FL_VALUE_TYPE_INT32_LIST: { |
| GString* str = g_string_new("["); |
| size_t len = fl_value_get_length(value); |
| const int32_t* data = fl_value_get_int32_list(value); |
| for (size_t i = 0; i < len; i++) { |
| if (i > 0) { |
| g_string_append(str, ", "); |
| } |
| g_string_append_printf(str, "%d", data[i]); |
| } |
| g_string_append(str, "]"); |
| return g_string_free(str, FALSE); |
| } |
| case FL_VALUE_TYPE_INT64_LIST: { |
| GString* str = g_string_new("["); |
| size_t len = fl_value_get_length(value); |
| const int64_t* data = fl_value_get_int64_list(value); |
| for (size_t i = 0; i < len; i++) { |
| if (i > 0) { |
| g_string_append(str, ", "); |
| } |
| g_string_append_printf(str, "%" G_GINT64_FORMAT, data[i]); |
| } |
| g_string_append(str, "]"); |
| return g_string_free(str, FALSE); |
| } |
| case FL_VALUE_TYPE_FLOAT_LIST: { |
| GString* str = g_string_new("["); |
| size_t len = fl_value_get_length(value); |
| const double* data = fl_value_get_float_list(value); |
| for (size_t i = 0; i < len; i++) { |
| if (i > 0) { |
| g_string_append(str, ", "); |
| } |
| g_string_append_printf(str, "%g", data[i]); |
| } |
| g_string_append(str, "]"); |
| return g_string_free(str, FALSE); |
| } |
| case FL_VALUE_TYPE_LIST: { |
| GString* str = g_string_new("["); |
| size_t len = fl_value_get_length(value); |
| for (size_t i = 0; i < len; i++) { |
| if (i > 0) { |
| g_string_append(str, ", "); |
| } |
| gchar* item_str = flpigeon_to_string(fl_value_get_list_value(value, i)); |
| g_string_append(str, item_str); |
| g_free(item_str); |
| } |
| g_string_append(str, "]"); |
| return g_string_free(str, FALSE); |
| } |
| case FL_VALUE_TYPE_MAP: { |
| GString* str = g_string_new("{"); |
| size_t len = fl_value_get_length(value); |
| for (size_t i = 0; i < len; i++) { |
| if (i > 0) { |
| g_string_append(str, ", "); |
| } |
| gchar* key_str = flpigeon_to_string(fl_value_get_map_key(value, i)); |
| gchar* val_str = flpigeon_to_string(fl_value_get_map_value(value, i)); |
| g_string_append_printf(str, "%s: %s", key_str, val_str); |
| g_free(key_str); |
| g_free(val_str); |
| } |
| g_string_append(str, "}"); |
| return g_string_free(str, FALSE); |
| } |
| default: |
| return g_strdup("[custom]"); |
| } |
| return g_strdup("null"); |
| } |
| |
| |
| struct _{{projectNameUpperCamelCase}}MessageCodec { |
| FlStandardMessageCodec parent_instance; |
| |
| }; |
| |
| G_DEFINE_TYPE({{projectNameUpperCamelCase}}MessageCodec, {{projectName}}_message_codec, fl_standard_message_codec_get_type()) |
| |
| |
| static gboolean {{projectName}}_message_codec_write_value(FlStandardMessageCodec* codec, GByteArray* buffer, FlValue* value, GError** error) { |
| if (fl_value_get_type(value) == FL_VALUE_TYPE_CUSTOM) { |
| switch (fl_value_get_custom_type(value)) { |
| } |
| } |
| |
| return FL_STANDARD_MESSAGE_CODEC_CLASS({{projectName}}_message_codec_parent_class)->write_value(codec, buffer, value, error); |
| } |
| |
| static FlValue* {{projectName}}_message_codec_read_value_of_type(FlStandardMessageCodec* codec, GBytes* buffer, size_t* offset, int type, GError** error) { |
| switch (type) { |
| default: |
| return FL_STANDARD_MESSAGE_CODEC_CLASS({{projectName}}_message_codec_parent_class)->read_value_of_type(codec, buffer, offset, type, error); |
| } |
| } |
| |
| static void {{projectName}}_message_codec_init({{projectNameUpperCamelCase}}MessageCodec* self) { |
| } |
| |
| static void {{projectName}}_message_codec_class_init({{projectNameUpperCamelCase}}MessageCodecClass* klass) { |
| FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->write_value = {{projectName}}_message_codec_write_value; |
| FL_STANDARD_MESSAGE_CODEC_CLASS(klass)->read_value_of_type = {{projectName}}_message_codec_read_value_of_type; |
| } |
| |
| static {{projectNameUpperCamelCase}}MessageCodec* {{projectName}}_message_codec_new() { |
| {{projectNameUpperCamelCase}}MessageCodec* self = {{projectNameCapitalSnakeCase}}_MESSAGE_CODEC(g_object_new({{projectName}}_message_codec_get_type(), nullptr)); |
| return self; |
| } |
| |
| struct _{{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse { |
| GObject parent_instance; |
| |
| FlValue* value; |
| }; |
| |
| G_DEFINE_TYPE({{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse, {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response, G_TYPE_OBJECT) |
| |
| static void {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_dispose(GObject* object) { |
| {{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse* self = {{projectNameCapitalSnakeCase}}_{{pluginClassCapitalSnakeCase}}_API_GET_PLATFORM_VERSION_RESPONSE(object); |
| g_clear_pointer(&self->value, fl_value_unref); |
| G_OBJECT_CLASS({{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_parent_class)->dispose(object); |
| } |
| |
| static void {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_init({{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse* self) { |
| } |
| |
| static void {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_class_init({{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponseClass* klass) { |
| G_OBJECT_CLASS(klass)->dispose = {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_dispose; |
| } |
| |
| {{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse* {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_new(const gchar* return_value) { |
| {{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse* self = {{projectNameCapitalSnakeCase}}_{{pluginClassCapitalSnakeCase}}_API_GET_PLATFORM_VERSION_RESPONSE(g_object_new({{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_get_type(), nullptr)); |
| self->value = fl_value_new_list(); |
| fl_value_append_take(self->value, fl_value_new_string(return_value)); |
| return self; |
| } |
| |
| {{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse* {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_new_error(const gchar* code, const gchar* message, FlValue* details) { |
| {{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse* self = {{projectNameCapitalSnakeCase}}_{{pluginClassCapitalSnakeCase}}_API_GET_PLATFORM_VERSION_RESPONSE(g_object_new({{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_response_get_type(), nullptr)); |
| self->value = fl_value_new_list(); |
| fl_value_append_take(self->value, fl_value_new_string(code)); |
| fl_value_append_take(self->value, fl_value_new_string(message != nullptr ? message : "")); |
| fl_value_append_take(self->value, details != nullptr ? fl_value_ref(details) : fl_value_new_null()); |
| return self; |
| } |
| |
| struct _{{projectNameUpperCamelCase}}{{pluginClass}}Api { |
| GObject parent_instance; |
| |
| const {{projectNameUpperCamelCase}}{{pluginClass}}ApiVTable* vtable; |
| gpointer user_data; |
| GDestroyNotify user_data_free_func; |
| }; |
| |
| G_DEFINE_TYPE({{projectNameUpperCamelCase}}{{pluginClass}}Api, {{projectName}}_{{pluginClassSnakeCase}}_api, G_TYPE_OBJECT) |
| |
| static void {{projectName}}_{{pluginClassSnakeCase}}_api_dispose(GObject* object) { |
| {{projectNameUpperCamelCase}}{{pluginClass}}Api* self = {{projectNameCapitalSnakeCase}}_{{pluginClassCapitalSnakeCase}}_API(object); |
| if (self->user_data != nullptr) { |
| self->user_data_free_func(self->user_data); |
| } |
| self->user_data = nullptr; |
| G_OBJECT_CLASS({{projectName}}_{{pluginClassSnakeCase}}_api_parent_class)->dispose(object); |
| } |
| |
| static void {{projectName}}_{{pluginClassSnakeCase}}_api_init({{projectNameUpperCamelCase}}{{pluginClass}}Api* self) { |
| } |
| |
| static void {{projectName}}_{{pluginClassSnakeCase}}_api_class_init({{projectNameUpperCamelCase}}{{pluginClass}}ApiClass* klass) { |
| G_OBJECT_CLASS(klass)->dispose = {{projectName}}_{{pluginClassSnakeCase}}_api_dispose; |
| } |
| |
| static {{projectNameUpperCamelCase}}{{pluginClass}}Api* {{projectName}}_{{pluginClassSnakeCase}}_api_new(const {{projectNameUpperCamelCase}}{{pluginClass}}ApiVTable* vtable, gpointer user_data, GDestroyNotify user_data_free_func) { |
| {{projectNameUpperCamelCase}}{{pluginClass}}Api* self = {{projectNameCapitalSnakeCase}}_{{pluginClassCapitalSnakeCase}}_API(g_object_new({{projectName}}_{{pluginClassSnakeCase}}_api_get_type(), nullptr)); |
| self->vtable = vtable; |
| self->user_data = user_data; |
| self->user_data_free_func = user_data_free_func; |
| return self; |
| } |
| |
| static void {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_cb(FlBasicMessageChannel* channel, FlValue* message_, FlBasicMessageChannelResponseHandle* response_handle, gpointer user_data) { |
| {{projectNameUpperCamelCase}}{{pluginClass}}Api* self = {{projectNameCapitalSnakeCase}}_{{pluginClassCapitalSnakeCase}}_API(user_data); |
| |
| if (self->vtable == nullptr || self->vtable->get_platform_version == nullptr) { |
| return; |
| } |
| |
| g_autoptr({{projectNameUpperCamelCase}}{{pluginClass}}ApiGetPlatformVersionResponse) response = self->vtable->get_platform_version(self->user_data); |
| if (response == nullptr) { |
| g_warning("No response returned to %s.%s", "{{pluginClass}}Api", "getPlatformVersion"); |
| return; |
| } |
| |
| g_autoptr(GError) error = NULL; |
| if (!fl_basic_message_channel_respond(channel, response_handle, response->value, &error)) { |
| g_warning("Failed to send response to %s.%s: %s", "{{pluginClass}}Api", "getPlatformVersion", error->message); |
| } |
| } |
| |
| void {{projectName}}_{{pluginClassSnakeCase}}_api_set_method_handlers(FlBinaryMessenger* messenger, const gchar* suffix, const {{projectNameUpperCamelCase}}{{pluginClass}}ApiVTable* vtable, gpointer user_data, GDestroyNotify user_data_free_func) { |
| g_autofree gchar* dot_suffix = suffix != nullptr ? g_strdup_printf(".%s", suffix) : g_strdup(""); |
| g_autoptr({{projectNameUpperCamelCase}}{{pluginClass}}Api) api_data = {{projectName}}_{{pluginClassSnakeCase}}_api_new(vtable, user_data, user_data_free_func); |
| |
| g_autoptr({{projectNameUpperCamelCase}}MessageCodec) codec = {{projectName}}_message_codec_new(); |
| g_autofree gchar* get_platform_version_channel_name = g_strdup_printf("dev.flutter.pigeon.{{projectName}}.{{pluginClass}}Api.getPlatformVersion%s", dot_suffix); |
| g_autoptr(FlBasicMessageChannel) get_platform_version_channel = fl_basic_message_channel_new(messenger, get_platform_version_channel_name, FL_MESSAGE_CODEC(codec)); |
| fl_basic_message_channel_set_message_handler(get_platform_version_channel, {{projectName}}_{{pluginClassSnakeCase}}_api_get_platform_version_cb, g_object_ref(api_data), g_object_unref); |
| } |
| |
| void {{projectName}}_{{pluginClassSnakeCase}}_api_clear_method_handlers(FlBinaryMessenger* messenger, const gchar* suffix) { |
| g_autofree gchar* dot_suffix = suffix != nullptr ? g_strdup_printf(".%s", suffix) : g_strdup(""); |
| |
| g_autoptr({{projectNameUpperCamelCase}}MessageCodec) codec = {{projectName}}_message_codec_new(); |
| g_autofree gchar* get_platform_version_channel_name = g_strdup_printf("dev.flutter.pigeon.{{projectName}}.{{pluginClass}}Api.getPlatformVersion%s", dot_suffix); |
| g_autoptr(FlBasicMessageChannel) get_platform_version_channel = fl_basic_message_channel_new(messenger, get_platform_version_channel_name, FL_MESSAGE_CODEC(codec)); |
| fl_basic_message_channel_set_message_handler(get_platform_version_channel, nullptr, nullptr, nullptr); |
| } |