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

Swithced to uint types instead unsigned int.

parent 4e081dfc
......@@ -5,8 +5,8 @@
#include <sys/time.h>
#include "binary_storage.h"
unsigned long encodeDbl(double a){
unsigned long b;
uint64_t encodeDbl(double a){
uint64_t b;
unsigned char *src = (unsigned char *)&a,
*dst = (unsigned char *)&b;
dst[0] = src[7];
......@@ -25,7 +25,7 @@ BinaryStorage bs_open(char* filename){
storage.file = fopen(filename,"wb");
storage.buf_size = 500;
storage.con_idx = 0;
storage.contents = (long*) malloc(sizeof(unsigned long)*storage.buf_size);
storage.contents = (uint64_t*) malloc(sizeof(uint64_t)*storage.buf_size);
char header[]="SNS-BIET2020";
fwrite(header,sizeof(header)-1,1,storage.file);
......@@ -39,12 +39,12 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
unsigned char name_len = strlen(name);
int i=0;
unsigned int tag_length=0;
uint32_t tag_length=0;
for(i=0;i<tags->num;i++){
tag_length+=strlen(tags->data[i])+2;
}
unsigned int total_length = bswap_32(1+1+name_len+1+8+1+8+1+tag_length);
uint32_t total_length = bswap_32(1+1+name_len+1+8+1+8+1+tag_length);
fwrite(&total_length,4,1,bs->file);
/* name */
......@@ -54,14 +54,14 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
/* timestamp */
fputc(2,bs->file);
unsigned int sec = bswap_32(timestamp.seconds);
unsigned int nano = bswap_32(timestamp.nanos);
uint32_t sec = bswap_32(timestamp.seconds);
uint32_t nano = bswap_32(timestamp.nanos);
fwrite(&sec,4,1,bs->file);
fwrite(&nano,4,1,bs->file);
/* double scalar */
fputc(17,bs->file);
unsigned long rawdata = encodeDbl(value);
uint64_t rawdata = encodeDbl(value);
fwrite(&rawdata,8,1,bs->file);
/* tags */
......@@ -80,7 +80,7 @@ int write_record(BinaryStorage *bs, char* name, TSTMP timestamp, double value, T
}
void bs_close(BinaryStorage *bs){
unsigned int total_length = bswap_32(1+1);
uint32_t total_length = bswap_32(1+1);
fwrite(&total_length,4,1,bs->file);
fputc(255,bs->file);
fputc(254,bs->file);
......@@ -88,10 +88,10 @@ void bs_close(BinaryStorage *bs){
bs->con_idx++;
int i;
for(i=0;i<bs->con_idx;i++){
unsigned long swapped = bswap_64(bs->contents[i]);
uint64_t swapped = bswap_64(bs->contents[i]);
fwrite(&swapped,8,1,bs->file);
}
unsigned int num_of_rec = bswap_32(bs->con_idx);
uint32_t num_of_rec = bswap_32(bs->con_idx);
fwrite(&num_of_rec,4,1,bs->file);
fclose(bs->file);
......
#include <stdint.h>
typedef struct tagset {
char **data;
size_t num;
} TAGS;
typedef struct timestamp {
unsigned int seconds;
unsigned int nanos;
uint32_t seconds;
uint32_t nanos;
} TSTMP;
typedef struct storage {
FILE* file;
unsigned long* contents;
unsigned int con_idx;
uint64_t* contents;
uint32_t con_idx;
size_t buf_size;
} BinaryStorage;
......
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