libs/stream_message/src/mbmsgser.cxx
// ===========================================================================
// To serialize the XML object, first use the msgapi to get Unicode,
// then use XML4C's intrinsic transcoding to make UTF-8.  Not that we have
// any need for more than ASCII at the moment.
//
To serialize the XML object, first use the msgapi to get Unicode,
then use XML4C's intrinsic transcoding to make UTF-8.  Not that we have
any need for more than ASCII at the moment.
To serialize the XML object first use the msgapi to get Unicode then use XML4C ' s intrinsic transcoding to make UTF - 8 . Not that we have any need for more than ASCII at the moment .
void MessageSerializer::serialize(const Message &t, const char *&data_param, size_t &length)
{
    reset();
    DOMString buffer;
    ((Message &)t).Encode(buffer);
    const XMLCh* DOMStrData = buffer.rawBuffer();
    size_t unilength = buffer.length();
    datap = new char[unilength * (sizeof(XMLCh) / 2 * 3) + 5];
    const XMLCh byteMask = 0xBF;
    const XMLCh byteMark = 0x80;
    const XMLCh *source = DOMStrData;
    char *target = datap + 4;
    for (size_t n = 0; n < unilength; n += 1) {
	int bytesToWrite;
        XMLCh ch = *source++;
        if (ch <= 0x80) {
	    bytesToWrite = 1;
	}
	else if (ch < 0x800) {
	    bytesToWrite = 2;
	}
	else if (ch < 0x10000) {
	    bytesToWrite = 3;
	}
	else if (ch < 0x200000) {
	    bytesToWrite = 4;
	}
	else if (ch < 0x4000000) {
	    bytesToWrite = 5;
	}
	else {
	    bytesToWrite = 6;
	}
	target += bytesToWrite;
	switch (bytesToWrite) {
	    case 6:*--target = (char)((ch | byteMark) & byteMask); ch >>= 6;
	    case 5:*--target = (char)((ch | byteMark) & byteMask); ch >>= 6;
	    case 4:*--target = (char)((ch | byteMark) & byteMask); ch >>= 6;
	    case 3:*--target = (char)((ch | byteMark) & byteMask); ch >>= 6;
	    case 2:*--target = (char)((ch | byteMark) & byteMask); ch >>= 6;
	    case 1:*--target = (char)(ch | firstByteMark[bytesToWrite]);
	}
	target += bytesToWrite;
    }
    length = target - datap;
    *target++ = '\0';
    data_param = datap;
    size_t len = length - 4;
    datap[3]  = len & 255;
    datap[2]  = (len >> 8) & 255;
    datap[1]  = (len >> 16) & 255;
    datap[0]  = (len >> 24) & 255;
}
void MessageSerializer :: serialize ( const Message & t , const char * & data_param , size_t & length ) { reset ( ) ; DOMString buffer ; ( ( Message & ) t ) . Encode ( buffer ) ; const XMLCh * DOMStrData = buffer . rawBuffer ( ) ; size_t unilength = buffer . length ( ) ; datap = new char [ unilength * ( sizeof ( XMLCh ) / 2 * 3 ) + 5 ] ; const XMLCh byteMask = 0xBF ; const XMLCh byteMark = 0x80 ; const XMLCh * source = DOMStrData ; char * target = datap + 4 ; for ( size_t n = 0 ; n < unilength ; n += 1 ) { int bytesToWrite ; XMLCh ch = * source ++ ; if ( ch <= 0x80 ) { bytesToWrite = 1 ; } else if ( ch < 0x800 ) { bytesToWrite = 2 ; } else if ( ch < 0x10000 ) { bytesToWrite = 3 ; } else if ( ch < 0x200000 ) { bytesToWrite = 4 ; } else if ( ch < 0x4000000 ) { bytesToWrite = 5 ; } else { bytesToWrite = 6 ; } target += bytesToWrite ; switch ( bytesToWrite ) { case 6 : * -- target = ( char ) ( ( ch | byteMark ) & byteMask ) ; ch >>= 6 ; case 5 : * -- target = ( char ) ( ( ch | byteMark ) & byteMask ) ; ch >>= 6 ; case 4 : * -- target = ( char ) ( ( ch | byteMark ) & byteMask ) ; ch >>= 6 ; case 3 : * -- target = ( char ) ( ( ch | byteMark ) & byteMask ) ; ch >>= 6 ; case 2 : * -- target = ( char ) ( ( ch | byteMark ) & byteMask ) ; ch >>= 6 ; case 1 : * -- target = ( char ) ( ch | firstByteMark [ bytesToWrite ] ) ; } target += bytesToWrite ; } length = target - datap ; * target ++ = ' \0 ' ; data_param = datap ; size_t len = length - 4 ; datap [ 3 ] = len & 255 ; datap [ 2 ] = ( len >> 8 ) & 255 ; datap [ 1 ] = ( len >> 16 ) & 255 ; datap [ 0 ] = ( len >> 24 ) & 255 ; }
To serialize the XML object, first use the msgapi to get Unicode,
then use XML4C's intrinsic transcoding to make UTF-8.
To serialize the XML object first use the msgapi to get Unicode then use XML4C ' s intrinsic transcoding to make UTF - 8 .
// Allocate a buffer big enough for the length word, followed by // the UTF-8 encoding, with null-termination. // XML4C can convert from UTF-8, but not to it. // This code taken from the Unicode Standard. // Return it. // network byte order is big-endian // fprintf(stderr, "serialize done, string %s, length %d\n", data_param + 4, length);