You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2021/03/02 15:53:44 UTC

[GitHub] [daffodil] mbeckerle commented on a change in pull request #494: Support booleans, arrays of complex types, fixed values, fill bytes

mbeckerle commented on a change in pull request #494:
URL: https://github.com/apache/daffodil/pull/494#discussion_r585685202



##########
File path: daffodil-runtime2/src/main/resources/c/libruntime/parsers.c
##########
@@ -69,44 +113,72 @@
         }                                                                      \
     }
 
-// Define functions to parse binary real and integer numbers
+// Define functions to parse binary real numbers and integers
 
-define_parse_endian_real(be, double, 64)
+define_parse_endian_bool(be, 16);
+define_parse_endian_bool(be, 32);
+define_parse_endian_bool(be, 8);
 
+define_parse_endian_real(be, double, 64)
 define_parse_endian_real(be, float, 32)
 
-define_parse_endian_integer(be, uint, 64)
-
-define_parse_endian_integer(be, uint, 32)
+define_parse_endian_integer(be, int, 16)
+define_parse_endian_integer(be, int, 32)
+define_parse_endian_integer(be, int, 64)
+define_parse_endian_integer(be, int, 8)
 
 define_parse_endian_integer(be, uint, 16)
-
+define_parse_endian_integer(be, uint, 32)
+define_parse_endian_integer(be, uint, 64)
 define_parse_endian_integer(be, uint, 8)
 
-define_parse_endian_integer(be, int, 64)
-
-define_parse_endian_integer(be, int, 32)
-
-define_parse_endian_integer(be, int, 16)
-
-define_parse_endian_integer(be, int, 8)
+define_parse_endian_bool(le, 16);
+define_parse_endian_bool(le, 32);
+define_parse_endian_bool(le, 8);
 
 define_parse_endian_real(le, double, 64)
-
 define_parse_endian_real(le, float, 32)
 
-define_parse_endian_integer(le, uint, 64)
-
-define_parse_endian_integer(le, uint, 32)
+define_parse_endian_integer(le, int, 16)
+define_parse_endian_integer(le, int, 32)
+define_parse_endian_integer(le, int, 64)
+define_parse_endian_integer(le, int, 8)
 
 define_parse_endian_integer(le, uint, 16)
-
+define_parse_endian_integer(le, uint, 32)
+define_parse_endian_integer(le, uint, 64)
 define_parse_endian_integer(le, uint, 8)
 
-define_parse_endian_integer(le, int, 64)
-
-define_parse_endian_integer(le, int, 32)
-
-define_parse_endian_integer(le, int, 16)
-
-define_parse_endian_integer(le, int, 8)
+// Define function to parse fill bytes until end position is reached
+
+void
+parse_fill_bytes(size_t end_position, PState *pstate)
+{
+    while (!pstate->error_msg && pstate->position < end_position)
+    {
+        char   buffer;
+        size_t count = fread(&buffer, 1, sizeof(buffer), pstate->stream);
+
+        pstate->position += count;
+        if (count < sizeof(buffer))
+        {
+            pstate->error_msg = eof_or_error_msg(pstate->stream);
+        }
+    }
+}
+
+// Define function to validate number is same as fixed value after parse
+
+void
+parse_validate_fixed(bool same, const char *element, PState *pstate)
+{
+    if (!pstate->error_msg && !same)
+    {
+        // Error message would be easier to assemble and
+        // internationalize if we used an error struct with multiple
+        // fields instead of a const char string.
+        pstate->error_msg = "Parse: Value of element does not match value of "
+                            "its 'fixed' attribute";

Review comment:
       This is an interesting issue. The WIP wiki page description of the Runtime2 subset of DFDL doesn't cover this issue. 
   
   I believe we should distinguish parse errors, runtime SDE, and validation errors. It is often important to successfully parse data because it is "well formed" yet carries invalid values in it, if only so you can display the data, and point out to users that the values are invalid. This sort of forensic analysis of data invalidity is impossible if we refuse to parse invalid data at all. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org