message: split message_parse_metadata()
Split the metadata parser. It is already getting too big to review, and
we haven't even added the body parser, yet.
@@ -140,10 +140,7 @@ void message_free(_Atomic unsigned long *n_refs, void *userdata) {
free(message);
}
-/**
- * message_parse_metadata() - XXX
- */
-int message_parse_metadata(Message *message, MessageMetadata *metadata) {
+static int message_parse_header(Message *message, MessageMetadata *metadata) {
static const CDVarType type[] = {
C_DVAR_T_INIT(
C_DVAR_T_TUPLE7(
@@ -167,8 +164,6 @@ int message_parse_metadata(Message *message, MessageMetadata *metadata) {
uint8_t field;
int r;
- *metadata = (MessageMetadata){};
-
c_dvar_begin_read(&v, message->big_endian, type, 1, message->header, message->n_header);
/*
@@ -334,6 +329,27 @@ int message_parse_metadata(Message *message, MessageMetadata *metadata) {
else if (r)
return error_fold(r);
+ return 0;
+}
+
+/**
+ * message_parse_metadata() - XXX
+ */
+int message_parse_metadata(Message *message, MessageMetadata *metadata) {
+ int r;
+
+ assert(!message->parsed);
+
+ *metadata = (MessageMetadata){};
+
+ /*
+ * As first step, parse the static header and the dynamic header
+ * fields. Any error there is fatal.
+ */
+ r = message_parse_header(message, metadata);
+ if (r)
+ return error_trace(r);
+
/*
* XXX: Validate padding between header and body!
*/
