Allow interior mutability for the context, read_until_with_ctx to allow ASTERIX "Extended Length Data Items"#646
Conversation
|
Note: I still get a failure (independently of my change?): |
|
Ah. I understand: I changed an error message. That's why the compile error check falls. I will have a look... |
140d973 to
7758a30
Compare
ecad1bc to
e34d40d
Compare
5b57af6 to
148df77
Compare
|
... Still working on the coverage |
|
@goto40 thanks for the PR! I haven't gone through it yet - but I'm not too worried about coverage, it's more important to me that the introduced features have tests |
|
Ok. Thank you for the info. Please let me know if I should add more info. |
src/attributes.rs
Outdated
| | [bytes_read](#bytes_read) | field | Set the field representing the number of bytes to read into a container | ||
| | [until](#until) | field | Set a predicate returning when to stop reading elements into a container | ||
| | [read_all](#read_all) | field | Read until [reader.end()] returns `true` | ||
| | [read_post_processing](#read_post_processing) | field | Code to postprocess read data (including temp values; can be used to modify the context via interior mutability) |
There was a problem hiding this comment.
Missing section for read_post_processing with examples.
There was a problem hiding this comment.
No section for until_with_ctx
There was a problem hiding this comment.
I added a section illustrating the context with interior mutability. I linked this section from the table for the attribute s until_with_ctx, writer_ctx, read_post_processing.
I am very sorry, but I somehow do not manage to get the doc test working in the CI. I cannot reproduce the (I am working on it)the trait boundVec: TryFrom is not satisfied locally... Maybe you can have a short look and give me a hint.
There was a problem hiding this comment.
Now the updated docs are available (including the doc tests passing through). I also added a link to the use case (EURCONTROL standard).
(see cargo doc --show --> deku/target/doc/deku/attributes/index.html#context_with_interior_mutability)
7c343c2 to
925013c
Compare
|
Note: once this PR is ready, I would like to squash-merge or to rebase my commits... |
|
If it helps reviewing, I could also extract a separate PR where I only change the |
TLDR; --> see "Main Changes"
Motivation: "Extended Length Data Items" consist of Arrays of data element like
{x: u32, y: u32, fx: bool}. Thefxis the control element which indicates the end of the array (fx==false/fx==0).However, user code shall not be aware of the
fxfield - it should only be used for I/O and be always correct: for writing this means to setfx=falseonly for the last element. For reading it means to readuntil fx==false. Importantly, for the programmer/user the data element look like{x: u32, y: u32}andfxis completely temporary (tempandtemp_value).Moreover, there may be an array of such elements. In this array we need access to the
fxinformation (readuntil). If thefxfield is completely temporary, you need to pass the info through the context back to the array (see exampleuntil_with_ctx) and set it in the inner element (seeread_post_processingin the example above). We also need to allow a separatectxfor the read/write case (seectxandwriter_ctx), since the array length is only known in the writer case.I made some (non-breaking) changes to
deku, which enabled me to implement the above technique (allowing an implementation of "Extended Length Data Items" of ASTERIX EUROCONTOL data structures).Main changes:
Ctx) must beCopyin some calls.It is changed to
Clone, this allows to add interior mutability in the context(like
Rc<Cell<bool>>). This is no breaking change, sinceCopyimpliesClone.until_with_ctx: likeuntil, but it also gets the context.writer_ctxfor fields: overridesctxfor the writer case - this allowsa different context value for reader and writer (the reader gets the original
ctx).read_post_processing: code which is inserted after a field isread (including a temp field). You have full context access (and you can modify
the context there).
Additional changes: