1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16let logTag = 'RpcServer_ApiMessage:  ';
17export default class ApiMessage  {
18    _deviceName = null;
19    _className = null;
20    _methodName = null;
21    _apiSession = null;
22    _parameterTypes = null;
23    _parameters = null;
24    _apiResult = null;
25
26    constructor(deviceName, className, methodName, apiSession, parameterTypes, parameters, apiResult) {
27        this._deviceName = deviceName;
28        this._className = className;
29        this._methodName = methodName;
30        this._apiSession = apiSession;
31        this._parameterTypes = parameterTypes;
32        this._parameters = parameters;
33        this._apiResult = apiResult;
34
35    }
36    marshalling(MessageSequence) {
37        console.log(logTag + "into marshalling.");
38        MessageSequence.writeString(this._deviceName);
39        MessageSequence.writeString(this._className);
40        MessageSequence.writeString(this._methodName);
41        MessageSequence.writeString(this._apiSession);
42        console.log(logTag + "writeString successfully.");
43        MessageSequence.writeStringArray(this._parameterTypes);
44        MessageSequence.writeStringArray(this._parameters);
45        MessageSequence.writeString(this._apiResult);
46        console.log(logTag + "marshalling successfully.");
47        return true;
48    }
49
50    unmarshalling(MessageSequence) {
51        console.log(logTag + "into unmarshalling.");
52        this._deviceName = MessageSequence.readString();
53        this._className = MessageSequence.readString();
54        this._methodName = MessageSequence.readString();
55        this._apiSession = MessageSequence.readString();
56        this._parameterTypes = MessageSequence.readStringArray();
57        this._parameters = MessageSequence.readStringArray();
58        this._apiResult = MessageSequence.readString();
59        console.log(logTag + "unmarshalling successfully.");
60        return true;
61    }
62}
63