Exemple #1
0
/*
 * Return number of deserialized sequence information
 */
size_t
gtm_deserialize_sequence(GTM_SeqInfo *seq, const char *buf, size_t buflen)
{
	size_t len = 0;

	seq->gs_key = (GTM_SequenceKeyData *)genAlloc0(sizeof(GTM_SequenceKeyData));

	memcpy(&seq->gs_key->gsk_keylen, buf + len, sizeof(uint32));
	len += sizeof(uint32);/* gs_key.gsk_keylen */

	seq->gs_key->gsk_key = (char *)genAlloc0(seq->gs_key->gsk_keylen+1);
	memcpy(seq->gs_key->gsk_key, buf + len, seq->gs_key->gsk_keylen);
	len += seq->gs_key->gsk_keylen;/* gs_key.gsk_key */

	memcpy(&seq->gs_key->gsk_type, buf + len, sizeof(GTM_SequenceKeyType));
	len += sizeof(GTM_SequenceKeyType);   /* gs_key.gsk_type */

	memcpy(&seq->gs_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_value */

	memcpy(&seq->gs_init_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_init_value */

	memcpy(&seq->gs_max_lastvals, buf + len, sizeof(uint32));
	len += sizeof(uint32);		  /* gs_max_lastvals */
	if (seq->gs_max_lastvals > 0)
		seq->gs_last_values = (GTM_SeqLastVal *)
				genAlloc(seq->gs_max_lastvals * sizeof(GTM_SeqLastVal));
	memcpy(&seq->gs_lastval_count, buf + len, sizeof(uint32));
	len += sizeof(uint32);		  /* gs_lastval_count */
	if (seq->gs_lastval_count > 0)
	{
		memcpy(seq->gs_last_values, buf + len,
				seq->gs_lastval_count * sizeof(GTM_SeqLastVal));
		len += seq->gs_lastval_count * sizeof(GTM_SeqLastVal); /* gs_last_values */
	}

	memcpy(&seq->gs_increment_by, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_increment_by */

	memcpy(&seq->gs_min_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_min_value */

	memcpy(&seq->gs_max_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_max_value */

	memcpy(&seq->gs_cycle, buf + len, sizeof(bool));
	len += sizeof(bool);  /* gs_cycle */

	memcpy(&seq->gs_called, buf + len, sizeof(bool));
	len += sizeof(bool);  /* gs_called */

	memcpy(&seq->gs_ref_count, buf + len, sizeof(uint32));
	len += sizeof(uint32);

	memcpy(&seq->gs_state, buf + len, sizeof(uint32));
	len += sizeof(uint32);

	return len;
}
/*
 * Return number of deserialized sequence information
 */
GTM_SeqInfo *
gtm_deserialize_sequence(const char *buf, size_t buflen)
{
	size_t len = 0;
	GTM_SeqInfo *seq;

	seq = (GTM_SeqInfo *)genAlloc0(sizeof(GTM_SeqInfo));
	seq->gs_key = (GTM_SequenceKeyData *)genAlloc0(sizeof(GTM_SequenceKeyData));

	memcpy(&seq->gs_key->gsk_keylen, buf + len, sizeof(uint32));
	len += sizeof(uint32);/* gs_key.gsk_keylen */

	seq->gs_key->gsk_key = (char *)genAlloc0(seq->gs_key->gsk_keylen+1);
	memcpy(seq->gs_key->gsk_key, buf + len, seq->gs_key->gsk_keylen);
	len += seq->gs_key->gsk_keylen;/* gs_key.gsk_key */

	memcpy(&seq->gs_key->gsk_type, buf + len, sizeof(GTM_SequenceKeyType));
	len += sizeof(GTM_SequenceKeyType);   /* gs_key.gsk_type */

	memcpy(&seq->gs_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_value */

	memcpy(&seq->gs_init_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_init_value */

	memcpy(&seq->gs_last_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_last_value */

	memcpy(&seq->gs_increment_by, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_increment_by */

	memcpy(&seq->gs_min_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_min_value */

	memcpy(&seq->gs_max_value, buf + len, sizeof(GTM_Sequence));
	len += sizeof(GTM_Sequence);  /* gs_max_value */

	memcpy(&seq->gs_cycle, buf + len, sizeof(bool));
	len += sizeof(bool);  /* gs_cycle */

	memcpy(&seq->gs_called, buf + len, sizeof(bool));
	len += sizeof(bool);  /* gs_called */

	memcpy(&seq->gs_ref_count, buf + len, sizeof(uint32));
	len += sizeof(uint32);

	memcpy(&seq->gs_state, buf + len, sizeof(uint32));
	len += sizeof(uint32);

	return seq;
}