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

Added description field

parent 29f44fe7
......@@ -33,16 +33,22 @@ void close_record(BinaryStorage *bs){
}
int write_meta(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, uint32_t extra_count){
int write_meta(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, char* description, uint32_t extra_count){
unsigned char name_len = strlen(name);
uint32_t descr_len=0;
if(description!=NULL){
descr_len = 5+strlen(description);
}
int i=0;
uint8_t i=0;
uint32_t tag_length=0;
for(i=0;i<tags->num;i++){
tag_length+=strlen(tags->data[i])+2;
if(tags!=NULL){
for(i=0;i<tags->num;i++){
tag_length+=strlen(tags->data[i])+2;
}
}
uint32_t total_length = bswap_32(1+1+name_len+1+8+extra_count+1+tag_length);
uint32_t total_length = bswap_32(1+1+name_len+1+8+extra_count+1+tag_length+descr_len);
fwrite(&total_length,4,1,bs->file);
/* name */
......@@ -58,25 +64,35 @@ int write_meta(BinaryStorage *bs, char* name, TSTMP timestamp, TAGS *tags, uint3
fwrite(&nano,4,1,bs->file);
/* tags */
for(i=0;i<tags->num;i++){
unsigned char tag_len = strlen(tags->data[i]);
fputc(BS_TAG,bs->file);
fputc(tag_len,bs->file);
fwrite(tags->data[i],1,tag_len,bs->file);
if(tags!=NULL){
for(i=0;i<tags->num;i++){
unsigned char tag_len = strlen(tags->data[i]);
fputc(BS_TAG,bs->file);
fputc(tag_len,bs->file);
fwrite(tags->data[i],1,tag_len,bs->file);
}
}
/* description */
if(description!=NULL){
fputc(BS_DESCR,bs->file);
uint32_t length = strlen(description);
uint32_t raw_len = bswap_32(length);
fwrite(&raw_len,4,1,bs->file);
fwrite(description, 1,length,bs->file);
}
}
int bsWriteDBL(BinaryStorage *bs, char* name, TSTMP timestamp, DBL value, TAGS *tags){
int bsWriteDBL(BinaryStorage *bs, char* name, TSTMP timestamp, DBL value, TAGS *tags, char* description){
uint32_t count = value.count;
if(count==0){
return -1;
}
else if(count==1){
write_meta(bs, name, timestamp, tags, 9);
write_meta(bs, name, timestamp, tags, description, 9);
fputc(BS_DBL,bs->file);
}
else {
write_meta(bs, name, timestamp, tags, 5+8*count);
write_meta(bs, name, timestamp, tags, description, 5+8*count);
fputc(BS_DBLWF,bs->file);
uint32_t rawcount = bswap_32(count*sizeof(double));
fwrite(&rawcount,4,1,bs->file);
......@@ -87,8 +103,6 @@ int bsWriteDBL(BinaryStorage *bs, char* name, TSTMP timestamp, DBL value, TAGS *
fwrite(&rawdata,8,1,bs->file);
}
close_record(bs);
}
......
......@@ -68,5 +68,5 @@ typedef struct storage {
} BinaryStorage;
BinaryStorage bsOpen(char* filename);
int bsWriteDBL(BinaryStorage *bs, char* name, TSTMP timestamp, DBL value, TAGS *tags);
int bsWriteDBL(BinaryStorage *bs, char* name, TSTMP timestamp, DBL value, TAGS *tags, char* description);
void bsClose(BinaryStorage *bs);
......@@ -7,7 +7,7 @@ int main(){
long int ms;
BinaryStorage storage = bsOpen("test_c.bin");
char *tag1 = "TAG1";
char *tag1 = "TAG1";
char *data[]={"MEGA_TAG",tag1};
TAGS tags={.data=data, .num=2};
......@@ -19,16 +19,19 @@ int main(){
DBL value;
double x;
char *description;
if(i%2==0){
x = 3.1415*i;
value = (DBL){.count = 1, .data=&x};
description = "double scalar";
} else {
double wf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
value = (DBL){.count = sizeof(wf)/8, .data=wf};
description = "double[]";
}
bsWriteDBL(&storage,"Test_Record", timestamp, value, &tags);
bsWriteDBL(&storage,"Test_Record", timestamp, value, &tags, description);
}
bsClose(&storage);
......
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