> For the complete documentation index, see [llms.txt](https://mwx.twelite.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mwx.twelite.info/v0.1.3/api-reference/functions-1/utility/expand_bytes.md).

# expand\_bytes()

バイト列を分解し変数に格納します。

```cpp
const uint8_t* expand_bytes(
        const uint8_t* b, const uint8_t* e, ...)
```

`expand_bytes()`は、パラメータに`uint8_t*`型のイテレータの組み合わせを指定します。これは解析対象の先頭と末尾の次のイテレータの指定となります。`e`の位置まで解析が進んだ場合はエラーとなり`nullptr`を返します。

展開にエラーがない場合は、次の読み出しを行うイテレータを戻します。

可変数パラメータには以下を指定します。

| バイト数                 | データ長 | 解説                                               |
| -------------------- | :--: | ------------------------------------------------ |
| `uint8_t`            |   1  |                                                  |
| `uint16_t`           |   2  | ビッグエンディアン並びとして展開する                               |
| `uint32_t`           |   4  | ビッグエンディアン並びとして展開する                               |
| `uint8_t[N]`         |   N  | `uint8_t` 型の固定長配列                                |
| `std::pair<char*,N>` |   N  | `char*`,`uint8_t*`型の配列と配列長のペア`make_pair()`で生成できる |

## 例

```cpp
auto&& rx = the_twelite.receiver.read();

char fourchars[5]{}; 
auto&& np = 
	expand_bytes(rx.get_payload().begin(), rx.get_payload().end()
		, make_pair((uint8_t*)fourchars, 4)
    );

// read rest of payload
uint8_t u8DI_BM_remote = 0xff;
uint16_t au16AI_remote[5];
expand_bytes(np, rx.get_payload().end()
	, u8DI_BM_remote
	, au16AI_remote[0]
	, au16AI_remote[1]
	, au16AI_remote[2]
	, au16AI_remote[3]
	, au16AI_remote[4]
);
```

この例では、まず４バイトの文字列を読み出しています。ここでは`make_pair()`を用いて明示的に４バイト分のデータを読み出します。

戻されたイテレータ`np`をもとに、次のデータを読み出します。次のデータは`uint8_t`型、あとは`uint16_t`型が５つ続いています。
