---
title: offlineCalculateByFile
description: "服务端生成文件形式的分桶数据，方便线上查询时快速查询结果。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcctrustzone/tee/kcal/kunpeng_kcal_16_0095.html
sourcePath: /source/zh/kunpengcctrustzone/tee/kcal/kunpeng_kcal_16_0095.html
indexId: 25f4c7925c1977f961494ea56de0400fa174692f493ce3e13696f3b2a5f1241364
---
# offlineCalculateByFile

服务端生成文件形式的分桶数据，方便线上查询时快速查询结果。
```
int offlineCalculateByFile(
DG_TeeCtx *dgTeeCtx,
const DG_MpcFileInput *input,
DG_MpcFileOutput *output
)
```


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| dgTeeCtx | KCAL上下文信息 | 为initTeeCtx成功初始化的结果 | 输入 |
| input | DG\_MpcFileInput | 不能输入为NULL | 输入 |
| output | 计算结果 类型为：DG\_MpcFileOutput | 不能输入为NULL | 输出 |


**表1 DG_MpcFileInput结构体**

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| filePath | char\* | 文件路径 |
| pathLen | uint32\_t | 路径长度 |
| dataSize | uint64\_t | 数据大小 |


**表2 DG_MpcFileOutput结构体**

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| filePath | char\* | 文件路径 |
| pathLen | uint32\_t | 路径长度 |
| dataSize | uint64\_t | 数据大小 |


#### 返回值

- 成功：返回0。
- 失败：返回错误码。


#### 错误码

| 错误码值 | 错误码 | 描述 | 特殊说明 |
| --- | --- | --- | --- |
| 4515 | DG\_ERR\_MPC\_TEE\_BUCKET\_NUM\_SET\_ERROR | 分桶数量设置错误 | \- |


#### 依赖

- pirOpts依赖  DG_InitPirOpts
的成功初始化PIR类算子函数组。
- 依赖的头文件为"data_guard_mpc.h"。


#### 示例

使用调用DG_InitPirOpts成功后的pirOpts来调用offlineCalculateByFile接口。


```
#include  "data_guard_mpc.h"
DG_MpcFileInput teeFileInput;
teeFileInput.filePath = const_cast<char *>(inputFilePath.c_str());
teeFileInput.pathLen = static_cast<uint32_t>(inputFilePath.length());
DG_MpcFileOutput teeFileOutput;
teeFileOutput.filePath = const_cast<char *>(outputCachePath.c_str());
teeFileOutput.pathLen = static_cast<uint32_t>(outputCachePath.length());
return pirOpts->offlineCalculateByFile(dgTeeCtx_, &teeFileInput, &teeFileOutput);
```

运行结果: res结果为0且output不为null。
