Available languages: [Python](https://databento.com/docs/api-historical/helpers/dbn-store-decode-record.python.md) · [C++](https://databento.com/docs/api-historical/helpers/dbn-store-decode-record.cpp.md) · [Rust](https://databento.com/docs/api-historical/helpers/dbn-store-decode-record.rust.md) · [HTTP](https://databento.com/docs/api-historical/helpers/dbn-store-decode-record.http.md)

Source: https://databento.com/docs/api-historical/helpers/dbn-store-decode-record


### AsyncDbnStore::decode_record

Decode a single record of a specific type.
If the record type is unknown, such as when working with Live data where the stream can contain several different record types, use [decode_record_ref](https://databento.com/docs/api-historical/helpers/dbn-store-decode-record-ref.md).

#### API method

```rust
pub async fn decode_record<T: HasRType>(
    &mut self,
) -> dbn::Result<Option<&T>>;
```

#### Parameters

| Parameter | Type | Description |
| `T` | HasRType | A DBN record type. |

#### Returns

A reference to the decoded record of type `T` or `Ok(None)` if the stream has been exhausted.

This function will return an error if the record is not of type `T` or there's an error reading from the input stream.

#### Example usage

```rust
use databento::{
    HistoricalClient,
    dbn::{Dataset, OhlcvMsg, Schema},
    historical::timeseries::GetRangeParams,
};
use time::macros::datetime;

let mut client =
    HistoricalClient::builder().key("$YOUR_API_KEY")?.build()?;
let mut decoder = client
    .timeseries()
    .get_range(
        &GetRangeParams::builder()
            .dataset(Dataset::XnasItch)
            .date_time_range(
                datetime!(2023-08-07 00:00 UTC)
                    ..datetime!(2023-08-08 00:00 UTC),
            )
            .symbols("AAPL")
            .schema(Schema::Ohlcv1M)
            .build(),
    )
    .await?;
let bar = decoder.decode_record::<OhlcvMsg>().await?.unwrap();
println!("{bar:#?}");
```
#### Example response

```plaintext
OhlcvMsg {
    hd: RecordHeader {
        length: 14,
        rtype: Ohlcv1M,
        publisher_id: XnasItchXnas,
        instrument_id: 32,
        ts_event: 1691395200000000000,
    },
    open: 183.440000000,
    high: 183.460000000,
    low: 182.750000000,
    close: 183.300000000,
    volume: 2030,
}
```
