base64.b64encode(data) equivalent
Iâm sure that we have that. I remember svenâs code using encoder but I do not know where. # Method for encoding ints with base64 encoding def encode(n): data = struct.pack("i", n) s = base64.b64encode(data) return s
around Zinc-Character-Encoding-Core :) Stef On 09 Mar 2014, at 09:07, Pharo4Stef <pharo4Stef@free.fr> wrote:
Iâm sure that we have that. I remember svenâs code using encoder but I do not know where.
# Method for encoding ints with base64 encoding def encode(n): data = struct.pack("i", n) s = base64.b64encode(data) return s
ZnBase64Encoder new encode: 42 asByteArray. => 'Kg==' (ZnBase64Encoder new decode: 'Kg==') asInteger. => 42 There is also #asByteArrayOfSize: and signed/unsigned might come into play as well. Note that strictly speaking (as implemented by ZnBase64Encoder), Base64 is a binary to string encoding. But is it often used string to string (as in #base64Encoded and #base64Decoded, which are still implemented using Base64MimeConverter) but the explicit correct way is as in ZnUtils #encodeBase64: and #decodeBase64: using a character encoding. On 09 Mar 2014, at 09:09, Pharo4Stef <pharo4Stef@free.fr> wrote:
around Zinc-Character-Encoding-Core :)
Stef On 09 Mar 2014, at 09:07, Pharo4Stef <pharo4Stef@free.fr> wrote:
Iâm sure that we have that. I remember svenâs code using encoder but I do not know where.
# Method for encoding ints with base64 encoding def encode(n): data = struct.pack("i", n) s = base64.b64encode(data) return s
thanks sven Iâm reading Hbase connection and Iâm trying to understand it :) On 09 Mar 2014, at 09:50, Sven Van Caekenberghe <sven@stfx.eu> wrote:
ZnBase64Encoder new encode: 42 asByteArray. => 'Kg=='
(ZnBase64Encoder new decode: 'Kg==') asInteger. => 42
There is also #asByteArrayOfSize: and signed/unsigned might come into play as well.
Note that strictly speaking (as implemented by ZnBase64Encoder), Base64 is a binary to string encoding. But is it often used string to string (as in #base64Encoded and #base64Decoded, which are still implemented using Base64MimeConverter) but the explicit correct way is as in ZnUtils #encodeBase64: and #decodeBase64: using a character encoding.
On 09 Mar 2014, at 09:09, Pharo4Stef <pharo4Stef@free.fr> wrote:
around Zinc-Character-Encoding-Core :)
Stef On 09 Mar 2014, at 09:07, Pharo4Stef <pharo4Stef@free.fr> wrote:
Iâm sure that we have that. I remember svenâs code using encoder but I do not know where.
# Method for encoding ints with base64 encoding def encode(n): data = struct.pack("i", n) s = base64.b64encode(data) return s
On 09 Mar 2014, at 9:50 , Sven Van Caekenberghe <sven@stfx.eu> wrote:
ZnBase64Encoder new encode: 42 asByteArray. => 'Kg=='
(ZnBase64Encoder new decode: 'Kg==') asInteger. => 42
There is also #asByteArrayOfSize: and signed/unsigned might come into play as well.
Note that strictly speaking (as implemented by ZnBase64Encoder), Base64 is a binary to string encoding.
"String" is such a loose concept, binary -> safe ASCII subset, really. Since Stefâs motivation was understanding (which in my mind always includes *why* something is done), the implication of that, is that you can safely transmit the data over any medium, with no fear of any intermediary transaction participant misinterpreting the data. The cost of this is a 33% overhead (3 binary bytes -> 4 encoded bytes), which isnât all that bad compared to alternatives like using the hex printstring. (Which, by the way, was fairly recently added as the ânewâ standard binary format in postgres, Iâd love to see the discussion where THAT ended up as the preferred alternative⦠http://www.postgresql.org/docs/9.1/static/datatype-binary.html) Cheers, Henry
thanks for the discussion. Stef On 10 Mar 2014, at 13:22, Henrik Johansen <henrik.s.johansen@veloxit.no> wrote:
On 09 Mar 2014, at 9:50 , Sven Van Caekenberghe <sven@stfx.eu> wrote:
ZnBase64Encoder new encode: 42 asByteArray. => 'Kg=='
(ZnBase64Encoder new decode: 'Kg==') asInteger. => 42
There is also #asByteArrayOfSize: and signed/unsigned might come into play as well.
Note that strictly speaking (as implemented by ZnBase64Encoder), Base64 is a binary to string encoding.
"String" is such a loose concept, binary -> safe ASCII subset, really. Since Stefâs motivation was understanding (which in my mind always includes *why* something is done), the implication of that, is that you can safely transmit the data over any medium, with no fear of any intermediary transaction participant misinterpreting the data.
The cost of this is a 33% overhead (3 binary bytes -> 4 encoded bytes), which isnât all that bad compared to alternatives like using the hex printstring. (Which, by the way, was fairly recently added as the ânewâ standard binary format in postgres, Iâd love to see the discussion where THAT ended up as the preferred alternative⦠http://www.postgresql.org/docs/9.1/static/datatype-binary.html)
Cheers, Henry
participants (3)
-
Henrik Johansen -
Pharo4Stef -
Sven Van Caekenberghe