Ejemplo n.º 1
0
kaa_error_t kaa_platform_protocol_serialize_client_sync(kaa_platform_protocol_t *self
        , const kaa_serialize_info_t *info
        , char **buffer
        , size_t *buffer_size)
{
    KAA_RETURN_IF_NIL4(self, info, buffer, buffer_size, KAA_ERR_BADPARAM);
    KAA_RETURN_IF_NIL3(info->allocator, info->services, info->services_count, KAA_ERR_BADDATA);

    KAA_LOG_TRACE(self->logger, KAA_ERR_NONE, "Serializing client sync...");

    *buffer_size = 0;
    kaa_error_t error = kaa_client_sync_get_size(self, info->services, info->services_count, buffer_size);
    KAA_RETURN_IF_ERR(error)

    KAA_LOG_DEBUG(self->logger, KAA_ERR_NONE, "Going to request sync buffer (size %zu)", *buffer_size);

    *buffer = info->allocator(info->allocator_context, *buffer_size);
    if (*buffer) {
        self->request_id++;
        error = kaa_client_sync_serialize(self, info->services, info->services_count, *buffer, buffer_size);
    } else {
        error = KAA_ERR_WRITE_FAILED;
    }

    if (error) {
        self->request_id--;
    } else {
        KAA_LOG_TRACE(self->logger, KAA_ERR_NONE, "Client sync successfully serialized");
    }

    return error;
}
Ejemplo n.º 2
0
kaa_error_t kaa_platform_protocol_serialize_client_sync(kaa_platform_protocol_t *self,
        const kaa_extension_id *services, size_t services_count,
        uint8_t *buffer, size_t *buffer_size)
{
    if (!self || !buffer_size) {
        return KAA_ERR_BADPARAM;
    }

    if (!services || services_count == 0) {
        return KAA_ERR_BADDATA;
    }

    size_t required_buffer_size = 0;
    kaa_error_t error = kaa_client_sync_get_size(self, services, services_count,
            &required_buffer_size);
    if (error) {
        KAA_LOG_ERROR(self->logger, error, "Failed to get required buffer size");
        return error;
    }

    if (*buffer_size < required_buffer_size || !buffer) {
        *buffer_size = required_buffer_size;
        return KAA_ERR_BUFFER_IS_NOT_ENOUGH;
    }
    *buffer_size = required_buffer_size;

    KAA_LOG_TRACE(self->logger, KAA_ERR_NONE, "Serializing client sync...");

    self->request_id++;
    error = kaa_client_sync_serialize(self, services, services_count, buffer, buffer_size);
    if (error) {
        self->request_id--;
        return error;
    }

    KAA_LOG_INFO(self->logger, KAA_ERR_NONE,
            "Client sync serialized: request id '%u', payload size '%zu'",
            self->request_id, *buffer_size);

    return KAA_ERR_NONE;
}