# TwePacket, spTwePacket

パケットデータは種別によってデータ構造が違いますが、様々な種類のパケットを一元管理するための基底クラスです。

```cpp
class TwePacket;
typedef std::shared_ptr<TwePacket> spTwePacket;
```

`spTwePacket` はメモリ管理のためのスマートポインタです。`std::shared_ptr`を用いています。

TwePacketクラスは、パケットデータのパケット種別の管理を行います。また、パケットデータの解釈を行うための仮想関数parse()メソッドを定義しています。パケット特有のデータ構造に基づく解釈やデータの保存等の取り扱いは、派生クラスに実装します。

## メソッド

### TwePacket() - コンストラクタ

```cpp
TwePacket(E_PKT ptyp = E_PKT::PKT_ERROR)
```

デフォルトでは、未解釈状態として `E_PKT::PKT_ERROR` で初期化します。

### \~TwePacket() - デストラクタ

```cpp
virtual ~TwePacket()
```

### get\_type()

```cpp
E_PKT get_type()
```

パケットの種別を[`E_PKT`](/latest/references/parser/twefmt/twepacket/e_pkt.md)型で返します。

### parse()

```cpp
virtual E_PKT parse(uint8_t* p, uint8_t u8len)
```

パケットデータのバイト列を与えて、パケットデータを解釈する。

派生クラスで、そのパケットに対応するデータ構造を解釈するための実装を行います。

戻り値は [`E_PKT`](/latest/references/parser/twefmt/twepacket/e_pkt.md)型 で、成功時は解釈されたパケット種別を、エラー時に `E_PKT::PKT_ERROR` を返します。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwm5.twelite.info/latest/references/parser/twefmt/twepacket.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
