Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Essentially the way this is done is to do a partial read, enough to get the number of bytes, then read the rest of the data into a discriminated record.</p> <p>Something like the following in pseudo-Ada:</p> <pre><code>type Payloads is array (Payload_Sizes range &lt;&gt;) of Your_One_Byte_Payload_Type; type Data (Payload_Length : Payload_Sizes) is record Tag : Tag_Type; Payload : Payloads(1 .. Payload_Length); end record; for Data use record Tag at 0 range 0 .. 15; Payload_Length at 2 range 0 .. 15; -- Omit a rep spec for Payload end record; </code></pre> <p>Typically the compiler will locate the Payload data immediately following the last rep-spec'ed field, but you'll need to verify this with the vendor, or do some test programs. (There may be a more explicit way to specify this, and I'm open to having this answer updated if someone provides a workable approach.)</p> <p>And do <em>not</em> provide a default for the Payload_Length discriminant, that would cause instances of the record to always reserve the maximum amount of storage needed for the largest value.</p> <p>Then, in your data reading code, something along the lines of:</p> <pre><code>loop Get(Data_File, Tag); Get(Data_File, Payload_Length) declare Data_Item : Data(Payload_Length); begin Data_Item.Tag := Tag; Get(Data_File, Data_Item.Payload); Process_Data(Data_Item); end; ... exit when Whatever; end loop; </code></pre> <p>(You'll need to work out your exit criteria.)</p> <p>Data_Item will then be dynamically sized for the Payload_Length. Beware, though, if that length is odd, as padding may occur...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload