Exemplo n.º 1
0
void o_document_deserialize_internal(struct o_document * doc, struct o_input_stream * stream, int embeddd)
{
	struct o_string_buffer * buff = o_string_buffer_new();
	int isfirst = 1;
	int readed;
	do
	{
		readed = o_input_stream_read(stream);
		if (isfirst && readed == '@')
		{
			char * str = o_string_buffer_str(buff);
			doc->class_name = str;
			o_string_buffer_clear(buff);
		}
		else if (readed == ':')
		{
			isfirst = 0;
			char * str = o_string_buffer_str(buff);
			struct o_document_value * val = o_document_value_deserialize(stream);
			o_document_field_set(doc, str, val);
			o_free(str);
			o_string_buffer_clear(buff);
		}
		else if (readed != -1)
		{
			o_string_buffer_append_char(buff, readed);
		}
	} while (readed != -1 && readed != ')');
	o_string_buffer_free(buff);
}
Exemplo n.º 2
0
void test_o_input_simple_read()
{
	unsigned char bytes[] =
	{ 1, 2, 3, -1, -1 };
	struct o_input_stream * inp = o_input_stream_new_bytes(bytes, 5);
	assert_true(o_input_stream_read(inp) == 1, "Error reading first byte");
	assert_true(o_input_stream_read(inp) == 2, "Error reading second byte");
	assert_true(o_input_stream_read(inp) == 3, "Error reading third byte");
	assert_true(o_input_stream_read(inp) == (int) (unsigned char) -1, "Error reading forty byte");
	assert_true(o_input_stream_read(inp) != -1, "Error reading -1 char content");
	assert_true(o_input_stream_read(inp) == -1, "Error reading end byte");
	o_input_stream_free(inp);
}