Skip to content

Instantly share code, notes, and snippets.

@zhangce
Created September 26, 2014 02:41
Show Gist options
  • Select an option

  • Save zhangce/dd7e3401ddbbc44fe576 to your computer and use it in GitHub Desktop.

Select an option

Save zhangce/dd7e3401ddbbc44fe576 to your computer and use it in GitHub Desktop.
bool Serialize(int fd) const {
int flag = contains_value_;
int pt = 0;
memcpy((void*) &buf[pt], &flag, sizeof(flag));
pt += sizeof(flag);
int length = key_.length();
memcpy((void*) &buf[pt], &length, sizeof(int));
pt += sizeof(int);
memcpy((void*) &buf[pt], key_.c_str(), length);
pt += length;
if(contains_value_){
length = value_.length();
memcpy((void*) &buf[pt], &length, sizeof(int));
pt += sizeof(int);
memcpy((void*) &buf[pt], value_.c_str(), length);
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment