void KPR_mqttclient_publish(xsMachine* the) { KPR_MQTTClientRecord *self = xsGetHostData(xsThis); FskErr err = kFskErrNone; char *topic; void *payload = NULL; UInt32 payloadLength = 0; UInt8 qos; Boolean retain; UInt16 token; if (xsToInteger(xsArgc) != 4) xsThrowIfFskErr(kFskErrParameterError); topic = xsToString(xsArg(0)); if (xsTest(xsArg(1))) { if (isArrayBuffer(xsArg(1))) { payload = xsToArrayBuffer(xsArg(1)); payloadLength = xsGetArrayBufferLength(xsArg(1)); } else { payload = xsToString(xsArg(1)); payloadLength = FskStrLen(payload); } } qos = xsToInteger(xsArg(2)); retain = xsToBoolean(xsArg(3)); bailIfError(KprMQTTClientPublish(self->client, topic, payload, payloadLength, qos, retain, &token)); xsResult = xsInteger(token); bail: xsThrowIfFskErr(err); }
void KPR_mqttclient_connect(xsMachine* the) { KPR_MQTTClientRecord *self = xsGetHostData(xsThis); char *host; UInt16 port; KprMQTTClientConnectOptions options; if (xsToInteger(xsArgc) != 10) xsThrowIfFskErr(kFskErrParameterError); host = xsToString(xsArg(0)); port = xsToInteger(xsArg(1)); options.isSecure = xsToBoolean(xsArg(2)); options.keepAlive = xsToInteger(xsArg(3)); options.username = xsTest(xsArg(4)) ? xsToString(xsArg(4)) : NULL; options.password = xsTest(xsArg(5)) ? xsToString(xsArg(5)) : NULL; options.willIsRetained = false; options.willQualityOfService = 0; options.willTopic = NULL; options.willPayload = NULL; options.willPayloadLength = 0; if (xsTest(xsArg(6))) { options.willTopic = xsToString(xsArg(6)); options.willQualityOfService = xsToInteger(xsArg(7)); options.willIsRetained = xsToBoolean(xsArg(8)); if (xsTest(xsArg(9))) { if (isArrayBuffer(xsArg(9))) { options.willPayload = xsToArrayBuffer(xsArg(9)); options.willPayloadLength = xsGetArrayBufferLength(xsArg(9)); } else { options.willPayload = xsToString(xsArg(9)); options.willPayloadLength = FskStrLen(options.willPayload); } } } xsThrowIfFskErr(KprMQTTClientConnect(self->client, host, port, &options)); }
TestArrayBuffer* ArrayBufferOrArrayBufferViewOrDictionary::getAsArrayBuffer() const { ASSERT(isArrayBuffer()); return m_arrayBuffer; }
TestArrayBuffer* StringOrArrayBufferOrArrayBufferView::getAsArrayBuffer() const { ASSERT(isArrayBuffer()); return m_arrayBuffer; }