Commit dd8f683a authored by Zhukov, Alexander P's avatar Zhukov, Alexander P
Browse files

minor edits for byte swapping

parent 598ffd98
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* #include <byteswap.h> */
#include <sys/time.h>
#include "binary_storage.h"
uint64_t encodeDbl(double a){
uint64_t b;
unsigned char *src = (unsigned char *)&a,
*dst = (unsigned char *)&b;
dst[0] = src[7];
dst[1] = src[6];
dst[2] = src[5];
dst[3] = src[4];
dst[4] = src[3];
dst[5] = src[2];
dst[6] = src[1];
dst[7] = src[0];
return b;
uint64_t bswap_d(double a){
uint64_t *b = (uint64_t *)&a;
return bswap_64(*b);
}
BinaryStorage bs_open(char* filename){
......@@ -61,7 +50,7 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
/* double scalar */
fputc(17,bs->file);
uint64_t rawdata = encodeDbl(value);
uint64_t rawdata = bswap_d(value);
fwrite(&rawdata,8,1,bs->file);
/* tags */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment