loci: add a function to parse messages without allocating memory
This will be used by the Indigo connection manager to parse messages directly
from the read buffer, saving three allocations and a memcpy.
diff --git a/c_gen/templates/locitest/test_utils.c b/c_gen/templates/locitest/test_utils.c
index bcd4194..563f510 100644
--- a/c_gen/templates/locitest/test_utils.c
+++ b/c_gen/templates/locitest/test_utils.c
@@ -118,10 +118,32 @@
return TEST_PASS;
}
+static int
+test_of_object_new_from_message_preallocated(void)
+{
+ /* v1 OFPT_HELLO, xid=0x12345678 */
+ uint8_t buf[] = { 0x01, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78 };
+
+ of_object_storage_t storage;
+ of_object_t *obj = of_object_new_from_message_preallocated(
+ &storage, buf, sizeof(buf));
+
+ TEST_ASSERT(obj != NULL);
+ TEST_ASSERT(obj->version = OF_VERSION_1_0);
+ TEST_ASSERT(obj->object_id = OF_HELLO);
+
+ uint32_t xid;
+ of_hello_xid_get(obj, &xid);
+ TEST_ASSERT(xid == 0x12345678);
+
+ return TEST_PASS;
+}
+
int
run_utility_tests(void)
{
RUN_TEST(has_outport);
+ RUN_TEST(of_object_new_from_message_preallocated);
RUN_TEST(dump_objs);
return TEST_PASS;