1/* 2 * Copyright (C) 2024 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: rpc.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: rpc.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