Re: Avoiding string break...



Hi Glus,

I have not found the functions you are mentioning in Devhelp (Gio::receive & Gio::send). Can you post a link to the Gnome website that documents them?

At work we use both base32 and base64 to encode binary data. The data could be for example an image, or encrypted data, or something else.

So base32 and base64 do solve the problem of null chars - if they are causing you a problem.

I would suggest that if you have a string object your first step would be to extract the data into an octet array, because that is the format you need to pass to g_base64_encode. Then when you receive the data you have to do the opposite, create a string object out of the raw data.

For example you could use this to get the binary data out of the object:
http://www.cplusplus.com/reference/string/string/data/

Another thing to keep in mind is that base 64 encodes 6 bits at a time, so if the number of bits in the data you want to encode is not a multiple of 8 it will be padded at the end with null bits. For example, if you want to send two octets, that is 16 bits, 3 octets are required after base64 encoding (3 * 6 = 18, so there will be two padding bits). But the encoding/decoding function should take care of padding bits for you.

Hope that helps. It is actually quite simple, but you need to stop thinking in terms of objects and instead think about the raw data.

P.




----- Original Message ----
From: Glus Xof <gtglus gmail com>
To: Piscium <groknok yahoo ie>
Cc: gtkmm-list gnome org
Sent: Mon, 3 May, 2010 20:10:32
Subject: Re: Avoiding string break...

> ----- Original Message ----
> From: Glus Xof <gtglus gmail com>
> To: gtkmm-list gnome org
> Sent: Mon, 3 May, 2010 16:04:29
> Subject: Avoiding string break...
>
> Hi guys,
>
> Must communicate two processes (client-server app) with (partially)
> encrypted messages...
>
> Does exist any foreseen solution to avoid the classical string break
> by the '\0' character ?
>
> (I use Gio::receive & Gio::send()...)
>
> Glus


2010/5/3 Piscium <groknok yahoo ie>:
> You could try g_base64_encode and g_base64_decode available in Glib. I did not find an equivalent in glibmm.
>

Thanks a lot, Piscium,

But, don't reussite !...

Trying to find something like g_strdup_printf to get guchar strings
(for testing purposes, at the moment)... but seems there is nothing.

The start point are two std::string values (one of those,
encrypted...). The goal is to pass them throw the Gio::send() -
Gio::receive() methods, avoiding the encrypted C string break by the
character '\0'.

A little more help will be appreciated...

Glus






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]