|
| 1 | +# Extend with new variants and features |
| 2 | + |
| 3 | +The following is a brief list of guiding principles to extend `intel_fw`. |
| 4 | +As a library, it should to adhere to those as requirements in order to provide |
| 5 | +guarantees to applications working with it. Generally, it should follow the |
| 6 | +[Rust API guidelines](https://rust-lang.github.io/api-guidelines/about.html). |
| 7 | + |
| 8 | +## Do not panic! |
| 9 | + |
| 10 | +Parsing firmware means looking for and acting on offsets and sizes frequently, |
| 11 | +and they always need to be checked to stay within the bounds of the given data. |
| 12 | +Never `unwrap()`, which means an _intentional panic_, in case something cannot |
| 13 | +be found, read, or recognized. Instead, return instances of `Self` for structs, |
| 14 | +wrapped in a `Result<Self, CustomError>` or possibly `Option<Self>`. |
| 15 | + |
| 16 | +## Continuous parsing |
| 17 | + |
| 18 | +There are circumstances under which a parser encounters an issue. It can be |
| 19 | +that offsets do not make sense, magic bytes (struct markers) are not as they |
| 20 | +were expected, or new variants are found with samples not encountered before. |
| 21 | +In those situations, it is desirable to follow a best-effort strategy. I.e., |
| 22 | +when there is still remaining data that could be parsed, keep going. |
| 23 | + |
| 24 | +## Let apps provide feedback |
| 25 | + |
| 26 | +In other words, **let the consuming application take care** of taking the result |
| 27 | +apart. Nested structures mean that whenever a node in a graph turns into an |
| 28 | +`Error` or `None`, other nodes beside it may still provide useful information. |
| 29 | +That information helps the user of an app to understand the context and possibly |
| 30 | +report what they are facing or look into the issue themselves. |
| 31 | + |
| 32 | +## Errors and context |
| 33 | + |
| 34 | +In order to make sense of an error, context is important. During development, it |
| 35 | +can be helpful to print out information right within a specific parser. However, |
| 36 | +a final app is typically not run in development mode, but as a release. In that |
| 37 | +moment, semantic errors will help to identify possible problems. Include offsets |
| 38 | +and sizes (or `Range`s) for the application to tell exactly where the problem |
| 39 | +is, and it can choose to e.g. dump a contextual hex view on the data. |
0 commit comments