src/js/lib/RTRemoteSerializer.js
/**
 * convert buffer to message object
 * @param messageBuffer {Buffer} the message buffer
 * @returns {Object} the message object
 */
convert buffer to message object
@param messageBuffer {Buffer} the message buffer
@returns {Object} the message object
convert buffer to message object @param messageBuffer { Buffer } the message buffer @returns { Object } the message object
function fromBuffer(messageBuffer) {
  const messageObj = JSONbig.parse(messageBuffer.toString(RTConst.DEFAULT_CHARSET));
  const mType = messageObj[RTConst.MESSAGE_TYPE];
  switch (mType) {
    case RTRemoteMessageType.SET_PROPERTY_BYNAME_REQUEST:
    case RTRemoteMessageType.SET_PROPERTY_BYNAME_RESPONSE:
    case RTRemoteMessageType.GET_PROPERTY_BYNAME_RESPONSE:
    case RTRemoteMessageType.GET_PROPERTY_BYNAME_REQUEST: {
      processRTValue(messageObj[RTConst.VALUE]);
      break;
    }
    case RTRemoteMessageType.METHOD_CALL_REQUEST: {
      const args = messageObj[RTConst.FUNCTION_ARGS] || [];
      args.forEach(arg => processRTValue(arg));
      break;
    }
    case RTRemoteMessageType.METHOD_CALL_RESPONSE: {
      processRTValue(messageObj[RTConst.FUNCTION_RETURN_VALUE]);
      break;
    }
    default: {
      break;
    }
  }
  return messageObj;
}
function fromBuffer ( messageBuffer ) { const messageObj = JSONbig . parse ( messageBuffer . toString ( RTConst . DEFAULT_CHARSET ) ) ; const mType = messageObj [ RTConst . MESSAGE_TYPE ] ; switch ( mType ) { case RTRemoteMessageType . SET_PROPERTY_BYNAME_REQUEST : case RTRemoteMessageType . SET_PROPERTY_BYNAME_RESPONSE : case RTRemoteMessageType . GET_PROPERTY_BYNAME_RESPONSE : case RTRemoteMessageType . GET_PROPERTY_BYNAME_REQUEST : { processRTValue ( messageObj [ RTConst . VALUE ] ) ; break ; } case RTRemoteMessageType . METHOD_CALL_REQUEST : { const args = messageObj [ RTConst . FUNCTION_ARGS ] || [ ] ; args . forEach ( arg => processRTValue ( arg ) ) ; break ; } case RTRemoteMessageType . METHOD_CALL_RESPONSE : { processRTValue ( messageObj [ RTConst . FUNCTION_RETURN_VALUE ] ) ; break ; } default : { break ; } } return messageObj ; }
convert buffer to message object
 @param messageBuffer {Buffer} the message buffer
 @returns {Object} the message object
convert buffer to message object @param messageBuffer { Buffer } the message buffer @returns { Object } the message object