diff options
Diffstat (limited to 'src/analysis/types/array.c')
-rw-r--r-- | src/analysis/types/array.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/analysis/types/array.c b/src/analysis/types/array.c index 5ea4179..b8321a2 100644 --- a/src/analysis/types/array.c +++ b/src/analysis/types/array.c @@ -72,6 +72,12 @@ static void g_array_type_dispose(GArrayType *); /* Procède à la libération totale de la mémoire. */ static void g_array_type_finalize(GArrayType *); +/* Charge un objet depuis une mémoire tampon. */ +static bool g_array_type_load(GArrayType *, GObjectStorage *, packed_buffer *); + +/* Sauvegarde un objet dans une mémoire tampon. */ +static bool g_array_type_store(const GArrayType *, GObjectStorage *, packed_buffer *); + /* Calcule une empreinte pour un type de données. */ static guint g_array_type_hash(const GArrayType *); @@ -111,6 +117,9 @@ static void g_array_type_class_init(GArrayTypeClass *klass) type = G_DATA_TYPE_CLASS(klass); + type->load = (type_load_fc)g_array_type_load; + type->store = (type_store_fc)g_array_type_store; + type->hash = (type_hash_fc)g_array_type_hash; type->dup = (type_dup_fc)g_array_type_dup; type->to_string = (type_to_string_fc)g_array_type_to_string; @@ -210,6 +219,115 @@ GDataType *g_array_type_new(GDataType *members) /****************************************************************************** * * +* Paramètres : type = type de données à constuire. * +* storage = conservateur de données à manipuler ou NULL. * +* pbuf = zone tampon à remplir. * +* * +* Description : Charge un objet depuis une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_array_type_load(GArrayType *type, GObjectStorage *storage, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + bool numbered; /* Choix de la dimension */ + leb128_t number; /* Valeur LEB128 à charger */ + uleb128_t value; /* Valeur ULEB128 à charger */ + + result = G_DATA_TYPE_CLASS(g_array_type_parent_class)->load(G_DATA_TYPE(type), storage, pbuf); + if (!result) goto exit; + + result = extract_packed_buffer(pbuf, &numbered, sizeof(uint8_t), false); + if (!result) goto exit; + + type->numbered = (numbered == 0x01); + + if (type->numbered) + { + result = unpack_leb128(&number, pbuf); + if (!result) goto exit; + + type->dim_number = number; + + } + else + { + result = unpack_uleb128(&value, pbuf); + if (!result) goto exit; + + type->dim_expr = calloc(value, sizeof(char)); + result = extract_packed_buffer(pbuf, type->dim_expr, value, false); + if (!result) goto exit; + + } + + result = g_serializable_object_load(G_SERIALIZABLE_OBJECT(type->members), storage, pbuf); + + exit: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : type = type de données à consulter. * +* storage = conservateur de données à manipuler ou NULL. * +* pbuf = zone tampon à remplir. * +* * +* Description : Sauvegarde un objet dans une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_array_type_store(const GArrayType *type, GObjectStorage *storage, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + size_t len; /* Taille d'une chaîne */ + + result = G_DATA_TYPE_CLASS(g_array_type_parent_class)->store(G_DATA_TYPE(type), storage, pbuf); + if (!result) goto exit; + + result = extend_packed_buffer(pbuf, (uint8_t []){ type->numbered ? 0x01 : 0x00 }, sizeof(uint8_t), false); + if (!result) goto exit; + + if (type->numbered) + { + result = pack_leb128((leb128_t []){ type->dim_number }, pbuf); + if (!result) goto exit; + + } + else + { + len = strlen(type->dim_expr); + + result = pack_uleb128((uleb128_t []){ len }, pbuf); + if (!result) goto exit; + + result = extend_packed_buffer(pbuf, type->dim_expr, len, false); + if (!result) goto exit; + + } + + result = g_serializable_object_store(G_SERIALIZABLE_OBJECT(type->members), storage, pbuf); + + exit: + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : type = type à consulter. * * * * Description : Calcule une empreinte pour un type de données. * |