<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
    <!ENTITY rfc3339 PUBLIC ''
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3339.xml'>
    <!ENTITY rfc3629 PUBLIC ''
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3629.xml'>
    <!ENTITY rfc5905 PUBLIC ''
      'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5905.xml'>
      ]>      

<rfc category="exp" ipr="trust200902" docName="draft-ruoska-encoding-06">

<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>

<?rfc toc="yes" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc iprnotified="no" ?>
<?rfc strict="yes" ?>

  <front>
    <title>Ruoska Encoding</title>
    <author initials="JP" surname="Makela" fullname="Jukka-Pekka Makela">
      <organization/>
      <address>
        <postal>
          <street></street>
          <city>Janakkala</city>
          <region>Tavastia Proper</region>
          <code></code>
          <country>Finland</country>
        </postal>
      </address>
    </author>
    <date/>
    <abstract>
      <t>
        This document describes hierarchically structured binary encoding format called Ruoska Encoding (later RSK). The main design goals are minimal resource usage, well defined structure with good selection of widely known data types, and still extendable for future usage.
      </t>
      <t>
        The main benefit when compared to non binary hierarchically structured formats like XML is simplicity and minimal resource demands. Even basic XML parsing is time and memory consuming operation.
      </t>
      <t>
        When compared to other binary formats like BER encoding of ASN.1 the main benefit is simplicity. ASN.1 with many different encodings is complex and even simple implementation needs a lot of effort. RSK is also more efficient than BER.
      </t>
    </abstract>
  </front>

  <middle>   
    <section anchor="document_structure" title="Document Structure">
      <t>
        The principal entity of RSK document is frame. Two main classes of frames exist. Meta Frames to define structure and Data Frames to hold actual payload data.
      </t>
      <t>
        All frames start with Leading Byte which defines frame type and some type depended instructions. Some meta frames and all data frames can be tagged with an identifier. Identifier type is defined in Leading Byte. If identifier exists it is placed right after the Leading Byte. In Data Frames payload comes after identifier. Meta Frames may also have payload or special fields or both. Data type of the payload is defined by frame type and type depended instructions. All frame types are explained in <xref target="frame_definitions" />.
      </t>
      <t>
        RSK document is structured as finite tree. The tree is rooted to Begin Frame. After the rooting Begin Frame follows data frames as leafs and Begin – End Frame pairs as branches. Branches may contain data frames as leafs and again Begin – End Frame pairs as sub branches. Null and Array Frames are considered as data frames here.
      </t>
      <t>
        RSK document always ends with End Frame. Use of End Frame is two fold. It is used to return from branch to parent level and terminate the document. So document must always start with Begin Frame and end with End Frame. Root nesting level 0 must not contain any other than rooting Begin and terminating End Frames. Between root Begin and terminating End Frame is nesting level 1. Nesting level 1 may contain data frames or branches or both.
      </t>
      <figure anchor="structure" title="Tree Structure">
        <artwork><![CDATA[
Example Tree Structure

0  1  2  Nesting levels
|  |  |
Begin[id:tractor]                              Begin Frame at level 0
|  String[id:manufacturer, value:Valmet]         Leaf at level 1
|  String[id:model, value:33D]                   Leaf at level 1
|  Begin[id:engine]                              Branch at level 1
|  |  String[id:fuel, value:Diesel]                Leaf at level 2
|  |  UInt8[id:horsepower, value:37]               Leaf at level 2
|  End                                           Ending branch
End                                            Terminating at level 0
]]>
        </artwork>
      </figure>
      <t>
      </t>
      <section anchor="endianness" title="Endianness">
        <t>
          Big-endian networking byte order is used. Endianness applies to all integer and floating point numbers. This includes payload of any data frames like Integer, Float, and Timestamp and 16-bits wide integer identifier values and also meta data fields like length of payload. Canonical network byte order is fully described in RFC791, Appendix B.
        </t>
      </section>
      <section anchor="string_encoding" title="String Encoding">
        <t>
          All strings are UTF-8 encoded. This applies to string identifiers and payload of String, Date, DateTime and DateTimeMillis Frames.
        </t>
        <t>
          Implementations using any of frame types above or String Identifier or both must be able to validate UTF-8 encoding. On writing phase UTF-8 encoding violation must be handled as error condition. If UTF-8 encoding fails on reading phase warning must be raised and let user decide to continue reading or not. More information about UTF-8 see <xref target="RFC3629">RFC 3629</xref>.
        </t>
      </section>
    </section>
    <section anchor="frame_definitions" title="Frame Definitions">
      <t>        
        As mentioned earlier the principal entity of RSK is frame. This section explains all frame types and type dependent special instructions in detail.
      </t>
      <section anchor="leading_byte" title="Leading Byte">
        <t>        
          All frames start with Leading Byte. Leading Byte determines frame type and type dependent instructions. The most significant bit is reserved for Extended Frames which may be introduced in later versions. See <xref target="extended_frame" /> for details.
        </t>
        <t>
          Leading Byte is presented as bit array where left-most bit is the most significant bit. MSB 0 bit numbering scheme is used with two exceptions. Left-most bit is reserved for Extended Frame and thus marked as 'X' for all Leading Byte definitions. Also some bits are marked with 'R' meaning that they are reserved for later use and must not be set in this version.
        </t>
        <t>
          Leading Byte is followed by frame type dependent fields like Identifier or Payload or both. These fields are presented as labeled byte blocks with possible lengths in bytes, kilobytes like 64k, or gigabytes like 4G.
        </t>
        <figure anchor="leading_byte_figure" title="Leading Byte">
        <artwork><![CDATA[
   Leading Byte    Example Field   Example Payload
+-+---------+---+ +-------------+ +---------------+
|X|1|2|3|4|5|6|7| |   4 or 8    | |    0 - 64k    |
+-+---------+---+ +-------------+ +---------------+
 | \       / \ /
 |   \   /    | Frame type dependent instructions bits 
 |     |
 |     | Frame type bits
 |
 | Extended frame bit
 ]]>
        </artwork>
      </figure>
          <t>
            <list style="hanging">
              <t hangText="Example Field:">Example of possible frame type dependent byte field. 4 or 8 means that field can be 4 or 8 bytes long. Actual length can be determined by frame type, instruction bits, or some other field.</t>
              <t hangText="Example Payload:">Example of possible frame type dependent payload field. 0 - 64k means that field can be from 0 to 65535 bytes long. Actual length can be determined by frame type, instruction bits, or some other field.</t>
              <t hangText="Frame type dependent instructions bits:">These bits determine type dependent instructions. See specific frame type sections for details. For most frame types these are used to define identifier type.</t>
              <t hangText="Frame type bits:">This bit field determines frame type. Values are defined in <xref target="frame_type_table" />.</t>
              <t hangText="Extended frame bit:">Extended frame bit. See <xref target="extended_frame" /> for details.</t>
            </list>
          </t>  
      </section>
      <section title="Meta Frames">
        <t>
          Meta Frames define document structure. 
        </t>
          <section title="Null Frame">
          <t>
            Null Frame can be tagged with an identifier but does not contain any payload data.
          </t>
          <figure anchor="null_figure" title="Null Frame">
            <artwork>
<![CDATA[
   Leading Byte   Identifier
+-+---------+---+ +---------+
|X|1|2|3|4|5|6|7| | 0 - 256 |
+-+---------+---+ +---------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="Begin Frame">
          <t>
            Document and branches start with Begin Frame. Begin Frame may have an identifier. More details about tree structure see <xref target="document_structure" />.
          </t>
          <figure anchor="begin_figure" title="Begin Frame">
            <artwork>
<![CDATA[
  Leading Byte     Identifier
+-+---------+---+ +----------+
|X|1|2|3|4|5|6|7| | 0 - 256  |
+-+---------+---+ +----------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>          
        </section>

        <section title="End Frame">
          <t>
            End Frame is used to return from branch to parent level in tree structure and also used to terminate a document. More details about tree structure see <xref target="document_structure" />.
          </t>
          <figure anchor="end_figure" title="End Frame">
            <artwork>
<![CDATA[
  Leading Byte                 
+-+---------+---+               
|X|1|2|3|4|5|R|R|               
+-+---------+---+              
   \       /      
     \   /                
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section anchor="array_frame" title="Array Frame">
          <t>
            Array column in Frame Type Table in <xref target="frame_type_table" /> defines frame types which can be enclosed into a array.
          </t>
          <t>
            Array itself and each item may have identifiers. Array identifier is defined in Leading Byte. All items have identifier of same type and all items are same frame type. Frame and identifier type for all items are defined by CLB (Common Leading Byte).
          </t>
          <t>
            Array capacity is defined by selecting corresponding Array Frame type. See <xref target="frame_type_table" /> for details.
          </t>
          <figure anchor="array_figure" title="Array Frame">
            <artwork>
<![CDATA[
  Leading Byte    Identifier   CLB    Count          Items
+-+---------+---+ +---------+ +---+ +-------+ +-------+ +-------+
|X|1|2|3|4|5|6|7| | 0 - 256 | | 1 | | 1/2/4 | | Item1 | | Item2 | ...
+-+---------+---+ +---------+ +---+ +-------+ +-------+ +-------+
   \       / \ /                              
     \   /    | Id bits                       
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">Array identifier. See <xref target="identifiers" /> for details.</t>
              <t hangText="CLB:">Common Leading Byte determines type of items and type of item identifiers.</t>
              <t hangText="Count:">8, 16, or 32-bits wide unsigned integer telling item count. Width of Count field depends on array type, see <xref target="frame_type_table" /> for details.</t>
              <t hangText="Items:">Array of items.</t>              
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
          <t>
            Array items are stored right after Count field. Items may have Identifier.
          </t>
          <figure anchor="array_item_figure" title="Array Item">
            <artwork>
<![CDATA[
  Identifier     Item Payload
+------------+ +--------------+
|   0 - 256  | |    1 - 4G    |
+------------+ +--------------+
]]>
            </artwork>
          </figure>          
        </section>
      </section>
      <section anchor="data_frames" title="Data Frames">
        <t>
          Data Frames are collection of widely used data types. There are frames for boolean, integer and floating point numbers, UTF-8 encoded strings, dates, and timestamps. There is also frame for raw binary data. All data frames can be tagged with an identifier.
        </t>
        <section title="Boolean Frame">
          <t>
            Boolean value (False/True) is defined by choosing corresponding Boolean Frame type. See <xref target="frame_type_table" />.
          </t>
          <figure anchor="boolean_figure" title="Boolean Frame">
            <artwork>
<![CDATA[
   Leading Byte    Identifier  
+-+---------+---+ +----------+
|X|1|2|3|4|5|6|7| | 0 - 256  |
+-+---------+---+ +----------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="Integer Frames">
          <t>
            Wide range of integer types are supported. Integer width and signedness are defined by choosing corresponding Integer Frame type. Signed integers are presented in two's complement notation.
          </t>
          <t>
            Integer payload is always stored in big-endian format. See <xref target="endianness" /> for details.
          </t>
          <figure anchor="integer_figure" title="Integer Frames">
            <artwork>
<![CDATA[
   Leading Byte    Identifier       Payload
+-+---------+---+ +----------+ +--------------+
|X|1|2|3|4|5|6|7| | 0 - 256  | |  1,2,4 or 8  |
+-+---------+---+ +----------+ +--------------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Payload:">Payload integer value.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="Float Frames">
          <t>
             Floating point number precision is defined by choosing corresponding Float Frame type. See <xref target="frame_type_table" /> for frame types. Floats are presented in IEEE754 standard format and endianness is big-endian. See <xref target="endianness" /> for details.
          </t>
          <figure anchor="float_figure" title="Float Frames">
            <artwork>
<![CDATA[
   Leading Byte    Identifier      Payload
+-+---------+---+ +----------+ +------------+
|X|1|2|3|4|5|6|7| | 0 - 256  | |  2,4 or 8  |
+-+---------+---+ +----------+ +------------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Payload:">Payload float value.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="String Frame">
          <t>
            String Frame can hold UTF-8 encoded string. If implementation supports String Frame it must be able to validate UTF-8 encoding. See <xref target="string_encoding" /> for details.
          </t>
          <t>
            Frame capacity is defined by selecting corresponding String Frame type. See <xref target="frame_type_table" /> for details.
          </t>          
          <figure anchor="string_figure" title="String Frame">
            <artwork>
<![CDATA[
   Leading Byte    Identifier   Length      Payload
+-+---------+---+ +----------+ +-------+ +-----------+
|X|1|2|3|4|5|6|7| | 0 - 256  | | 1/2/4 | |  0 - 4G   |
+-+---------+---+ +----------+ +-------+ +-----------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Length:">8, 16, or 32-bits wide unsigned integer telling length of string in bytes. Depends on String Frame type, see <xref target="frame_type_table" /> for details.</t>
              <t hangText="Payload:">UTF-8 encoded string.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="Binary Frame">
          <t>
            Binary Frame holds arbitrary binary data.
          </t>
          <t>
            Frame capacity is defined by selecting corresponding Binary Frame type. See <xref target="frame_type_table" /> for details.
          </t>
          <figure anchor="binary_figure" title="Binary Frame">
            <artwork>
<![CDATA[
   Leading Byte    Identifier   Length      Payload
+-+---------+---+ +----------+ +-------+ +-----------+
|X|1|2|3|4|5|6|7| | 0 - 256  | | 1/2/4 | |  0 - 4G   |
+-+---------+---+ +----------+ +-------+ +-----------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Length:">8, 16, or 32-bits wide unsigned integer telling length of payload in bytes. Depends on Binary Frame type, see <xref target="frame_type_table" /> for details.</t>
              <t hangText="Payload:">Arbitrary binary data.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="DateTime Frames">
          <t>
            DateTime Frames hold date or date and time in UTC timescale as UTF-8 encoded string. String formats are compatible with <xref target="RFC3339">RFC 3339</xref>.
          </t>
          <t>
            If implementation supports any of DateTime Frames it must be able to validate UTF-8 encoding. See <xref target="string_encoding" /> for details. Besides string formats must be validated but date data validation is not part of RSK. On writing phase illegal string format must be handled as error. On reading phase string format violation can be handled by rising warning and let user decide continue reading or not.
          </t>
          <t>
            Date frame types and corresponding date string formats:
              <list style="hanging">
                <t hangText="Date:">YYYY-MM-DD</t>
                <t hangText="DateTime:">YYYY-MM-DDTHH:MM:SSZ</t>
                <t hangText="DateTimeMillis:">YYYY-MM-DDTHH:MM:SS.SSSZ</t>
              </list>
          </t>
          <figure anchor="datetime_figure" title="DateTime Frame">
            <artwork>
<![CDATA[
   Leading Byte    Identifier   Date/DateTime/DateTimeMillis
+-+-------+-+---+ +----------+ +----------------------------+
|X|1|2|3|4|5|6|7| | 0 - 256  | |         10/20/24           | 
+-+-------+-+---+ +----------+ +----------------------------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Date/DateTime/DateTimeMillis:">Date, DateTime, or DateTimeMillis string depends of date frame type.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="NTP Short Frame">
          <t>
            NTP Short Frame holds NTP Short Format compatible timestamp. See <xref target="RFC5905">RFC 5905</xref> for details.
          </t>
          <figure anchor="ntp_short_figure" title="NTP Short Format Frame">
            <artwork>
<![CDATA[
   Leading Byte    Identifier   Seconds   Fraction
+-+-------+-+---+ +----------+ +-------+ +--------+
|X|1|2|3|4|5|6|7| | 0 - 256  | |   2   | |   2    |
+-+-------+-+---+ +----------+ +-------+ +--------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Seconds:">16-bits unsigned integer telling seconds.</t>
              <t hangText="Fraction:">16-bits unsigned integer holding fractions of second.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="NTP Timestamp Frame">
          <t>
            NTP Timestamp Frame holds NTP Timestamp Format compatible timestamp. See <xref target="RFC5905">RFC 5905</xref> for details.
          </t>
          <figure anchor="ntp_timestamp_figure" title="NTP Timestamp Format Frame">
            <artwork>
<![CDATA[
   Leading Byte    Identifier   Seconds   Fraction
+-+-------+-+---+ +----------+ +-------+ +--------+
|X|1|2|3|4|5|6|7| | 0 - 256  | |   4   | |   4    |
+-+-------+-+---+ +----------+ +-------+ +--------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Seconds:">32-bits unsigned integer telling seconds.</t>
              <t hangText="Fraction:">32-bits unsigned integer holding fractions of second.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="NTP Date Frame">
          <t>
            NTP Date Frame holds NTP Date Format compatible date. See <xref target="RFC5905">RFC 5905</xref> for details.
          </t>
          <figure anchor="ntp_date_figure" title="NTP Date Format Frame">
            <artwork>
<![CDATA[
   Leading Byte    Identifier   Era   Era Offset   Fraction
+-+-------+-+---+ +----------+ +---+ +----------+ +--------+
|X|1|2|3|4|5|6|7| | 0 - 256  | | 4 | |    4     | |   8    |
+-+-------+-+---+ +----------+ +---+ +----------+ +--------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>          
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Era:">32-bits signed integer telling the era of timestamp. See <xref target="RFC5905">RFC 5905</xref> for era definitions.</t>
              <t hangText="Offset:">32-bits unsigned integer holding number of seconds since beginning of the Era.</t>
              <t hangText="Fraction:">64-bits unsigned integer holding fractions of second.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
        <section title="RSK Date Frame">
          <t>
            RSK Date is optimized version of NTP Date Format defined in <xref target="RFC5905">RFC 5905</xref>.
          </t>
          <t>
            Differences with NTP Date Format
            <list style="hanging">
              <t hangText="Width of Era field:">NTP Date Format has 32-bits wide Era field. Here Era is only 8-bits wide. Interpretation is same but with narrowed range. Epoch is same so Era 0 starts at 1900-01-01 00:00:00 UTC like in NTP Date Format.</t>
              <t hangText="Width of Fraction Field:">NTP Date Format uses 64-bits wide Fraction field. Here fraction is only 16-bits wide and thus capable to 16 microsecond resolution.</t>
            </list>
          </t>
          <figure anchor="rsk_date_figure" title="RSK Date Frame">
            <artwork>
<![CDATA[
   Leading Byte    Identifier   Era   Era Offset   Fraction
+-+-------+-+---+ +----------+ +---+ +----------+ +--------+
|X|1|2|3|4|5|6|7| | 0 - 256  | | 1 | |    4     | |   2    |
+-+-------+-+---+ +----------+ +---+ +----------+ +--------+
   \       / \ /
     \   /    | Id bits
       |
       | Type bits
]]>
            </artwork>
          </figure>
          <t>
            <list style="hanging">
              <t hangText="Identifier &amp; Id bits:">See <xref target="identifiers" /> for details.</t>
              <t hangText="Era:">8-bit signed integer telling the era of timestamp. See <xref target="RFC5905">RFC 5905</xref> for era definitions.</t>
              <t hangText="Offset:">32-bit unsigned integer holding number of seconds since beginning of the Era.</t>
              <t hangText="Fraction:">16-bit unsigned integer holding fractions of second.</t>
              <t hangText="Type bits:">See <xref target="frame_type_table" />.</t>
            </list>
          </t>
        </section>
      </section>
      <section anchor="extended_frame" title="Extended Frames">
        <t>
          Extended Frame is concept to introduce new structures and data types in future versions of RSK. The most significant bit in Leading Byte is reserved for Extended Frames. In this version Extended bit must not be set when writing a RSK document. If Extended Frame is discovered on reading phase it must be handles as error in this version.
        </t>          
      </section>
    </section>
    <section anchor="identifiers" title="Identifiers">
      <t>
        All data frames and some of the meta frames can be tagged with an identifier. Identifier can be defined as 8 or 16-bit wide unsigned integer or as length-prefixed UTF-8 encoded string. If identifier is not needed it can be set to Null.
      </t>
      <t>
        Frame's Leading Byte tells type of identifier. Identifier bytes are placed immediately after the Leading Byte. In case of integer identifier there is one or two bytes depending on selected integer identifier type. String identifier can take up to 256 bytes. See following sections for details.
      </t>
      <section title="Identifier Types in Leading Byte">
        <t>
          Two least significant bits of Leading Byte are reserved for Id bits in all frame types which can be tagged with an identifier.
        </t>
        <figure anchor="identifier_types_figure" title="Identifier Types">
          <artwork>
<![CDATA[
  Leading Byte     Identifier
+-+---------+---+ +----------+
|X|1|2|3|4|5|6|7| | 0 - 256  |
+-+---------+---+ +----------+
             \ /
              | Id bits
]]>
          </artwork>
        </figure>
        <t>
          Id bits values and identifier types:
          <list style="hanging">
            <t hangText="00">Null Identifier. See <xref target="null_identifier"/>.</t>
            <t hangText="01">8-bits wide Integer Identifier. See <xref target="integer_identifier"/>.</t>
            <t hangText="10">16-bits wide Integer Identifier. See <xref target="integer_identifier"/>.</t>
            <t hangText="11">String Identifier. See <xref target="string_identifier"/></t>
          </list>
        </t>
      </section>
      <section anchor="null_identifier" title="Null Identifier">
        <t>
          Some frames in a document may not need identifier so it can be left empty by setting it Null in Leading Byte.
        </t>
      </section>
      <section anchor="integer_identifier" title="Integer Identifiers">
        <t>
          Integer identifier types are 8 or 16-bits wide unsigned integers. Integer identifiers are presented in big-endian format. See <xref target="endianness" /> for details.
        </t>
        <figure anchor="integer_id_figure" title="Integer Identifier">
          <artwork>
<![CDATA[
  Leading Byte      Uint8           Uint16
+---------------+ +-------+      +----------+
|X|1|2|3|4|5|6|7| |   1   |  OR  |    2     |
+---------------+ +-------+      +----------+
                  |                         |
                  \---Integer Identifier ---/

]]>
          </artwork>
        </figure>
      </section>
      <section anchor="string_identifier" title="String Identifier">
        <t>
          String identifier is length-prefixed and UTF-8 encoded. Length is presented by one byte as 8-bits wide unsigned integer at the beginning of identifier field. String identifier itself can be 0 - 255 bytes long.
        </t>
        <t>
          If implementation supports string identifiers it must be able to validate UTF-8 encoding. See <xref target="string_encoding" /> for details.
        </t>        
        <figure anchor="string_id_figure" title="String Identifier">
          <artwork>
<![CDATA[
  Leading Byte      Length     UTF-8 Encoded String
+---------------+ +--------+ +----------------------+
|X|1|2|3|4|5|6|7| |   1    | |       0 - 255        |
+---------------+ +--------+ +----------------------+
                  |                                 |
                  \------ String Identifier --------/

]]>
          </artwork>
        </figure>        
      </section>
    </section>
    <section anchor="frame_type_table" title="Frame Type Table">
      <figure>
        <artwork>
<![CDATA[
 No Frame                   Type    Id    Array  Payload
-------------------------------------------------------------------
 1. Null                    0x00    [x]    [ ]      0
 2. Begin                   0x04    [x]    [ ]      0
 3. End                     0x08    [ ]    [ ]      0

 4. Boolean False           0x0C    [x]    [ ]      0
 5. Boolean True            0x10    [x]    [ ]      0

 6. TinyArray               0x14    [x]    [ ]    0 - 255 (items)
 7. Array                   0x18    [x]    [ ]    0 - 64k (items)
 8. LongArray               0x1C    [x]    [ ]    0 - 4G  (items)

 9. TinyString              0x20    [x]    [x]    0 - 255
10. String                  0x24    [x]    [x]    0 - 64k
11. LongString              0x28    [x]    [x]    0 - 4G

12. TinyBinary              0x2C    [x]    [x]    0 - 255
13. Binary                  0x30    [x]    [x]    0 - 64k
14. LongBinary              0x34    [x]    [x]    0 - 4G

15. Signed int 8-bits       0x38    [x]    [x]      1
16. Signed int 16-bits      0x3C    [x]    [x]      2
17. Signed int 32-bits      0x40    [x]    [x]      4
18. Signed int 64-bits      0x44    [x]    [x]      8

19. Unsigned int 8-bits     0x48    [x]    [x]      1
20. Unsigned int 16-bits    0x4C    [x]    [x]      2
21. Unsigned int 32-bits    0x50    [x]    [x]      4
22. Unsigned int 64-bits    0x54    [x]    [x]      8

23. Floating 16-bits        0x58    [x]    [x]      2
24. Floating 32-bits        0x5C    [x]    [x]      4
25. Floating 64-bits        0x60    [x]    [x]      8

26. Date                    0x64    [x]    [x]     10
27. DateTime                0x68    [x]    [x]     20
28. DateTimeMillis          0x6C    [x]    [x]     24

29. NTP Short Format        0x70    [x]    [x]      4
30. NTP Timestamp Format    0x74    [x]    [x]      8
31. NTP Date Format         0x78    [x]    [x]     16

32. RSK Date                0x7C    [x]    [x]      7
]]>
        </artwork>
      </figure>
      <t>
        Frame Type Table columns:
        <list style="hanging">
            <t hangText="Frame:">Name of frame type. See <xref target="frame_definitions" /> for detailed frame definitions.</t>
            <t hangText="Type:">Hexadecimal value of Leading Byte with mask 0xFC. See <xref target="leading_byte" /> for detailed description of Leading Byte.</t>
            <t hangText="Id:">All marked with X has identifier field. See <xref target="identifiers" /> for details.</t>
            <t hangText="Array:">All marked with X can be enclosed into a array. See <xref target="array_frame" /> for details.</t>
            <t hangText="Payload:">Payload length in bytes for data frames and item count for arrays.</t>
        </list>
      </t>
    </section>    
    <section anchor="implementation_notes" title="Implementation Notes">
      <t>
        RSK is designed so that implementations could have very small memory and other resource demands. Pay attention to memory usage and try to perform IO operations efficiently.
      </t>
      <t>
        Implementations must make sure that well formed documents are written. On reading phase any deformation in document or frame structure must be detected and handled as error condition.
      </t>
      <t>
        Implementations can vary depending on environment and usage. All implementations must support at least Begin and End Frames to be able to handle document structure. Other frame types may not be supported. Implementation may also support most or all frame types but not all identifier types. Some frame types can be also partially supported so that they can be detected and skipped on reading phase although their payload data is not interpreted.
      </t>
    </section>

    <section title="Security Considerations">      
      <t>
        RSK is data encoding format and does not include any executable commands. Implementations must make sure that any parts of encoded documents are not leaked into execution memory. Even malformed documents must be handled so that memory leaks are avoided.
      </t>
      <t>
        RSK does not include any means to validate payload data integrity. Protocols based on RSK or underlying mechanisms which are utilized by those protocols must take care of this. If data integrity is not checked can data get corrupted by malfunctioning devices, software, or malicious attackers.
      </t>
    </section>

    <section title="IANA Considerations">
      <t>
        The MIME media type for RSK documents is application/ruoska.
        <list style="hanging">
          <t hangText="Type name:">application</t>
          <t hangText="Subtype name:">ruoska</t>
          <t hangText="Required parameters:">n/a</t>
          <t hangText="Optional parameters:">n/a</t>
        </list>
      </t>
    </section>
  </middle>

    <back>
      <references title='Normative References'>
        &rfc3339;
        &rfc3629;
        &rfc5905;
      </references>
    </back>

</rfc>
