• Martes 30 de Abril de 2024, 05:23

Autor Tema:  Serializacion en C!!  (Leído 2443 veces)

ekys

  • Nuevo Miembro
  • *
  • Mensajes: 4
    • Ver Perfil
Serializacion en C!!
« en: Jueves 14 de Abril de 2011, 09:09 »
0
Hola a todos,

me gustaría que alguien me ayudara.

El caso es q estoy intentando serializar una estructura definida por mí (basicamente es una estructura en arbol dnd cada nodo tiene un string y un entero) y lo estoy haciendo en C (sí en C, ni C# ni C++) y para ello utilizo la libreria c11n. Sigo las intrucciones del manual pero no hay manera!!!!!

Alguien ha trabajado alguna vez con esta librería (segun dicen es parecida a la libreria s11n utilizada en C++)??

Algun tipo de ayuda para digerir mi desesperacion??


Gracias de antemano por cualquier tipo de ayuda.

Leber

  • Miembro activo
  • **
  • Mensajes: 65
    • Ver Perfil
Re: Serializacion en C!!
« Respuesta #1 en: Jueves 14 de Abril de 2011, 09:22 »
0
Podrías poner un poco de código. No esperarás que adivinemos que te esta fallando, verdad?  ^_^

ekys

  • Nuevo Miembro
  • *
  • Mensajes: 4
    • Ver Perfil
Re: Serializacion en C!!
« Respuesta #2 en: Jueves 14 de Abril de 2011, 10:05 »
0
El error que obtengo es segmentation fault. Algo me dice que el problema esta en la definicion de AST_c11n.


Y este és el codigo: un main, el archivo de cabecera del mi tipo "AST"y el respectivo AST.c


//*****************************MAIN.c*************************************

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "AST.h"
#include "c11n.h"
#include "c11n_io.h"
#include "c11n_stream_FILE.h"

/// Main program
int main(int argc,char *argv[])
{
   AST* a1=NULL;
   a1 = InsertAST(a1, "prueba");

   c11n_node * n = c11n_node_create("a1");
   bool rc = c11n_serialize( AST_c11n, n, &a1);
   c11n_node_destroy( n );
   if( ! rc ) printf("SERIALIZE error !!!!!");

   c11n_stream *str= c11n_stream_for_filename("a1.c11n", true);
   bool rc2 = c11n_save_serializable( str, AST_c11n, &a1 );
   c11n_serializable_save( str, AST_c11n, &a1, 0 );

   str->api->destroy(str);
   
   return 0;
}

//*****************************AST.h*************************************

#include "c11n.h"

typedef struct bnode AST;

//AST definitions FIELDs
struct bnode {
   char widget_name[20];
   int count;
   AST *left;
   AST *right;
};

AST* InsertAST ( AST* root, char* nodename);

extern const c11n_marshaller * AST_c11n;


//*****************************AST.c*************************************

#include "AST.h"

AST* InsertAST ( AST* root, char* nodename)
{
   if ( root == NULL ) {
      root = malloc ( sizeof ( AST ) );
      strcpy ( root->widget_name, nodename );
      root->count = 1;
      root->left = root->right = NULL;
   } else if ( strcmp (nodename, root->widget_name ) < 0 ){   //else if ( root->left == NULL)
      root->left = InsertAST ( root->left, nodename);
   }
   else if ( strcmp (nodename, root->widget_name ) > 0 ){
      root->right = InsertAST ( root->right, nodename);
   }
   else{ // must be equal
      root->count++;
   }

   return root;
}

static const c11n_marshaller_api c11n_markshaller_api_AST =
    C11N_MARSHALLER_API_INIT("AST",
              NULL,
              NULL,
              NULL,
              NULL,
              NULL);

static const c11n_marshaller AST_c11nX = { &c11n_markshaller_api_AST };
const c11n_marshaller * AST_c11n = &AST_c11nX;

m0skit0

  • Miembro de PLATA
  • *****
  • Mensajes: 2337
  • Nacionalidad: ma
    • Ver Perfil
    • http://fr33kk0mpu73r.blogspot.com/
Re: Serializacion en C!!
« Respuesta #3 en: Jueves 14 de Abril de 2011, 11:41 »
0
Por favor utiliza las etiquetas de código para publicar código...

ekys

  • Nuevo Miembro
  • *
  • Mensajes: 4
    • Ver Perfil
Re: Serializacion en C!!
« Respuesta #4 en: Lunes 18 de Abril de 2011, 23:50 »
0
ok,  sorry.