You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@daffodil.apache.org by Roger L Costello <co...@mitre.org> on 2021/02/03 14:07:05 UTC

Example of where lengthKind=endOfParent is well-suited?

Hi Folks,

Would you give an easy-to-understand, intuitive example where lengthKind=endOfParent is well-suited, please?

/Roger

Re: Example of where lengthKind=endOfParent is well-suited?

Posted by "Beckerle, Mike" <mb...@owlcyberdefense.com>.
End of parent enables saving some space for extra stored length fields, by dual-purposing an overall record length
to also provide the length of the last child item.

Consider a record with these data items in it:

quantity
price
tax (optional field)
description

Only the last is a text string and is variable length.

So this could be represented by:

<element name="recLen" type="xs:unsignedInt"
    dfdl:outputValueCalc="{ dfdl:contentLength(../record, 'bytes') }" />
<element name="record" dfdl:lengthKind="explicit" dfdl:length="{ ../recLen }">
   <complexType>
      <sequence>
        <element name="quantity" type="xs:unsignedInt"/>
        <element name="price" type="xs:decimal" dfdl:binaryNumberRep="packed" dfdl:length="6" />
        <element name="isTax" type="xs:boolean" dfdl:length="1"/>
        <element name="tax" type="xs:decimal" minOccurs="0" dfdl:binaryNumberRep="packed" dfdl:length="4"
             dfdl:occursCountKind="expression" dfdl:occursCount="{ ../isTax }"/>
         <element name="description" type="xs:string" dfdl:lengthKind="endOfParent"/>
     </sequence>
  </complexType>
</element>

Basically, if there are multiple variable-length things in the record, you get to have an overall record length at the start, which is useful for skipping past whole records without having to parse the individual items within each record, and you save on storing one length field/item within the record, as the last variable length thing doesn't need one.

So you get some useful functionality (recLen above) for no storage cost.


________________________________
From: Roger L Costello <co...@mitre.org>
Sent: Wednesday, February 3, 2021 9:07 AM
To: users@daffodil.apache.org <us...@daffodil.apache.org>
Subject: Example of where lengthKind=endOfParent is well-suited?

Hi Folks,

Would you give an easy-to-understand, intuitive example where lengthKind=endOfParent is well-suited, please?

/Roger