KineticStatus KineticSocket_WriteProtobuf(int socket, KineticPDU* pdu)
{
    assert(pdu != NULL);
    LOGF1("Writing protobuf (%zd bytes)...", pdu->header.protobufLength);

    uint8_t* packed = (uint8_t*)malloc(pdu->header.protobufLength);

    if (packed == NULL) {
        LOG0("Failed allocating memory for protocol buffer");
        return KINETIC_STATUS_MEMORY_ERROR;
    }
    size_t len = KineticProto_Message__pack(&pdu->protoData.message.message, packed);
    assert(len == pdu->header.protobufLength);

    ByteBuffer buffer = ByteBuffer_Create(packed, len, len);

    KineticStatus status = KineticSocket_Write(socket, &buffer);

    free(packed);
    return status;
}
Exemple #2
0
KineticStatus KineticSocket_WriteProtobuf(int socket, KineticPDU* pdu)
{
    assert(pdu != NULL);
    #ifdef KINETIC_LOG_SOCKET_OPERATIONS
    LOGF("Writing protobuf (%zd bytes)...", pdu->header.protobufLength);
    #endif

    uint8_t* packed = (uint8_t*)malloc(pdu->header.protobufLength);

    if (packed == NULL) {
        LOG("Failed allocating memory for protocol buffer");
        return KINETIC_STATUS_MEMORY_ERROR;
    }
    size_t len = KineticProto__pack(&pdu->protoData.message.proto, packed);
    assert(len == pdu->header.protobufLength);

    ByteBuffer buffer = ByteBuffer_Create(packed, len);
    buffer.bytesUsed = len;

    KineticStatus status = KineticSocket_Write(socket, &buffer);

    free(packed);
    return status;
}