Re: even better coerce to record with usrf
Re: even better coerce to record with usrf
- Subject: Re: even better coerce to record with usrf
- From: Arthur J Knapp <email@hidden>
- Date: Fri, 14 Dec 2001 13:25:21 -0500
>
Date: Fri, 14 Dec 2001 08:26:15 -0800
>
Subject: Re: even better coerce to record with usrf
>
From: Paul Berkowitz <email@hidden>
>
To: Applescript-Users <email@hidden>
>
On 12/14/01 7:21 AM, "Arthur J Knapp" <email@hidden> wrote:
>
>
> I see that you didn't care for my faster method: ;-)
>
>
>
> on IntegerToBytes(n)
>
>
>
> return ({{a:n}} as string)'s text -4 thru -1
>
Arthur,
>
>
I must admit I've missed all of this. It seemed rather too esoteric for me.
>
But now I'm intrigued: what threads, or links, should i go to read up on
>
this?
I have no idea where you can read up on this. Every thing I know
has come from trial & error, as well as from discussions on this list.
>
... What's it do anyway? When I try out the line in the middle of it,
>
using the number 12 for n, all I get is a non-printing square character in
>
quotes (in SD 3). If I omit the text -4 thru -1 bit I get
>
"usrflistTEXTalong"
Yeah, allow me to try to explain as much as I know:
set dataString to {{a:12}} as string
set dataAscii to every character of dataString
repeat with i in dataAscii
set i's contents to ASCII number i
end repeat
(*
* 0, 0, 0, 1, 0, 0, 0, 0, 117, 115, 114, 102,
* 108, 105, 115, 116, 0, 0, 0, 30, 0, 0, 0, 2,
* 0, 0, 0, 0, 84, 69, 88, 84, 0, 0, 0, 1, 97,
* 0, 108, 111, 110, 103, 0, 0, 0, 4,
* 0, 0, 0, 12
*)
-- Let me rewrite the above in an understandable way,
-- (all whitespace is mine):
(* 1) 0001 0000 usrf
* 2) list (30) 0002 0000
* 3) TEXT 0001 a 0
* 4) long 0004 (12)
*)
Line 1 is some type of header. This is appearently what
allows AppleScript to know that the data is a record of
some kind.
Line 2 identifies a "list" type. The (30) is actually
(ASCII number 0) & (ASCII number 0) & (ASCII number 0) &
(ASCII number 30). This type of data is called a "long",
where 4 bytes are used to represent a numerical value. You
can think of the number system as being base 256, ie: the
right-most byte is the ones place, the second byte from the
right is the 256ths place, etc.
The (30) indicates that the list's data is 30 bytes in
length, ie: count the bytes following 30. I refer to this
as the "data-size".
The 0002 following the data-size is another "long",
indicating how many items are in the list. The 0000
following that is appearently another long, though
I don't know what it's purpose is. It always follows
a "list"'s data-size.
Line 3 is the data for the record label "a". It's
type is given first, "TEXT". Although record properties
are not considered "strings" in AppleScripting, they
are in this data-structure.
Next is the data-size, a "long" indicating the number 1,
(ie: "a" is one byte). If the label had been {Hello:"Paul"},
then the data-size would be 5, (0005).
It is also important to notice the final ASCII number 0
on this line. Appearently, AppleScript needs to "pad"
values whose data-size is not even. The data-size does not
reflect this.
Line 4 is the value of a of {a:12}, ie: it is the number
12 itself. First the type, "long". Then the data-size,
0004, (4). Last, the number-as-long itself: 0 0 0 12.
A more generic way to describe all of this is as follows:
long(1) & long(0) & "usrf"
"list" & dataSize(30) & itemCount(2) & long(0)
"TEXT" & dataSize(1) & "a" & nullPadByte
"long" & dataSize(4) & long(12)
I'm not good at explaining these sort of things, but
I hope some of this was enlightening.
P.S. I'm still just a scripter...
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
try
<
http://www.AppleScriptSourcebook.com/>
on error number -128
end try
}