• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2/*
3 * Copyright (c) 2022-2025 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16Object.defineProperty(exports, "__esModule", { value: true });
17exports.withStringArrayResult = exports.withStringResult = exports.providePlatformDefinedData = exports.ArrayDecoder = exports.NativeStringBase = void 0;
18const Wrapper_1 = require("./Wrapper");
19const arrays_1 = require("#common/wrappers/arrays");
20const Callback_1 = require("#common/wrappers/Callback");
21class NativeStringBase extends Wrapper_1.Wrapper {
22    constructor(ptr) {
23        super(ptr);
24    }
25    toString() {
26        let length = this.bytesLength();
27        let data = new Uint8Array(length);
28        this.getData(data);
29        return (0, arrays_1.decodeToString)(data);
30    }
31}
32exports.NativeStringBase = NativeStringBase;
33class ArrayDecoder {
34    decode(blob) {
35        const size = this.getArraySize(blob);
36        const result = new Array(size);
37        for (let index = 0; index < size; index++) {
38            result[index] = this.getArrayElement(blob, index);
39        }
40        this.disposeArray(blob);
41        return result;
42    }
43}
44exports.ArrayDecoder = ArrayDecoder;
45let platformData = undefined;
46function providePlatformDefinedData(platformDataParam) {
47    platformData = platformDataParam;
48    let registry = platformDataParam.callbackRegistry();
49    if (registry)
50        (0, Callback_1.setCallbackRegistry)(registry);
51}
52exports.providePlatformDefinedData = providePlatformDefinedData;
53function withStringResult(ptr) {
54    if ((0, Wrapper_1.isNullPtr)(ptr))
55        return undefined;
56    let managedString = platformData.nativeString(ptr);
57    let result = managedString === null || managedString === void 0 ? void 0 : managedString.toString();
58    managedString === null || managedString === void 0 ? void 0 : managedString.close();
59    return result;
60}
61exports.withStringResult = withStringResult;
62function withStringArrayResult(ptr) {
63    if (ptr == Wrapper_1.nullptr)
64        return new Array();
65    let managedStringArray = platformData.nativeStringArrayDecoder().decode(ptr);
66    return managedStringArray.map((nativeString) => nativeString.toString());
67}
68exports.withStringArrayResult = withStringArrayResult;
69//# sourceMappingURL=Platform.js.map