<commit_before>#include "opensync.h"
#include "opensync_internals.h"

int osync_marshal_get_size_changetype( OSyncChangeType changetype )
{
  return sizeof( int );
}

void osync_marshal_changetype( OSyncMessage *message, OSyncChangeType changetype )
{
  osync_message_write_int( message, (int)changetype );
}

void osync_demarshal_changetype( OSyncMessage *message, OSyncChangeType *changetype )
{
  int change_type = 0;

  osync_message_read_int( message, &change_type );
  *changetype =(OSyncChangeType)change_type;
}

int osync_marshal_get_size_change( OSyncChange *change )
{
  int size = 0;

  if ( !change )
    return size;

  size += strlen( change->uid );
  size += strlen( change->hash );
  size += sizeof( int ); // change->size
  size += change->size;  // change->data
  size += sizeof( int ); // change->has_data
  size += strlen( change->objtype_name );
  size += strlen( change->format_name );
  size += strlen( change->initial_format_name );
  size += osync_marshal_get_size_changetype( change->changetype );
  size += sizeof( long long int ); // change->id
  size += strlen( change->destobjtype );
  size += strlen( change->sourceobjtype );
  size += osync_marshal_get_size_member( change->sourcemember );

  return size;
}

void osync_marshal_change( OSyncMessage *message, OSyncChange *change )
{
  osync_message_write_string( message, change->uid );
  osync_message_write_string( message, change->hash );
  osync_message_write_int( message, change->size );

  // TODO: check for plain/struct

  osync_message_write_data( message, change->data, change->size );
  osync_message_write_int( message, change->has_data );
  osync_message_write_string( message, change->objtype_name );
  osync_message_write_string( message, change->format_name );
  osync_message_write_string( message, change->initial_format_name );
  osync_marshal_changetype( message, change->changetype );
  osync_message_write_long_long_int( message, change->id );
  osync_message_write_string( message, change->destobjtype );
  osync_message_write_string( message, change->sourceobjtype );
  osync_marshal_member( message, change->sourcemember );
}

void osync_demarshal_change( OSyncMessage *message, OSyncChange **change )
{
  OSyncChange *new_change = osync_change_new();

  osync_message_read_string( message, &( new_change->uid ) );
  osync_message_read_string( message, &( new_change->hash ) );
  osync_message_read_int( message, &( new_change->size ) );<commit_msg>Marshall objtype/objformat names properly<commit_after>#include "opensync.h"
#include "opensync_internals.h"

int osync_marshal_get_size_changetype( OSyncChangeType changetype )
{
  return sizeof( int );
}

void osync_marshal_changetype( OSyncMessage *message, OSyncChangeType changetype )
{
  osync_message_write_int( message, (int)changetype );
}

void osync_demarshal_changetype( OSyncMessage *message, OSyncChangeType *changetype )
{
  int change_type = 0;

  osync_message_read_int( message, &change_type );
  *changetype =(OSyncChangeType)change_type;
}

int osync_marshal_get_size_change( OSyncChange *change )
{
  int size = 0;

  if ( !change )
    return size;

  size += strlen( change->uid );
  size += strlen( change->hash );
  size += sizeof( int ); // change->size
  size += change->size;  // change->data
  size += sizeof( int ); // change->has_data
  size += strlen( change->objtype_name );
  size += strlen( change->format_name );
  size += strlen( change->initial_format_name );
  size += osync_marshal_get_size_changetype( change->changetype );
  size += sizeof( long long int ); // change->id
  size += strlen( change->destobjtype );
  size += strlen( change->sourceobjtype );
  size += osync_marshal_get_size_member( change->sourcemember );

  return size;
}

void osync_marshal_change( OSyncMessage *message, OSyncChange *change )
{
  osync_message_write_string( message, change->uid );
  osync_message_write_string( message, change->hash );
  osync_message_write_int( message, change->size );

  // TODO: check for plain/struct

  char *format_name = change->format ? change->format->name : change->format_name;
  char *objtype_name = change->objtype ? change->objtype->name : change->objtype_name;
  char *initial_format_name = change->initial_format ? change->initial_format->name : change->initial_format_name;
  osync_message_write_data( message, change->data, change->size );
  osync_message_write_int( message, change->has_data );
  osync_message_write_string( message, objtype_name );
  osync_message_write_string( message, format_name );
  osync_message_write_string( message, initial_format_name );
  osync_marshal_changetype( message, change->changetype );
  osync_message_write_long_long_int( message, change->id );
  osync_message_write_string( message, change->destobjtype );
  osync_message_write_string( message, change->sourceobjtype );
  osync_marshal_member( message, change->sourcemember );
}

void osync_demarshal_change( OSyncMessage *message, OSyncChange **change )
{
  OSyncChange *new_change = osync_change_new();

  osync_message_read_string( message, &( new_change->uid ) );
  osync_message_read_string( message, &( new_change->hash ) );
  osync_message_read_int( message, &( new_change->size ) );
{'fraction_non_alphanumeric': 0.11834774255523535, 'fraction_numerical': 0.0007684918347742555, 'mean_word_length': 5.5566750629722925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1185002', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1692, 'n_words': 336}