예제 #1
0
/**
 * Deserialization routine for pubdata.
 */
static void
deserialize_pubdata(bstr_t *bs, void *valptr, size_t len)
{
	struct pubdata *pd = valptr;

	g_assert(sizeof *pd == len);

	bstr_read_time(bs, &pd->next_enqueue);
	bstr_read_time(bs, &pd->expiration);

	/*
	 * Temporary, until 0.96.7 is out: we cannot blindly read the version
	 * since it was lacking in previous experimental versions.  Therefore
	 * only do it if we have unread data.
	 *
	 * The test will be removed in versions after 0.96.7, when we can be
	 * certain that the new data format was serialized.
	 *		--RAM, 2009-10-18
	 */

	if (bstr_unread_size(bs))
		bstr_read_u8(bs, &pd->version);
	else
		pd->version = 0;
}
예제 #2
0
파일: dbmw.c 프로젝트: Haxe/gtk-gnutella
/**
 * Wrapper to the user-supplied deserialization routine for values.
 *
 * @param dw		the DBM wrapper object
 * @param bs		the initialized binary stream from which we're reading
 * @param valptr	where deserialization should be done
 * @param len		length of arena at valptr, for assertions
 *
 * @return TRUE if deserialization was OK.
 */
static gboolean
dbmw_deserialize(const dbmw_t *dw, bstr_t *bs, gpointer valptr, size_t len)
{
	(*dw->unpack)(bs, valptr, len);

	if (bstr_has_error(bs))
		return FALSE;
	else if (bstr_unread_size(bs)) {
		/*
		 * Something is wrong, we're not deserializing the right data?
		 * Let bstr_error() report the error (caller to check returned value).
		 */
		bstr_trailing_error(bs);
		return FALSE;
	}

	return TRUE;
}