> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XGameSaveEnumerateBlobInfo

> XGameSaveEnumerateBlobInfo

# XGameSaveEnumerateBlobInfo

检索 XGameSaveContainer 内容的 Blob 信息。

## Syntax

```cpp theme={null}
HRESULT XGameSaveEnumerateBlobInfo(  
         XGameSaveContainerHandle container,  
         void* context,  
         XGameSaveBlobInfoCallback* callback  
)  
```

### Parameters

*container*   \_In\_\
类型：XGameSaveContainerHandle

包含要枚举的 Blob 的 **XGameSaveContainer** 句柄。

*context*   \_In\_opt\_\
类型：void\*

将传递给回调函数的指针。

*callback*   \_In\_\
类型：XGameSaveBlobInfoCallback\*

将为容器中每个 Blob 调用的函数，返回 false 以停止枚举。

### Return value

类型：HRESULT

函数结果。

## Remarks

<Note>虽然此函数在时间敏感型线程上调用是安全的，但 XGameSaveBlobInfoCallback 可能会导致延迟，具体取决于标题在回调中执行的操作。例如，从回调中复制数据是可以的；但是，执行任何非时间敏感型调用可能会延迟回调的返回。有关详细信息，请参阅[时间敏感型线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

Blob 包含构成容器的实际可检索数据。枚举 Blob 将使你能够查看容器内所有可用的数据。你可以使用 [XGameSaveEnumerateBlobInfoByName](/reference/system/xgamesave/functions/xgamesaveenumerateblobinfobyname) 枚举与特定前缀匹配的 Blob。

```cpp theme={null}
// wrapper for calling a method on each item in the XGameSaveContainerInfo 
HRESULT Sample::_ForEachBlob(_In_ const XGameSaveContainerInfo* container, _In_ void* context, _In_ XGameSaveBlobInfoCallback* callback) 
{ 
    // create the container handle so we can inspect the contents 
    XGameSaveContainerHandle containerContext = nullptr; 
    HRESULT hr = XGameSaveCreateContainer(_provider, container->name, &containerContext); 
    if (SUCCEEDED(hr)) 
    { 
        // for each item in the container invoke the callback 
        hr = XGameSaveEnumerateBlobInfo(containerContext, context, callback); 
    } 
  
    if (containerContext != nullptr) 
    { 
        // make sure we close the context handle or we will leak memory 
        XGameSaveCloseContainer(containerContext); 
    } 
    return hr; 
} 
  
// check to see if the container has the minimum blobs we need to load a save 
HRESULT Sample::_CheckForRequiredBlobs(_In_ XGameSaveContainerInfo* container) 
{ 
    const char* blobNames[] = { 
        "WorldState", 
        "PlayerState", 
        "PlayerInventory" 
    }; 
    return _CheckContainerForRequiredBlobs(container, blobNames, _countof(blobNames)); 
} 
  
//confirm this container has the blobs the caller is looking for 
HRESULT Sample::_CheckContainerForRequiredBlobs( 
    _In_ XGameSaveContainerInfo* container, 
    _In_z_count_(countOfBlobs) const char** expectedBlobNames, 
    _In_ uint32_t countOfBlobs) 
{ 
    HRESULT hr; 
    struct QueryContext 
    { 
        QueryContext(const char** blobNames, uint32_t countOfBlobs) : 
            expectedCount(countOfBlobs), expectedBlobNames(blobNames), hitCount(0) 
        {} 
  
        uint32_t expectedCount; 
        const char** expectedBlobNames; 
        uint32_t hitCount; 
    }; 
  
    QueryContext qc{ expectedBlobNames, countOfBlobs }; 
  
    // simple check to see if we just see each of the blob names in the container 
    // a more robust check would identify which blob was missing to inform the caller 
    auto callback = [](_In_ const XGameSaveBlobInfo* info, _In_ void* context) 
    { 
        QueryContext* qc = reinterpret_cast<QueryContext*>(context); 
        for (uint32_t i = 0; i < qc->expectedCount; i++) 
        { 
            if (strcmp(qc->expectedBlobNames[i], info->name) == 0) 
            { 
                if (++qc->hitCount == qc->expectedCount) 
                { 
                    // all the expected names are here, can stop enum 
                    return false; 
                } 
            } 
        } 
        // keep enumerating 
        return true; 
    }; 
  
    hr = _ForEachBlob(container, &qc, callback); 
    if (SUCCEEDED(hr)) 
    { 
        if (qc.hitCount != qc.expectedCount) 
        { 
            printf("missing blobs from container!"); 
            hr = E_UNEXPECTED; 
        } 
    } 
  
    return hr; 
} 
  
// find the size of a set of blobs in a container 
HRESULT Sample::_GetContainerBlobsDataSize( 
    _In_ const XGameSaveContainerInfo* container, 
    _In_z_count_(countOfBlobs) const char** blobNames, 
    _In_ uint32_t countOfBlobs, 
    _Out_ size_t* containerSize) 
{ 
  
    *containerSize = 0; 
  
    struct BlobSize { 
        size_t size; 
        const char** blobNames; 
        uint32_t countOfBlobs; 
    }; 
  
    BlobSize blobSize = { 0, blobNames, countOfBlobs }; 
  
    HRESULT hr = _ForEachBlob(container, &blobSize, 
        [](const XGameSaveBlobInfo* info, void* ctx) 
    { 
        BlobSize* size = reinterpret_cast<BlobSize*>(ctx); 
        for (uint32_t i = 0; i < size->countOfBlobs; i++) 
        { 
            if (strcmp(info->name, size->blobNames[i]) == 0) 
            { 
                size->size += strlen(info->name) + 1; // length + null 
                size->size += info->size + sizeof(XGameSaveBlob); 
                break; 
            } 
        } 
        return true; 
    }); 
  
    if (SUCCEEDED(hr)) 
    { 
        *containerSize = blobSize.size; 
    } 
  
    return hr; 
} 
```

## Requirements

**头文件：** XGameSave.h

**库：** xgameruntime.lib

**受支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## Conceptual documentation

* [时间敏感型线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[XGameSave](/reference/system/xgamesave/xgamesave_members)\
[XGameSaveBlobInfo](/reference/system/xgamesave/structs/xgamesaveblobinfo)\
[XGameSaveEnumerateBlobInfoByName](/reference/system/xgamesave/functions/xgamesaveenumerateblobinfobyname)\
[调试游戏保存](/build/core-features/common/game-save/game-saves-debugging)


## Related topics

- [XGameSaveEnumerateBlobInfoByName](/zh-CN/reference/system/xgamesave/functions/xgamesaveenumerateblobinfobyname.md)
- [XGameSaveBlobInfoCallback](/zh-CN/reference/system/xgamesave/functions/xgamesaveblobinfocallback.md)
- [XGameSaveBlob](/zh-CN/reference/system/xgamesave/structs/xgamesaveblob.md)
- [XGameSave](/zh-CN/reference/system/xgamesave/xgamesave_members.md)
- [XGameSave API 概述](/zh-CN/build/core-features/common/game-save/xgamesave.md)
