<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">

<rfc number="8710" xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902"
     docName="draft-ietf-core-multipart-ct-04" consensus="true" category="std" obsoletes=""
     updates="" submissionType="IETF" xml:lang="en" tocInclude="true"
     tocDepth="4" symRefs="true" sortRefs="true" version="3"> 

  <front>
    <title abbrev="Multipart Content-Format for CoAP">Multipart Content-Format
    for the Constrained Application Protocol (CoAP)</title>

<seriesInfo name="RFC" value="8710"/>
    <author initials="T." surname="Fossati" fullname="Thomas Fossati">
      <organization>ARM</organization>
      <address>
        <email>thomas.fossati@arm.com</email>
      </address>
    </author>
    <author initials="K." surname="Hartke" fullname="Klaus Hartke">
      <organization>Ericsson</organization>
      <address>
        <postal>
          <street>Torshamnsgatan 23</street>
          <city>Stockholm</city>
          <code>16483</code>
          <country>Sweden</country>
        </postal>
        <email>klaus.hartke@ericsson.com</email>
      </address>
    </author>
    <author initials="C." surname="Bormann" fullname="Carsten Bormann">
      <organization>Universität Bremen TZI</organization>
      <address>
        <postal>
          <street>Postfach 330440</street>
          <city>Bremen</city>
          <code>D-28359</code>
          <country>Germany</country>
        </postal>
        <phone>+49-421-218-63921</phone>
        <email>cabo@tzi.org</email>
      </address>
    </author>
    <date year="2020" month="February"/>
    <area>ART</area>
    <workgroup>CoRE</workgroup>
    <keyword>CoAP</keyword>
    <keyword>Multipart Content-Format</keyword>
    <abstract>
      <t>This memo defines application/multipart-core, an
      application-independent media type that can be used to combine
      representations of zero or more different media types (each with a
      Constrained Application Protocol (CoAP) Content-Format identifier) into a single
      representation, with minimal framing overhead.
      </t>
    </abstract>
  </front>
  <middle>


    <section anchor="introduction" numbered="true" toc="default">
      <name>Introduction</name>
      <t>
This memo defines application/multipart-core, an application-independent media
type that can be used to combine representations of zero or more different
media types (each with a CoAP Content-Format identifier <xref target="RFC7252"
format="default"/>) into a single representation, with minimal framing
overhead.
</t>
      <t>This simple and efficient binary framing mechanism can be employed to
      create application-specific message bodies that build on multiple
      already existing media types.</t>

      <t>As the name of the media type suggests, application/multipart-core
      was inspired by the multipart media types initially defined in the
      original set of MIME specifications <xref target="RFC2046"
      format="default"/> and later.  However, while those needed to focus on the
      syntactic aspects of integrating multiple representations into one
      email, transfer protocols providing full data transparency such as CoAP
      as well as readily available encoding formats such as the Concise Binary
      Object Representation (CBOR) <xref target="RFC7049" format="default"/>
      shift the focus towards the intended use of the combined
      representations.  In this respect, the basic intent of the
      application/multipart-core media type is like that of multipart/mixed
      (<xref sectionFormat="of" section="5.1.3" target="RFC2046"
      format="default"/>); however, the semantics are relaxed to allow for
      both ordered and unordered collections of media types. </t>

      <ul empty="true">
<li>Historical Note: Experience with multipart/mixed in email has shown that
recipients that care about order of included body parts will process them in
the order they are listed inside multipart/mixed, and recipients that don't
care about the order will ignore it anyway.  The media type multipart/parallel
that was intended for unordered collections didn't deploy.
</li>
      </ul>
<t>
The detailed semantics of the representations are refined by the context
established by the application in the accompanying request parameters, e.g.,
the resource URI and any further options (header fields), but three usage
scenarios are envisioned:</t>




      <t>In one case, the individual representations in an application/multipart-core message body
occur in a sequence, which may be employed by an application where
such a sequence is natural, e.g., for a number of audio snippets in
various formats to be played out in that sequence or search results
returned in order of relevance.</t>

      <t>In another case, an application may be more interested in a bag of
      representations (which are distinguished by their Content-Format
      identifiers), such as an audio snippet and a text representation
      accompanying it.  In such a case, the sequence in which these occur may
      not be relevant to the application.  This specification adds the option
      of substituting a null value for the representation of an optional part,
      which indicates that the part is not present.</t>
      <t>A third common situation only has a single representation in the
      sequence, and the sender selects just one of a set of formats
      possible for this situation.  This kind of union "type" of formats may
      also make the presence of the actual representation optional, the
      omission of which leads to a zero-length array.</t>

      <t>Where these rules are not sufficient, an application might still use
      the general format defined here but register a new media type and an
      associated Content-Format identifier to associate the representation
      with these more specific semantics instead of using the
      application/multipart-core media type.</t>
      <t>Also, future specifications might want to define rough equivalents
      for other multipart media types with specific semantics not covered by
      the present specification, such as multipart/alternative (<xref
      sectionFormat="of" section="5.1.4" target="RFC2046"/>), where several
      alternative representations are provided in the message body, but only
      one of those is to be selected by the recipient for its use (this is
      less likely to be useful in a constrained environment that has
      facilities for pre-flight discovery).</t>
      <section anchor="requirements-language" numbered="true" toc="default">
        <name>Requirements Language</name>


        <t>
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
    "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
    NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>",
    "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are
    to be interpreted as described in BCP&nbsp;14 <xref target="RFC2119"/>
    <xref target="RFC8174"/> when, and only when, they appear in all capitals,
    as shown here.
        </t>



      </section>
    </section>
    <section anchor="encoding" numbered="true" toc="default">
      <name>Multipart Content-Format Encoding</name>
      <t>A representation of media type application/multipart-core contains a collection of
zero or more representations, each along with their respective Content-Format.</t>
      <t>The collection is encoded as a CBOR <xref target="RFC7049"
      format="default"/> array with an even number of elements.  Counting from
      zero, the odd-numbered elements are a byte string containing a
      representation or the value "null" (if an optional part is
      indicated as not given).  The (even-numbered) element preceding each of
      these is an unsigned integer specifying the Content-Format ID of the
      representation following it.</t>
      <t>For example, a collection containing two representations, one with
Content-Format ID 42 and one with Content-Format ID 0, looks like this
in CBOR diagnostic notation:</t>
<artwork><![CDATA[[42, h'0123456789abcdef', 0, h'3031323334']]]>
</artwork>


      <t>For illustration, the structure of an application/multipart-core representation can
be described by the Concise Data Definition Language (CDDL) <xref target="RFC8610" format="default"/> specification in <xref target="mct-cddl" format="default"/>:</t>
      <figure anchor="mct-cddl">
        <name>CDDL for application/multipart-core</name>
        <artwork type="cddl" name="" align="left" alt=""><![CDATA[
multipart-core = [* multipart-part]
multipart-part = (type: uint .size 2, part: bytes / null)
]]></artwork>
      </figure>
      <t>This format is intended as a strict specification: an implementation
<bcp14>MUST</bcp14> stop processing the representation if there is a CBOR
well-formedness error, a deviation from the structure defined above,
or any residual data left after processing the CBOR data item.
(This generally means the representation is not processed at
all unless some streaming processing has already happened.)</t>
    </section>
    <section anchor="usage-example-observing-resources" numbered="true" toc="default">
      <name>Usage Example: Observing Resources</name>
      <t>This section illustrates a less obvious example for using
application/multipart-core: combining it with observing a resource
<xref target="RFC7641" format="default"/> to handle pending results.</t>


      <t>When a client registers to observe a resource for which no
      representation is available yet, the server may send one or more 2.05
      (Content) notifications that indicate the lack of an actual
      representation. Later on, when one becomes available, the server will
      send the first actual 2.05 (Content) or 2.03 (Valid) notification.

A diagram depicting possible resulting sequences of notifications, identified
by their respective response code, is shown in <xref target="fig-sequence"
format="default"/>.</t>
      <figure anchor="fig-sequence">
        <name>Sequence of Notifications</name>
        <artwork name="" type="" align="left" alt=""><![CDATA[
      __________       __________       __________
     |          |     |          |     |          |
---->|   2.05   |---->|  2.05 /  |---->|  4.xx /  |
     |  Pending |     |   2.03   |     |   5.xx   |
     |__________|     |__________|     |__________|
        ^   \ \          ^    \           ^
         \__/  \          \___/          /
                \_______________________/
]]></artwork>
      </figure>
      <t>The specification of the Observe option requires that all
notifications carry the same Content-Format.  The
application/multipart-core media type can be used to provide that
Content-Format, e.g., by carrying an empty list of representations in the
case marked as "Pending" in <xref target="fig-sequence" format="default"/> and carrying a single
representation specified as the target Content-Format in the case in
the middle of the figure.</t>
    </section>
    <section anchor="implementation-hints" numbered="true" toc="default">
      <name>Implementation Hints</name>
      <t>This section describes the serialization for readers that may be new
to CBOR.  It does not contain any new information.</t>
      <t>An application/multipart-core representation carrying no
representations is represented by an empty CBOR array, which is
serialized as a single byte with the value 0x80.</t>
      <t>An application/multipart-core representation carrying a single
representation is represented by a two-element CBOR array, which is
serialized as 0x82 followed by the two elements.  The first element is
an unsigned integer for the Content-Format value, which is represented as described in
<xref target="tbl-integer" format="default"/>.  The second element is the object as a byte string,
which is represented as a length as described in <xref target="tbl-length" format="default"/>
followed by the bytes of the object.</t>
      <table anchor="tbl-integer" align="center">
        <name>Serialization of Content-Format</name>
        <thead>
          <tr>
            <th align="left">Serialization</th>
            <th align="left">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td align="left">0x00..0x17</td>
            <td align="left">0..23</td>
          </tr>
          <tr>
            <td align="left">0x18 0xnn</td>
            <td align="left">24..255</td>
          </tr>
          <tr>
            <td align="left">0x19 0xnn 0xnn</td>
            <td align="left">256..65535</td>
          </tr>
        </tbody>
      </table>
      <table anchor="tbl-length" align="center">
        <name>Serialization of Object Length</name>
        <thead>
          <tr>
            <th align="left">Serialization</th>
            <th align="left">Length</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td align="left">0x40..0x57</td>
            <td align="left">0..23</td>
          </tr>
          <tr>
            <td align="left">0x58 0xnn</td>
            <td align="left">24..255</td>
          </tr>
          <tr>
            <td align="left">0x59 0xnn 0xnn</td>
            <td align="left">256..65535</td>
          </tr>
          <tr>
            <td align="left">0x5a 0xnn 0xnn 0xnn 0xnn</td>
            <td align="left">65536..4294967295</td>
          </tr>
          <tr>
            <td align="left">0x5b 0xnn .. 0xnn (8 bytes)</td>
            <td align="left">4294967296..</td>
          </tr>
        </tbody>
      </table>
      <t>For example, a single text/plain object (Content-Format 0) of value
"Hello World" (11 characters) would be serialized as follows:</t>
<artwork><![CDATA[0x82 0x00 0x4b H e l l o 0x20 W o r l d]]>
</artwork>

      <t>In effect, the serialization for a single object is done by prefixing
      the object with information that there is one object (here: 0x82),
      information about its Content-Format (here: 0x00), and information
      regarding its length (here: 0x4b).</t>

      <t>For more than one representation included in an
      application/multipart-core representation, the head of the CBOR array is
      adjusted (0x84 for two representations, 0x86 for three, etc.), and the
      sequences of Content-Format and embedded representations follow.</t>
      <t>For instance, the example from <xref target="encoding"
      format="default"/> would be serialized as follows:</t>
<artwork><![CDATA[0x84 (*) 0x182A 0x48 0x0123456789ABCDEF (+) 0x00 0x45 0x3031323334]]>
</artwork>

      <t>where (*) marks the start of the information about the first
      representation (Content-Format 42, byte string length 8), and (+) marks
      the start of the second representation (Content-Format 0, byte string
      length 5).</t>
    </section>

    <section anchor="IANA" numbered="true" toc="default">
      <name>IANA Considerations</name>
      <section anchor="registration-of-media-type-applicationmultipart-core" numbered="true" toc="default">
        <name>Registration of Media Type application/multipart-core</name>
        <t>IANA has registered the following media type <xref target="RFC6838" format="default"/>:</t>
        <dl newline="false" spacing="normal">
          <dt>Type name:</dt>
          <dd>
  application</dd>
          <dt>Subtype name:</dt>
          <dd>
  multipart-core</dd>
          <dt>Required parameters:</dt>
          <dd>
  N/A</dd>
          <dt>Optional parameters:</dt>
          <dd>
  N/A</dd>
          <dt>Encoding considerations:</dt>
          <dd>
  binary</dd>
          <dt>Security considerations:</dt>
          <dd>
  See the Security Considerations section of RFC 8710.</dd>
          <dt>Interoperability considerations:</dt>
          <dd>
  N/A</dd>
          <dt>Published specification:</dt>
          <dd>
  RFC 8710</dd>
          <dt>Applications that use this media type:</dt>
          <dd>
  Applications that need to combine representations of zero or more different
media types into one, e.g., EST over secure CoAP (EST-CoAP) <xref target="I-D.ietf-ace-coap-est" format="default"/></dd>
          <dt>Fragment identifier considerations:</dt>
          <dd>
  The syntax and semantics of fragment identifiers specified for
  application/multipart-core are as specified for application/cbor. (At
  publication of this document, there is no fragment identification syntax
  defined for application/cbor.)</dd>
          <dt>Additional information:<br/></dt>
          <dd>
            <dl newline="false" spacing="normal">
              <dt>Deprecated alias names for this type:</dt>
              <dd>N/A</dd>
              <dt>Magic number(s):</dt>
              <dd>N/A</dd>
              <dt>File extension(s):</dt>
              <dd>N/A</dd>
              <dt>Macintosh file type code(s):</dt>
              <dd>N/A</dd>
            </dl>
          </dd>
          <dt>Person &amp; email address to contact for further information:</dt>
          <dd>
  iesg@ietf.org</dd>
          <dt>Intended usage:</dt>
          <dd>
  COMMON</dd>
          <dt>Restrictions on usage:</dt>
          <dd>
  N/A</dd>
          <dt>Author:</dt>
          <dd>
  CoRE WG</dd>
          <dt>Change controller:</dt>
          <dd>
  IESG</dd>
          <dt>Provisional registration? (standards tree only):</dt>
          <dd>
  no</dd>
        </dl>
      </section>
      <section anchor="registration-of-a-content-format-identifier-for-applicationmultipart-core" numbered="true" toc="default">
        <name>Registration of a Content-Format Identifier for application/multipart-core</name>
        <t>IANA has registered the following Content-Format in the "CoAP
        Content-Formats" subregistry within the "Constrained RESTful
        Environments (CoRE) Parameters" registry:</t>
        <table align="center">
        <name>Addition to "CoAP Content-Formats" Registry</name>
          <thead>
            <tr>
              <th align="left">Media Type</th>
              <th align="left">Encoding</th>
              <th align="left">ID</th>
              <th align="left">Reference</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td align="left">application/multipart-core</td>
              <td align="left">-</td>
              <td align="left">62</td>
              <td align="left">RFC 8710</td>
            </tr>
          </tbody>
        </table>
      </section>
    </section>
    <section anchor="Security" numbered="true" toc="default">
      <name>Security Considerations</name>

<t>The security considerations of <xref target="RFC7049" format="default"/>
apply.  In particular, resource exhaustion attacks may employ large values for
the byte string size fields or employ deeply nested structures of recursively
embedded application/multipart-core representations.</t>
    </section>
  </middle>
  <back>

<displayreference target="I-D.ietf-ace-coap-est" to="EST-COAPS"/>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>

<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7049.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7252.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
      </references>
      <references>
        <name>Informative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2046.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7641.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8610.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6838.xml"/>
<xi:include href="https://www.rfc-editor.org/refs/bibxml3/reference.I-D.ietf-ace-coap-est.xml"/>

      </references>
    </references>
    <section numbered="false" anchor="acknowledgements" toc="default">

      <name>Acknowledgements</name>
      <t>Most of the text in this document is from earlier contributions by
      two of the authors, <contact fullname="Thomas Fossati"/> and <contact
      fullname="Klaus Hartke"/>.  This earlier work was reorganized in this document based on the
      requirements in <xref target="I-D.ietf-ace-coap-est" format="default"/>
      and discussions with <contact fullname="Michael Richardson"/>,
      <contact fullname="Panos Kampanis"/>, and <contact fullname="Peter van
      der Stok"/>.</t>


    </section>
  </back>

</rfc>
