# ModelPackage

```cpp
#include <qbruntime/model_package.h>

class mobilint::ModelPackage
```

Represents an MXQ package (.mxqpkg) that packs multiple MXQ files into a single file.

Opens the package once and creates [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>) objects from its MXQ entries without unpacking it. Prefer this class to Model::create(mxq\_pkg\_path, entry\_name, ...) when creating many models from the same package, because the package index is read only once.

Models created from a [ModelPackage](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/modelpackage/index.md>) do not depend on it, so the [ModelPackage](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/modelpackage/index.md>) may be destroyed while the models are still in use.

> [!WARNING]
>
> The package file is read again by createModel and loadEntry, and by the created models when they are launched. Moving or deleting the file before then makes those calls fail, and modifying it may make the models produce wrong results.

The const member functions, such as createModel and loadEntry, may be called concurrently from multiple threads on the same [ModelPackage](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/modelpackage/index.md>).

## Static functions

| Member | Description |
| --- | --- |
| [`create`](<#create>) | Opens the specified MXQ package file. |

### create

```cpp
static std::unique_ptr<ModelPackage> create(const std::string &mxq_pkg_path, StatusCode &sc)
```

Opens the specified MXQ package file.

Reads and validates the package index. The MXQ entries are not loaded until createModel is called.

**Parameters**

- `mxq_pkg_path` *\[in\]* — The path to the MXQ package file.
- `sc` *\[out\]* — A reference to a status code that will be updated to indicate whether the package was successfully opened or if an error occurred.

**Returns**

A unique pointer to the created [ModelPackage](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/modelpackage/index.md>) object.

## Member functions

| Member | Description |
| --- | --- |
| [`ModelPackage`](<#modelpackage>) ×2 |  |
| [`operator=`](<#operator-assign>) ×2 |  |
| [`createModel`](<#createmodel>) ×2 | Creates a [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>) object from an MXQ entry in the package. |
| [`getPath`](<#getpath>) | Returns the path to the MXQ package file. |
| [`getEntryNames`](<#getentrynames>) | Returns the names of all entries in the package, in the order they are stored. |
| [`loadEntry`](<#loadentry>) | Reads the payload of a non-MXQ entry in the package into memory. |

### ModelPackage

```cpp
ModelPackage(const ModelPackage &other)=delete
```

```cpp
ModelPackage(ModelPackage &&other) noexcept
```

### operator=

```cpp
ModelPackage & operator=(const ModelPackage &rhs)=delete
```

```cpp
ModelPackage & operator=(ModelPackage &&rhs) noexcept
```

### createModel

```cpp
std::unique_ptr<Model> createModel(const std::string &entry_name, StatusCode &sc) const
```

Creates a [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>) object from an MXQ entry in the package.

The model is initialized in auto-core mode.

> [!NOTE]
>
> The created [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>) object must be launched before performing inference. See [Model::launch](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/#launch>) for more details.

**Parameters**

- `entry_name` *\[in\]* — The name of the MXQ entry in the package (e.g. "block\_0\_expert\_0.mxq").
- `sc` *\[out\]* — A reference to a status code that will be updated to indicate whether the model was successfully created or if an error occurred.

**Returns**

A unique pointer to the created [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>) object.

```cpp
std::unique_ptr<Model> createModel(const std::string &entry_name, const ModelConfig &config, StatusCode &sc) const
```

Creates a [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>) object from an MXQ entry in the package and configuration.

> [!NOTE]
>
> The created [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>) object must be launched before performing inference. See [Model::launch](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/#launch>) for more details.

**Parameters**

- `entry_name` *\[in\]* — The name of the MXQ entry in the package (e.g. "block\_0\_expert\_0.mxq").
- `config` *\[in\]* — The configuration settings to initialize the [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>).
- `sc` *\[out\]* — A reference to a status code that will be updated to indicate whether the model was successfully created or if an error occurred.

**Returns**

A unique pointer to the created [Model](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/model/index.md>) object.

### getPath

```cpp
std::string getPath() const
```

Returns the path to the MXQ package file.

**Returns**

The MXQ package file path.

### getEntryNames

```cpp
std::vector<std::string> getEntryNames() const
```

Returns the names of all entries in the package, in the order they are stored.

The names include entries that are not MXQ files, such as a manifest. Only MXQ entries can be passed to createModel, and only the other entries can be passed to loadEntry.

**Returns**

The entry names.

### loadEntry

```cpp
StatusCode loadEntry(const std::string &entry_name, std::vector<uint8_t> &buffer) const
```

Reads the payload of a non-MXQ entry in the package into memory.

The whole payload is read at once and verified against the checksum stored in the package. This is intended for small entries such as a manifest. MXQ entries are rejected; use createModel for them.

**Parameters**

- `entry_name` *\[in\]* — The name of the entry in the package (e.g. "manifest.json").
- `buffer` *\[out\]* — A reference to a byte vector that will store the entry payload. Its previous contents are discarded.

**Returns**

A status code indicating whether the entry was successfully read or if an error occurred. [StatusCode::ModelPackage\_FailedToReadEntry](<https://docs.mobilint.com/runtime/kr/v1.6/api/cpp/#statuscode>) is returned for an MXQ entry.
