Skip to content

Commit

Permalink
Improve usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
cfnptr authored Feb 3, 2024
1 parent 33f39ec commit 546c926
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,34 @@ See the [documentation](https://cfnptr.github.io/pack).
```cpp
void packReaderExampleCPP()
{
pack::Reader packReader("resources.pack");
auto itemIndex = packReader.getItemIndex("textures/sky.png");
std::vector<uint8_t> itemData;
packReader.readItemData(itemIndex, itemData);
pack::Reader packReader("resources.pack");
auto itemIndex = packReader.getItemIndex("textures/sky.png");
std::vector<uint8_t> itemData;
packReader.readItemData(itemIndex, itemData);
// use data...
}
```

```c
void packReaderExampleC()
{
PackReader packReader = NULL;
PackResult packResult = createFilePackReader("resources.pack", false, 1, &packReader);
if (packResult != SUCCESS_PACK_RESULT) abort();
PackReader packReader = NULL;
PackResult packResult = createFilePackReader("resources.pack", false, 1, &packReader);
if (packResult != SUCCESS_PACK_RESULT) abort();

uint64_t itemIndex = 0;
bool result = getPackItemIndex(packReader, "textures/sky.png")
if (!result) abort();
uint64_t itemIndex = 0;
bool result = getPackItemIndex(packReader, "textures/sky.png")
if (!result) abort();

uint32_t dataSize = getPackItemDataSize(packReader, itemIndex);
uint8_t* itemData = (uint8_t*)malloc(dataSize);
if (!itemData) abort();
uint32_t dataSize = getPackItemDataSize(packReader, itemIndex);
uint8_t* itemData = (uint8_t*)malloc(dataSize);
if (!itemData) abort();

packResult = readPackItemData(packReader, itemIndex, itemData, 0)
if (packResult != SUCCESS_PACK_RESULT) { free(data); abort(); }
packResult = readPackItemData(packReader, itemIndex, itemData, 0)
if (packResult != SUCCESS_PACK_RESULT) { free(data); abort(); }

// use data...
destroyPackReader(packReader);
}
```

Expand Down

0 comments on commit 546c926

Please sign in to comment.