mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-15 07:15:03 -04:00
More documentation and unit tests for event_tagging.
svn:r1476
This commit is contained in:
parent
1eadb3e3a2
commit
5b3fb5bfa5
@ -67,6 +67,30 @@
|
||||
#include "mm-internal.h"
|
||||
#include "util-internal.h"
|
||||
|
||||
/*
|
||||
Here's our wire format:
|
||||
|
||||
Stream = TaggedData*
|
||||
|
||||
TaggedData = Tag Length Data
|
||||
where the integer value of 'Length' is the length of 'data'.
|
||||
|
||||
Tag = HByte* LByte
|
||||
where HByte is a byte with the high bit set, and LByte is a byte
|
||||
with the high bit clear. The integer value of the tag is taken
|
||||
by concatenating the lower 7 bits from all the tags. So for example,
|
||||
the tag 0x66 is encoded as [66], whereas the tag 0x166 is encoded as
|
||||
[82 66]
|
||||
|
||||
Length = Integer
|
||||
|
||||
Integer = NNibbles Nibble* Padding?
|
||||
where NNibbles is a 4-bit value encoding the number of nibbles-1,
|
||||
and each Nibble is 4 bits worth of encoded integer, in big-endian
|
||||
order. If the total encoded integer size is an odd number of nibbles,
|
||||
a final padding nibble with value 0 is appended.
|
||||
*/
|
||||
|
||||
int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf);
|
||||
int evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf);
|
||||
int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t tag);
|
||||
|
@ -1464,6 +1464,33 @@ end:
|
||||
evbuffer_free(tmp);
|
||||
}
|
||||
|
||||
static void
|
||||
evtag_test_peek(void *ptr)
|
||||
{
|
||||
struct evbuffer *tmp = evbuffer_new();
|
||||
ev_uint32_t u32;
|
||||
|
||||
evtag_marshal_int(tmp, 30, 0);
|
||||
evtag_marshal_string(tmp, 40, "Hello world");
|
||||
|
||||
tt_int_op(evtag_peek(tmp, &u32), ==, 1);
|
||||
tt_int_op(u32, ==, 30);
|
||||
tt_int_op(evtag_peek_length(tmp, &u32), ==, 0);
|
||||
tt_int_op(u32, ==, 1+1+1);
|
||||
tt_int_op(evtag_consume(tmp), ==, 0);
|
||||
|
||||
tt_int_op(evtag_peek(tmp, &u32), ==, 1);
|
||||
tt_int_op(u32, ==, 40);
|
||||
tt_int_op(evtag_peek_length(tmp, &u32), ==, 0);
|
||||
tt_int_op(u32, ==, 1+1+11);
|
||||
tt_int_op(evtag_payload_length(tmp, &u32), ==, 0);
|
||||
tt_int_op(u32, ==, 11);
|
||||
|
||||
end:
|
||||
evbuffer_free(tmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
test_methods(void *ptr)
|
||||
@ -1832,6 +1859,7 @@ struct testcase_t evtag_testcases[] = {
|
||||
{ "int", evtag_int_test, TT_FORK, NULL, NULL },
|
||||
{ "fuzz", evtag_fuzz, TT_FORK, NULL, NULL },
|
||||
{ "encoding", evtag_tag_encoding, TT_FORK, NULL, NULL },
|
||||
{ "peek", evtag_test_peek, 0, NULL, NULL },
|
||||
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user