Sending the Output Results
For details about the plugin code, see Sample Plugin Head File (MxpiSamplePlugin.h) and Sample Plugin Source File (MxpiSamplePlugin.cpp).
- Construct the output data structure.
The data transmitted between plugins is defined by protobuf. Select a proper structure based on the protobuf data format provided by the API. For details about the data format, see Metadata and Metadata Proto File. If no matching structure is found, you can customize a structure. However, you must comply with the following rules:
- The data structure contains a single repeated variable. See the following example:
message CustomDataList // Custom data type. { repeated CustomData dataVec = 1; } message CustomData // Custom data content. { repeated MxpiMetaHeader headerVec = 1; // This member must be included. xxx; // Custom field. } - repeated MxpiMetaHeader headerVec = 1 must be included and must be the first member. This data structure is used to describe the dependency between data for the serialization plugin to assemble data.
- The data structure contains a single repeated variable. See the following example:
- Send data.
The user assembles the output data structure, calls AddProtoMetadata() to mount the result to the corresponding buffer when the input is obtained, and then sends data by using the SendData() API.
MxpiMetadataManager mxpiMetadataManager(buffer); mxpiMetadataManager.AddProtoMetadata(metadataKey, std::static_pointer_cast<void>(customDataListSptr)); // customDataListSptr is a smart pointer of the custom data structure. SendData(0, buffer); // 0 indicates the output port number. Change it based on the site requirements.
- Output the exception.When the service logic is abnormal, the result needs to be transferred to the downstream system in the following way:
- Add the error information.
Assemble the error code and error information into the MxpiErrorInfo data structure, and add the error information to the metadata.
MxpiErrorInfo mxpiErrorInfo; mxpiErrorInfo.ret = ErrorCode; // ErrorCode indicates the corresponding error code. mxpiErrorInfo.errorInfo = "Image resize, failed."; MxpiMetadataManager mxpiMetadataManager(buffer); mxpiMetadataManager.AddErrorInfo(pluginName, mxpiErrorInfo);
- Send the error information.
SendData(0, buffer); // The error information has been mounted to the buffer in the previous step. Perform this operation to send the error information to the downstream plugin.
- Add the error information.