Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Torque is cheap.


devel / comp.lang.tcl / Re: How to set string to NULL (Hex value 00)

SubjectAuthor
* How to set string to NULL (Hex value 00)Torsten Berg
+- How to set string to NULL (Hex value 00)Christian Gollwitzer
`* How to set string to NULL (Hex value 00)Rich
 `- How to set string to NULL (Hex value 00)Torsten Berg

1
Re: How to set string to NULL (Hex value 00)

<be616bc7-9c98-4ecb-82b4-cd166e76709dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10610&group=comp.lang.tcl#10610

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:4ea2:0:b0:53a:714a:f81c with SMTP id ed2-20020ad44ea2000000b0053a714af81cmr132458qvb.15.1674948879851;
Sat, 28 Jan 2023 15:34:39 -0800 (PST)
X-Received: by 2002:a81:53c2:0:b0:506:6954:1da4 with SMTP id
h185-20020a8153c2000000b0050669541da4mr1762768ywb.171.1674948879690; Sat, 28
Jan 2023 15:34:39 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 28 Jan 2023 15:34:39 -0800 (PST)
In-Reply-To: <c4h2ub$258k$1@godfrey.mcc.ac.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=77.1.244.230; posting-account=ZxsDiAkAAAC9vQQOtXQfXsMvri8SBAlg
NNTP-Posting-Host: 77.1.244.230
References: <5gjk60p3hukfgvehk4i6p6loc7bev74557@4ax.com> <c4e1i2$2i2595$1@ID-102549.news.uni-berlin.de>
<c4h2ub$258k$1@godfrey.mcc.ac.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <be616bc7-9c98-4ecb-82b4-cd166e76709dn@googlegroups.com>
Subject: Re: How to set string to NULL (Hex value 00)
From: ber...@typoscriptics.de (Torsten Berg)
Injection-Date: Sat, 28 Jan 2023 23:34:39 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2939
 by: Torsten Berg - Sat, 28 Jan 2023 23:34 UTC

Wow, this is an old discussion ... but this is the problem I seem to have with Tcl 8.6.12 ...

I need to build a BLOB for a field in an SQLite table. It should start with these four bytes:

byte[2] magic = 0x4750;
byte version;
byte flags;

So, the first one is ASCII "GP", the second one should be a zero as an "8-bit unsigned integer" and the third one is a byte with flags that is "00000011" (only the two right-most bits are set) in my case. What I do is

binary format a2BB8 GP 0 00000011

Looking at the hex representation of the BLOB, it looks like this: "47 50 c0 80 03"
I can see the correct first two bytes (the "GP") and the last byte (the flags) but the NULL comes out as "c080".

Even if I do

set BLOB \x47\x50\x00\x03

I get the same output.

So, how do I get the BLOB to look like this (hex representation): "47 50 00 03"

On Thursday, April 1, 2004 at 2:43:49 PM UTC+2, Donal K. Fellows wrote:
> Michael Schlenker wrote:
> > So your above code probably should work, as co80 was a valid NULL in
> > some UTF-8, but nowadays this is broken.
> There was some discussion of this topic before Xmas between some UNICODE
> people and some of the Core Team. We couldn't reach agreement over what
> the right way forward was; their preferred solutions (which varied from
> making the app exit immediately to substituting such sequences with the
> UNICODE "unknown character sequence" character) would have broken far
> too much existing code and data for our taste, and our preferred
> solutions (which can be summed up largely by the IETF dictum "Be liberal
> in what you accept and strict in what you generate") had them throwing
> up their arms in horror. We did not see eye-to-eye... :^(
> Donal.

Re: How to set string to NULL (Hex value 00)

<tr5jg2$2nrah$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10613&group=comp.lang.tcl#10613

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: aurio...@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: How to set string to NULL (Hex value 00)
Date: Sun, 29 Jan 2023 11:58:10 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <tr5jg2$2nrah$1@dont-email.me>
References: <5gjk60p3hukfgvehk4i6p6loc7bev74557@4ax.com>
<c4e1i2$2i2595$1@ID-102549.news.uni-berlin.de>
<c4h2ub$258k$1@godfrey.mcc.ac.uk>
<be616bc7-9c98-4ecb-82b4-cd166e76709dn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 29 Jan 2023 10:58:10 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="35af1fe2a312bc5db02be37f72badb69";
logging-data="2878801"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yxisZrJYehvHNZC6A/nre1Odv24rWKd0="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Cancel-Lock: sha1:l5LroySWq0HWqnThl5onJDJLNB8=
In-Reply-To: <be616bc7-9c98-4ecb-82b4-cd166e76709dn@googlegroups.com>
 by: Christian Gollwitzer - Sun, 29 Jan 2023 10:58 UTC

Am 29.01.23 um 00:34 schrieb Torsten Berg:
> Wow, this is an old discussion ... but this is the problem I seem to have with Tcl 8.6.12 ...
>
> I need to build a BLOB for a field in an SQLite table. It should start with these four bytes:
>
> byte[2] magic = 0x4750;
> byte version;
> byte flags;
>
> So, the first one is ASCII "GP", the second one should be a zero as an "8-bit unsigned integer" and the third one is a byte with flags that is "00000011" (only the two right-most bits are set) in my case. What I do is
>
> binary format a2BB8 GP 0 00000011
>
> Looking at the hex representation of the BLOB, it looks like this: "47 50 c0 80 03"
> I can see the correct first two bytes (the "GP") and the last byte (the flags) but the NULL comes out as "c080".

This means that the string has been encoded in UTF-8. The problem is not
with "binary format", it is the transition from the string to the
database. For example, if you were writing the content to a file, you
would need to do "fconfigure $fd -encoding binary -translation binary"
to do so, and what you see is alike to "fconfigure $fd -encoding utf8".

Hence, you need to check the database interface layer if there is an
option to pass binary contents.

Christian

Re: How to set string to NULL (Hex value 00)

<tr5tql$2piqi$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10616&group=comp.lang.tcl#10616

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: How to set string to NULL (Hex value 00)
Date: Sun, 29 Jan 2023 13:54:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <tr5tql$2piqi$2@dont-email.me>
References: <5gjk60p3hukfgvehk4i6p6loc7bev74557@4ax.com> <c4e1i2$2i2595$1@ID-102549.news.uni-berlin.de> <c4h2ub$258k$1@godfrey.mcc.ac.uk> <be616bc7-9c98-4ecb-82b4-cd166e76709dn@googlegroups.com>
Injection-Date: Sun, 29 Jan 2023 13:54:29 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="dc88019474eaccf49546a08619447910";
logging-data="2935634"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BILrE588xbN5F/ZQDQVaO"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:RsEXTFHLTmyq1Ehm9qoGKxmZPRc=
 by: Rich - Sun, 29 Jan 2023 13:54 UTC

Torsten Berg <berg@typoscriptics.de> wrote:
> Wow, this is an old discussion ... but this is the problem I seem to have with Tcl 8.6.12 ...
>
> I need to build a BLOB for a field in an SQLite table. It should start with these four bytes:
>
> byte[2] magic = 0x4750;
> byte version;
> byte flags;
>
> So, the first one is ASCII "GP", the second one should be a zero as
> an "8-bit unsigned integer" and the third one is a byte with flags
> that is "00000011" (only the two right-most bits are set) in my case.
> What I do is
>
> binary format a2BB8 GP 0 00000011
>
> Looking at the hex representation of the BLOB, it looks like this:
> "47 50 c0 80 03"
>
> I can see the correct first two bytes (the "GP") and the last byte
> (the flags) but the NULL comes out as "c080".
>
> Even if I do
>
> set BLOB \x47\x50\x00\x03
>
> I get the same output.
>
> So, how do I get the BLOB to look like this (hex representation): "47 50 00 03"

You have not stated how you are looking at the "hex representation".
If you ask for the 'hex' in the normal Tcl way, it appears to work
properly:

$ rlwrap tclsh
% set blob [binary format a2BB8 GP 0 00000011]
GP
% binary scan $blob H* hex
1
% set hex
47500003
%

And as Christian pointed out, the hex you quote is the UTF-8 encoding
of the binary blob. So it looks like you are gaining a UTF-8 encoding
of the blob somewhere.

Re: How to set string to NULL (Hex value 00)

<ba2cda04-fbbe-4895-b4f3-3d1e1573086en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10623&group=comp.lang.tcl#10623

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:4113:b0:71d:8e0d:1280 with SMTP id j19-20020a05620a411300b0071d8e0d1280mr137440qko.399.1675018881329;
Sun, 29 Jan 2023 11:01:21 -0800 (PST)
X-Received: by 2002:a25:4b46:0:b0:7fd:7b0:5e89 with SMTP id
y67-20020a254b46000000b007fd07b05e89mr3808019yba.225.1675018881142; Sun, 29
Jan 2023 11:01:21 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sun, 29 Jan 2023 11:01:20 -0800 (PST)
In-Reply-To: <tr5tql$2piqi$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=77.1.33.92; posting-account=ZxsDiAkAAAC9vQQOtXQfXsMvri8SBAlg
NNTP-Posting-Host: 77.1.33.92
References: <5gjk60p3hukfgvehk4i6p6loc7bev74557@4ax.com> <c4e1i2$2i2595$1@ID-102549.news.uni-berlin.de>
<c4h2ub$258k$1@godfrey.mcc.ac.uk> <be616bc7-9c98-4ecb-82b4-cd166e76709dn@googlegroups.com>
<tr5tql$2piqi$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ba2cda04-fbbe-4895-b4f3-3d1e1573086en@googlegroups.com>
Subject: Re: How to set string to NULL (Hex value 00)
From: ber...@typoscriptics.de (Torsten Berg)
Injection-Date: Sun, 29 Jan 2023 19:01:21 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3546
 by: Torsten Berg - Sun, 29 Jan 2023 19:01 UTC

Hi,

and thanks for your thoughts! They made me read the SQLite documentation again carefully for the Tcl binding and the 'eval' command. I found this sentence:

"If the $bigstring variable has both a string and a "bytearray" representation, then TCL inserts the value as a string. If it has only a "bytearray" representation, then the value is inserted as a BLOB. To force a value to be inserted as a BLOB even if it also has a text representation, use a "@" character to in place of the "$"."

That did the trick!

On Sunday, January 29, 2023 at 2:54:34 PM UTC+1, Rich wrote:
> Torsten Berg <be...@typoscriptics.de> wrote:
> > Wow, this is an old discussion ... but this is the problem I seem to have with Tcl 8.6.12 ...
> >
> > I need to build a BLOB for a field in an SQLite table. It should start with these four bytes:
> >
> > byte[2] magic = 0x4750;
> > byte version;
> > byte flags;
> >
> > So, the first one is ASCII "GP", the second one should be a zero as
> > an "8-bit unsigned integer" and the third one is a byte with flags
> > that is "00000011" (only the two right-most bits are set) in my case.
> > What I do is
> >
> > binary format a2BB8 GP 0 00000011
> >
> > Looking at the hex representation of the BLOB, it looks like this:
> > "47 50 c0 80 03"
> >
> > I can see the correct first two bytes (the "GP") and the last byte
> > (the flags) but the NULL comes out as "c080".
> >
> > Even if I do
> >
> > set BLOB \x47\x50\x00\x03
> >
> > I get the same output.
> >
> > So, how do I get the BLOB to look like this (hex representation): "47 50 00 03"
> You have not stated how you are looking at the "hex representation".
> If you ask for the 'hex' in the normal Tcl way, it appears to work
> properly:
>
> $ rlwrap tclsh
> % set blob [binary format a2BB8 GP 0 00000011]
> GP
> % binary scan $blob H* hex
> 1
> % set hex
> 47500003
> %
>
> And as Christian pointed out, the hex you quote is the UTF-8 encoding
> of the binary blob. So it looks like you are gaining a UTF-8 encoding
> of the blob somewhere.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor