Skip to content

Commit

Permalink
Merge branch 'pradeep-k-marshal-verbose'
Browse files Browse the repository at this point in the history
  • Loading branch information
amygara committed Apr 29, 2015
2 parents 1838bff + 606c0b4 commit 55df535
Showing 1 changed file with 16 additions and 85 deletions.
101 changes: 16 additions & 85 deletions lib/marshal/marshal.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* @desc: The function does the marshing. Function does all the allocation.
* It is caller's responsibility to free the memory allocated.
Expand Down Expand Up @@ -56,6 +55,7 @@ gwkv_marshal_server(struct operation* data, int status, char** ascii)
strcat(val,data->value); //<data block>.
strcat(val,b3); //\r\n.
strcat(val,b4); //END \r\n.
kvprintf("[!] server marshaling GET");
break;
}
*ascii = val;
Expand Down Expand Up @@ -162,22 +162,16 @@ gwkv_marshal_client(struct operation* data, char** ascii)
int
gwkv_demarshal_server(char* ascii, struct operation** op)
{
/*switch(data->method_type) {
case SET:
//convert ascii to operation
case GET:
//convert ascii to operation
/* SET: convert ascii to operation
GET: convert ascii to operation
}*/
//char s0[] = "VALUE";
char* traverse = ascii;
struct operation *data = (struct operation*)malloc(sizeof(struct operation));
char s1[] = "set";
char s2[] = "get";

/*if (strcmp(ascii, s0) >= strlen(s0)) {
} else*/
if ( 0 == strncmp(ascii, s1, strlen(s1))) {
kvprintf("[!] server demarshal SET: %s\n", ascii);
data->method_type = SET;
traverse += strlen(s1) + 1;

Expand Down Expand Up @@ -210,19 +204,11 @@ gwkv_demarshal_server(char* ascii, struct operation** op)
assert(0);
}

traverse = temp;//pointing to \r\n.
traverse = temp + 1;//pointing to \r\n.

/*temp = strchr(traverse, ' ');
if (NULL != temp) {
traverse = temp + 1;
assert(traverse[0] == '\r');
assert(traverse[1] == '\n');
} else {
assert(0);
}*/
assert(traverse[1] == '\n');
assert(traverse[0] == '\n');

traverse += 2; // pointing to data
traverse += 1; // pointing to data

temp = strchr(traverse, '\r');
if ( NULL != temp) {
Expand All @@ -240,6 +226,8 @@ gwkv_demarshal_server(char* ascii, struct operation** op)


} else if (0 == strncmp(ascii, s2, strlen(s2))) {

kvprintf("[!] server demarshal GET: %s\n", ascii);
data->method_type = GET;
traverse += strlen(s2) + 1;//pointing key
char* temp = strchr(traverse, '\r');
Expand Down Expand Up @@ -270,27 +258,34 @@ gwkv_demarshal_client(char* ascii, struct operation** op, int* status)
char s1[]="NOT_STORED\r\n";
char s2[]="EXISTS\r\n";
char s3[]="NOT_FOUND\r\n";

if(strcmp(ascii,s0)==0){
kvprintf("[!] client demarshal SET: %s\n", ascii);
data->method_type=SET;
*status=0;
return 0;
}
else if(strcmp(ascii,s1)==0){
kvprintf("[!] client demarshal SET: %s\n", ascii);
data->method_type=SET;
*status=1;
return 0;
}
else if(strcmp(ascii,s2)==0){
kvprintf("[!] client demarshal SET: %s\n", ascii);
data->method_type=SET;
*status=2;
return 0;
}
else if(strcmp(ascii,s3)==0){
kvprintf("[!] client demarshal SET: %s\n", ascii);
data->method_type=SET;
*status=3;
return 0;
}

kvprintf("[!] client demarshal GET: %s\n", ascii);

char *value = "VALUE";
char* traverse = ascii;
if( 0 != strncmp(traverse, value, strlen(value))) {
Expand Down Expand Up @@ -329,68 +324,4 @@ gwkv_demarshal_client(char* ascii, struct operation** op, int* status)
strncpy(data->value, traverse, data->value_length);
}
return 0;

/*
int i=0;
int offset = 0;
char *a=ascii;
i=0;
char b[50];
while(a[i]!=' ' && a[i]!='\0'){
b[i]=a[i];
i++;
}
b[i]='\0';
offset += i+1;
char c1[]="VALUE";
if(strcmp(b,c1)!=0){
return -1;
}
data->method_type = GET;
//key
a = ascii + offset;
i=0;
while(a[i]!=' '&& a[i]!='\0'){
b[i]=a[i];
i++;
}
b[i]='\0';
offset += i+1;
data->key_length = i + 1;
data->key = malloc(data->key_length);
strcpy(data->key, b);
//flag
i=0;
while(b[i]!=' '&&b[i]!='\0'){
b[i]=a[i];
i++;
}
b[i]='\0';
offset += i+1;
//length
i=0;
while(b[i]!=' '&&b[i]!='\0'){
b[i]=a[i];
i++;
}
b[i]='\0';
offset += i+1;
data->value_length = atoi(b);
//\r\n
offset += 2;
//data_value
i=0;
while(b[i]!='\r'&&b[i]!='\0'){
b[i]=a[i];
i++;
}
b[i]='\0';
offset += i+1;
char *b2 = (char*)malloc(50*sizeof(char));
strcat(b2,b);
data->value = b1;*/
}

0 comments on commit 55df535

Please sign in to comment.