# `CRAM.SliceHeader`
[🔗](https://github.com/baoulo/cram-elixir/blob/v0.1.0/lib/cram/slice_header.ex#L1)

Fields from an uncompressed slice header block (CRAMv3 §8.5).

`external_reference` is false when the 16-byte MD5 is all zeros or when the
slice names an embedded reference block. Inspection records that flag and
does not fetch bases.

# `t`

```elixir
@type t() :: %CRAM.SliceHeader{
  alignment_span: integer(),
  alignment_start: integer(),
  block_content_ids: [integer()],
  block_count: non_neg_integer(),
  embedded_reference_id: integer(),
  external_reference: boolean(),
  record_count: non_neg_integer(),
  record_counter: non_neg_integer(),
  reference_md5: binary(),
  reference_sequence_id: integer()
}
```

An uncompressed slice header.

  * `:reference_sequence_id` — reference id, or `-1` when unmapped
  * `:alignment_start` — start stored in the slice header
  * `:alignment_span` — span stored in the slice header
  * `:record_count` — records in the slice
  * `:record_counter` — record counter
  * `:block_count` — number of following content ids
  * `:block_content_ids` — those content ids
  * `:embedded_reference_id` — content id of an embedded reference, or `-1`
  * `:reference_md5` — 16 raw MD5 bytes
  * `:external_reference` — true when the MD5 is not all zeros and the
    embedded id is `-1`

    iex> %CRAM.SliceHeader{embedded_reference_id: -1, external_reference: true, reference_md5: <<1::128>>}.external_reference
    true

# `parse`

```elixir
@spec parse(binary()) :: {:ok, t()} | {:error, CRAM.Error.t()}
```

Parse an uncompressed slice header.

`data` is the raw block payload. Returns `{:ok, slice}`. A short payload
is `reason: :truncated`. A negative record count, counter, or block count
is `reason: :bad_header`. Does not raise and does not fetch a reference.

    iex> body =
    ...>   CRAM.Itf8.encode!(0) <>
    ...>     CRAM.Itf8.encode!(1) <>
    ...>     CRAM.Itf8.encode!(8) <>
    ...>     CRAM.Itf8.encode!(2) <>
    ...>     CRAM.Ltf8.encode!(0) <>
    ...>     CRAM.Itf8.encode!(0) <>
    ...>     CRAM.Itf8.encode!(-1) <>
    ...>     <<1::128>>
    iex> {:ok, slice} = CRAM.SliceHeader.parse(body)
    iex> {slice.record_count, slice.embedded_reference_id, slice.external_reference}
    {2, -1, true}
    iex> {:error, error} = CRAM.SliceHeader.parse(<<0>>)
    iex> error.reason
    :truncated

---

*Consult [api-reference.md](api-reference.md) for complete listing*
