uint32_t MamaRecordedMessageCodec::encodeMsg(char* buffer, MamaMsg* mm)
{
	char* orig_buffer = buffer;
	// Leave 4 bytes for the message size
	buffer += 4;

	uint32_t r = 4;
	MamaMsgIterator* mmi = new MamaMsgIterator(NULL);
    mm->begin(*mmi);
    while (*(*mmi) != NULL)
    {
    	MamaMsgField& mmf = *(*mmi);
    	try
    	{
    		r += encodeField(buffer, mmf);
    	}
		catch(MamaStatus& ms)
		{
			// Pretend this field never happened...
			//printf("Skipping encoding of MAMA Field - MAMA exception encountered: %s\n", ms.toString());
		}
    	//printf("r = %d\n", r);
        ++(*mmi);
    }
    delete mmi;
    // Populate the first 4 bytes with the message size
    uint32_t buffer_size = (uint32_t)r;
    //printf("Encoding Msg of size [%d]...\n", buffer_size);
    memcpy(orig_buffer, &buffer_size, 4);
    return r;
}
示例#2
0
void encodeMove(char *dst, int cx, int cy, int dx, int dy) {
	encodeField(dst, cx, cy);
	dst[2] = ':';
	encodeField(dst+3, dx, dy);
	dst[5] = 0;
}