Created
September 26, 2014 02:41
-
-
Save zhangce/dd7e3401ddbbc44fe576 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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