/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module RpcInterface
 */
import { BentleyStatus } from "@itwin/core-bentley";
import { IModelError } from "../../IModelError";
/** Support for transporting RPC values using the HTTP multipart content type.
 * @internal
 */
export class RpcMultipart {
    /** Creates a multipart form object for an RPC value. */
    static createForm(value) {
        const form = new FormData();
        RpcMultipart.writeValueToForm(form, value);
        return form;
    }
    /** Creates a multipart stream for an RPC value. */
    static createStream(value) {
        return this.platform.createStream(value);
    }
    /** Obtains the RPC value from a multipart HTTP request. */
    static async parseRequest(req) {
        return this.platform.parseRequest(req);
    }
    /** @internal */
    static writeValueToForm(form, value) {
        form.append("objects", value.objects);
        for (let i = 0; i !== value.data.length; ++i) {
            this.platform.appendToForm(i, form, value);
        }
    }
}
/** @internal */
RpcMultipart.platform = {
    createStream(_value) {
        throw new IModelError(BentleyStatus.ERROR, "Not bound.");
    },
    async parseRequest(_req) {
        throw new IModelError(BentleyStatus.ERROR, "Not bound.");
    },
    appendToForm(i, form, value) {
        form.append(`data-${i}`, new Blob([value.data[i]], { type: "application/octet-stream" }));
    },
};
//# sourceMappingURL=RpcMultipart.js.map