Ejemplo n.º 1
0
inline void GTMTrackLayer::WriteTrackpoint( double lat, double lon, float altitude, bool start )
{
    void* pBuffer = CPLMalloc(25);
    void* pBufferAux = pBuffer;
    //latitude
    appendDouble(pBufferAux, lat);
    pBufferAux = (char*)pBufferAux + 8; 
    //longitude
    appendDouble(pBufferAux, lon);
    pBufferAux = (char*)pBufferAux + 8; 
    //date
    appendInt(pBufferAux, 0);
    pBufferAux = (char*)pBufferAux + 4; 
    //start
    appendUChar(pBufferAux, start);
    pBufferAux = (char*)pBufferAux + 1; 
    //altitude
    appendFloat(pBufferAux, altitude);
    VSIFWriteL(pBuffer, 25, 1, poDS->getTmpTrackpointsFP());
    poDS->incNumTrackpoints();
    CPLFree(pBuffer);
}
Ejemplo n.º 2
0
static int write_samples_data(const LoggerMessage *msg)
{
        ChannelSample *sample = msg->channelSamples;
        size_t channelCount = msg->sampleCount;

        if (NULL == sample) {
                pr_warning("Logger: null sample record\r\n");
                return WRITE_FAIL;
        }

        int i;
        for (i = 0; 0 < channelCount; channelCount--, sample++, i++) {
                appendFileBuffer(0 == i ? "" : ",");

                if (!sample->populated)
                        continue;

                const int precision = sample->cfg->precision;

                switch(sample->sampleData) {
                case SampleData_Float:
                case SampleData_Float_Noarg:
                        appendFloat(sample->valueFloat, precision);
                        break;
                case SampleData_Int:
                case SampleData_Int_Noarg:
                        appendInt(sample->valueInt);
                        break;
                case SampleData_LongLong:
                case SampleData_LongLong_Noarg:
                        appendLongLong(sample->valueLongLong);
                        break;
                case SampleData_Double:
                case SampleData_Double_Noarg:
                        appendDouble(sample->valueDouble, precision);
                        break;
                default:
                        pr_warning("file: Unknown channel sample type\n");
                }
        }

        appendFileBuffer("\n");
        return writeFileBuffer();
}
Ejemplo n.º 3
0
double* parseDoubles( const char* str, const char* delims, unsigned long* p_n ){
    char* cpy = copy( str );

    size_t n = 0;
    size_t i = 0;
    double* arr = NULL;

    char* token = strtok( cpy, delims );
    while( token != NULL ){
        appendDouble( atof( token ), &arr, i++, &n );
        token = strtok( NULL, delims );
    }

    free( cpy );

    *p_n = i;
    return arr;

}
bool UmbrellaSerializedReply::prepare(const McReply& reply,
                                      mc_op_t op, uint64_t reqid,
                                      struct iovec*& iovOut, size_t& niovOut) {
  static char nul = '\0';

  /* We can reuse this struct multiple times, reset the counters */
  nEntries_ = nStrings_ = offset_ = 0;
  error_ = false;
  niovOut = 0;

  appendInt(I32, msg_op, umbrella_op_from_mc[op]);
  appendInt(U64, msg_reqid, reqid);
  appendInt(I32, msg_result, umbrella_res_from_mc[reply.result()]);

  if (reply.appSpecificErrorCode()) {
    appendInt(I32, msg_err_code, reply.appSpecificErrorCode());
  }
  if (reply.flags()) {
    appendInt(U64, msg_flags, reply.flags());
  }
  if (reply.exptime()) {
    appendInt(U64, msg_exptime, reply.exptime());
  }
  if (reply.delta()) {
    appendInt(U64, msg_delta, reply.delta());
  }
  if (reply.leaseToken()) {
    appendInt(U64, msg_lease_id, reply.leaseToken());
  }
  if (reply.cas()) {
    appendInt(U64, msg_cas, reply.cas());
  }
  if (reply.lowValue() || reply.highValue()) {
    appendDouble(reply.lowValue());
  }
  if (reply.highValue()) {
    appendDouble(reply.highValue());
  }

  /* TODO: if we intend to pass chained IOBufs as values,
     we can optimize this to write multiple iovs directly */
  if (reply.hasValue()) {
    auto valueRange = reply.valueRangeSlow();
    appendString(msg_value,
                 reinterpret_cast<const uint8_t*>(valueRange.begin()),
                 valueRange.size());
  }

  /* NOTE: this check must come after all append*() calls */
  if (error_) {
    return false;
  }

  size_t size = sizeof(entry_list_msg_t) +
    sizeof(um_elist_entry_t) * nEntries_ +
    offset_;

  msg_.total_size = folly::Endian::big((uint32_t)size);
  msg_.nentries = folly::Endian::big((uint16_t)nEntries_);

  iovs_[1].iov_len = sizeof(um_elist_entry_t) * nEntries_;
  niovOut = 2;

  for (size_t i = 0; i < nStrings_; i++) {
    iovs_[niovOut].iov_base = (char *)strings_[i].begin();
    iovs_[niovOut].iov_len = strings_[i].size();
    niovOut++;

    iovs_[niovOut].iov_base = &nul;
    iovs_[niovOut].iov_len = 1;
    niovOut++;
  }

  iovOut = iovs_;
  return true;
}