Commit 699ab806 authored by Greg Williams's avatar Greg Williams
Browse files

Added clarification to README to prefix rake commands with 'bundle exec'

parent 03553431
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ Getting Started

    > cd kinetic-c
    > bundle install # Ensures you have all RubyGems needed
    > rake #run all tests and build kinetic-c library and examples
    > bundle execute rake #run all tests and build kinetic-c library and examples

Dependencies
============
@@ -33,6 +33,8 @@ Dependencies
Common Developer Tasks
======================

NOTE: Prefix the following commands with `bundle exec` so that they execute in the context of the bundle environment setup via `bundle install`.

* Run all tests and build the library and examples
    * `rake`
* Build the library
+42 −0
Original line number Diff line number Diff line
#include "KineticExchange.h"
#include <string.h>

void KineticExchange_Init(
    KineticExchange* const exchange,
    int64_t identity,
    int64_t connectionID)
{
    memset(exchange, 0, sizeof(KineticExchange));
    exchange->identity = identity;
    exchange->connectionID = connectionID;
}

void KineticExchange_SetClusterVersion(
    KineticExchange* const exchange,
    int64_t clusterVersion)
{
    exchange->clusterVersion = clusterVersion;
    exchange->has_clusterVersion = true;
}

void KineticExchange_IncrementSequence(KineticExchange* const exchange)
{
    exchange->sequence++;
}

void KineticExchange_ConfigureHeader(
    const KineticExchange* const exchange,
    KineticProto_Header* const header)
{
    header->has_clusterversion = exchange->has_clusterVersion;
    if (exchange->has_clusterVersion)
    {
        header->clusterversion = exchange->clusterVersion;
    }
    header->has_identity = true;
    header->identity = exchange->identity;
    header->has_connectionid = true;
    header->connectionid = exchange->connectionID;
    header->has_sequence = true;
    header->sequence = exchange->sequence;
}
+43 −0
Original line number Diff line number Diff line
#ifndef _KINETIC_EXCHANGE_H
#define _KINETIC_EXCHANGE_H

#include "KineticTypes.h"
#include "KineticProto.h"

typedef struct _KineticExchange
{
    // Defaults to false, since clusterVersion is optional
    // Set to true to enable clusterVersion for the exchange
    bool has_clusterVersion;

    // Optional field - default value is 0
    // The version number of this cluster definition. If this is not equal to
    // the value on the device, the request is rejected and will return a
    // `VERSION_FAILURE` `statusCode` in the `Status` message.
    int64_t clusterVersion;

    // Required field
    // The identity associated with this request. See the ACL discussion above.
    // The Kinetic Device will use this identity value to lookup the
    // HMAC key (shared secret) to verify the HMAC.
    int64_t identity;

    // Required field
    // A unique number for this connection between the source and target.
    // On the first request to the drive, this should be the time of day in
    // seconds since 1970. The drive can change this number and the client must
    // continue to use the new number and the number must remain constant
    // during the session
    int64_t connectionID;

    // Required field
    // A monotonically increasing number for each request in a TCP connection.
    int64_t sequence;
} KineticExchange;

void KineticExchange_Init(KineticExchange* const exchange, int64_t identity, int64_t connectionID);
void KineticExchange_SetClusterVersion(KineticExchange* const exchange, int64_t clusterVersion);
void KineticExchange_IncrementSequence(KineticExchange* const exchange);
void KineticExchange_ConfigureHeader(const KineticExchange* const exchange, KineticProto_Header* const header);

#endif // _KINETIC_EXCHANGE_H
+11 −0
Original line number Diff line number Diff line
#ifndef _KINETIC_MESSAGE_H
#define _KINETIC_MESSAGE_H

#include "KineticTypes.h"
#include "KineticProto.h"
#include "KineticExchange.h"

void KineticMessage_Init(KineticProto* message, KineticExchange* exchange);
void KineticMessage_NOOP(KineticProto* message);

#endif // _KINETIC_MESSAGE_H

src/lib/KineticPDU.c

0 → 100644
+70 −0
Original line number Diff line number Diff line
#include "KineticPDU.h"
#include <string.h>
#include <arpa/inet.h>
#include <stdio.h>

static void KineticPDU_PackInt64(uint8_t* const buffer, int64_t value);
static int64_t KineticPDU_UnpackInt64(const uint8_t* const buffer);

void KineticPDU_Create(
    KineticPDU* const pdu,
    uint8_t* const buffer,
    const KineticProto* const proto,
    const uint8_t* const value,
    int64_t valueLength)
{
    size_t protoPackedSize;

    // Initialize the instance struct
    assert(pdu != NULL);
    memset(pdu, 0, sizeof(KineticPDU));

    // Assign the data buffer pointer
    assert(buffer != NULL);
    pdu->data = buffer;

    // Setup the PDU header fields
    pdu->prefix = &buffer[0];
    *pdu->prefix = (uint8_t)'F';
    pdu->protoLength = &buffer[1];
    assert(proto != NULL);
    protoPackedSize = KineticProto_get_packed_size(proto);
    KineticPDU_PackInt64(pdu->protoLength, protoPackedSize);
    pdu->valueLength = &buffer[1 + sizeof(int64_t)];
    KineticPDU_PackInt64(pdu->valueLength, valueLength);

    // Populate with the encoded kinetic protocol buffer
    pdu->proto = &buffer[PDU_HEADER_LEN];
    assert(proto != NULL);
    KineticProto_pack(proto, pdu->proto);

    // Populate with the value data, if specified
    if (value != NULL)
    {
        pdu->value = &buffer[PDU_HEADER_LEN + protoPackedSize];
        memcpy(pdu->value, value, valueLength);
    }
}

void KineticPDU_PackInt64(uint8_t* const buffer, int64_t value)
{
    int i;
    for (i = sizeof(int64_t) - 1; i >= 0; i--)
    {
        buffer[i] = value & 0xFF;
        value = value >> 8;
    }
}

int64_t KineticPDU_UnpackInt64(const uint8_t* const buffer)
{
    int i;
    int64_t value = 0;
    for (i = 0; i < sizeof(int64_t); i++)
    {
        value <<= 8;
        value += buffer[i];
    }
    return value;
}
//
Loading