io7m | single-page | multi-page | SMF Format Specification 0.16.0-SNAPSHOT
3.3. Section - smf
Previous
3. SMF/B - Binary Encoding
Up
3.5. Section - metadata
Next

# 3.4. Sections

- 3.4.1. Definition
- 3.4.2. Alignment
- 3.4.3. Available Sections
- 3.4.4. Enumerating Sections

## 3.4.1. Definition

1
Directly following the header, an SMF/B file consists of a series of sections. A section begins with the following fixed-size structure:

### 3.4.1.2. Section header

    <composite name="SMFSection">
      <type name="magicNumber"
            description="The magic number identifying the section."
            primitiveType="uint64"/>
      <type name="size"
            description="The size of the section data"
            primitiveType="uint64"
            semanticType="Length"/>
    </composite>

3
The id field of the section header identifies the type of the section. The size field of the section header specifies the data size; the size in octets of the data that follows the section header. The data size necessarily includes any trailing padding octets that may be inserted in order to guarantee that the start of the next section (if any) is correctly aligned. This implies that the data size of any given section MUST be a multiple of the alignment size.
4
Implementations MUST ignore any content inside a section of an unrecognized type [1]. As sections explicitly state the size of their own data, implementations can simply seek forwards in the file by the specified data size to reach the next section.
5
The first section in an SMF/B file MUST be an smf section. The last section in an SMF/B file MUST be an end section.

## 3.4.2. Alignment

1
Sections MUST be aligned to 16 octet boundaries. As the section header is defined to be exactly 16 octets, this implies that the data within a section will also be aligned to a 16 octet boundary [2].

## 3.4.3. Available Sections

1
This version of the specification defines the following sections:

### 3.4.3.2. Sections

- end
- metadata
- smf
- triangles
- vertices-noninterleaved

## 3.4.4. Enumerating Sections

1
Note: This subsection is informative.
2
The design of sections allows for implementations to quickly enumerate all sections within a file using the following strategy:

### 3.4.4.3. Enumerating Sections

    void showSections()
    {
      // Read SMF header
      long smf = readUnsigned64();
      int major = readUnsigned32();
      int minor = readUnsigned32();

      // Read all sections
      while (bytesRemaining()) {
        long offset = currentOffset();
        long magic = readUnsigned64();
        long size = readUnsigned64();

        System.out.printf(
        "section: %s %s %s\n",
        Long.toUnsignedString(offset),
        Long.toUnsignedString(magic, 16),
        Long.toUnsignedString(size));

        seek(size);
      }
    }

4
The bytesAvailable method is assumed to return true if there are any bytes remaining in the file. The currentOffset method is assumed to return the current read position in octets within the file. The readUnsigned64 method is assumed to read a 64-bit big-endian integer from the current file, advancing the current read position by 8 octets. The readUnsigned32 method is assumed to read a 32-bit big-endian integer from the current file, advancing the current read position by 4 octets.

## Footnotes

1 | Ignoring unrecognized sections allows for forwards compatibility: An implementation supporting version m can read a file of version n, where m < n, and ignore any new sections specified by format n that it does not understand. References to this footnote: 1
2 | The requirement for data to be aligned to 16 octet boundaries is intended to facilitate implementations using vector instruction sets such as SSE to efficiently operate on memory-mapped SMF/B files. References to this footnote: 1

3.3. Section - smf
Previous
3. SMF/B - Binary Encoding
Up
3.5. Section - metadata
Next
io7m | single-page | multi-page | SMF Format Specification 0.16.0-SNAPSHOT