Object "Serialization"
[1/13] from: gjones05::mail::orion::org at: 22-Feb-2001 14:07
Hi,
In a separate thread, a question was asked about serialization of
objects by Sharriff Aina. I had a similar question in mind and was
hoping for an answer. Since the thread had gotten a bit off topic, I'm
reposting essentially the same question in this separate thread.
To date, when I want to save an object, I've been using 'save. Then
when I need the object back, I use 'read and then 'do the object.
For example:
data: make object! [
name: "Joe"
]
save %my-object.r data
;... later i need the object ...
data: read %my-object.r
data: do data
print data/name
>>
Joe
It works, but I am wondering is there a "better" way?
--Scott
[2/13] from: petr:krenzelok:trz:cz at: 22-Feb-2001 21:40
----- Original Message -----
From: GS Jones <[gjones05--mail--orion--org]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, February 22, 2001 9:07 PM
Subject: [REBOL] Object "Serialization"
> Hi,
> In a separate thread, a question was asked about serialization of
<<quoted lines omitted: 12>>
> data: do data
> print data/name
use 'load instead of 'read? Then you don't need to 'do the 'data ...
-pekr-
[3/13] from: gjones05:mail:orion at: 22-Feb-2001 15:36
> > In a separate thread, a question was asked about serialization of
> > objects by Sharriff Aina. I had a similar question in mind and was
> > hoping for an answer. Since the thread had gotten a bit off topic,
I'm
> > reposting essentially the same question in this separate thread.
> >
<<quoted lines omitted: 15>>
> use 'load instead of 'read? Then you don't need to 'do the 'data ...
> -pekr-
Thanks, that is a good point!
Scott
[4/13] from: gjones05:mail:orion at: 22-Feb-2001 16:32
> > > In a separate thread, a question was asked about serialization of
> > > objects by Sharriff Aina. I had a similar question in mind and
was
> > > hoping for an answer. Since the thread had gotten a bit off
topic,
> I'm
> > > reposting essentially the same question in this separate thread.
> > >
> > > To date, when I want to save an object, I've been using 'save.
Then
> > > when I need the object back, I use 'read and then 'do the object.
> > >
<<quoted lines omitted: 15>>
> Thanks, that is a good point!
> Scott
Actually, when I tried it, simply using 'load did not re-initialize the
object (unless I am missing some additional subtle point). I played
with several additional variations, with the same conclusions. So I
guess the way I've been doing it will have to be good enough. It still
seems as though there should be a more seemless and coherent way to
serialize the object.
Thanks for your attention, pekr.
--Scott
[5/13] from: rgombert:essentiel at: 23-Feb-2001 0:39
Maybe this script could be of some help. It's intended to allow to save and
retrieve a word/value pair in a file.
It is an early version i've made while learning REBOL.
An example : I put the script in the word 'file, then save this word, give
it another value then reload the initial one.
the scipt is 845 bytes long, and the disk data only 443.
Any comment welcome
Renaud
-----------------------------------------------------------------
sample session for the example:
-----------------------------------------------------------------
>> file: read %scripts/binutils.r
== {REBOL [
Title: "Nom du script"
File: %binutils.r
Date: 4-Jun-1999
Author: "Renaud GOMBERT"
Purpose: "Save...
>> put-bin file %data.bin
>> file: 456
== 456
>> file
== 456
>> get-bin %data.bin
== {REBOL [
Title: "Nom du script"
File: %binutils.r
Date: 4-Jun-1999
Author: "Renaud GOMBERT"
Purpose: "Save...
>> file
== {REBOL [
Title: "Nom du script"
File: %binutils.r
Date: 4-Jun-1999
Author: "Renaud GOMBERT"
Purpose: "Save...
>>
-----------------------------------------------------------------
The scipt itself:
-----------------------------------------------------------------
REBOL [
Title: "Nom du script"
File: %binutils.r
Date: 4-Jun-1999
Author: "Renaud GOMBERT"
Purpose: "Save and retrieve any word/value pair as binary"
To-do: {
Make a refinement to do compressions only if needed
Allow processing of multiple word/value pairs at one time
}
Release: 0.0.1
Category: []
]
put-bin: func [ "Save word/value pair as compressed binary"
'data [any-type!] "word to process"
filename [file!] "file to write to"
/local temp
][
temp: make object! [
value: get data
name: data
]
write/binary filename compress to-binary mold temp
]
get-bin: func [ "Save word/value pair as compressed binary"
filename [file!] "file to get word/value from"
/local temp
][
temp: do decompress read/binary filename
set temp/name temp/value
]
[6/13] from: agem:crosswinds at: 23-Feb-2001 0:30
>>>>>>>>>>>>>>>>>> Ursprüngliche Nachricht <<<<<<<<<<<<<<<<<<
Am 22.02.01, 23:32:53, schrieb "GS Jones" <[gjones05--mail--orion--org]> zum
Thema [REBOL] Re: Object "Serialization":
> > > > In a separate thread, a question was asked about serialization of
> > > > objects by Sharriff Aina. I had a similar question in mind and
<<quoted lines omitted: 27>>
> > Scott
> Actually, when I tried it, simply using 'load did not re-initialize
the
> object (unless I am missing some additional subtle point). I played
> with several additional variations, with the same conclusions. So I
> guess the way I've been doing it will have to be good enough. It
still
> seems as though there should be a more seemless and coherent way to
> serialize the object.
data: do %my-object.r
before that you have like
>> a: [make object! []]
== [make object! []]
>> a/1
== make
>> a/2
== object!
So load gives »source«, do »compiles« it.
Note 'save of strings has some bugs before last /core-experimental,
specially with »{». do not:
>> mold "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{"
== {{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{}}
>> load mold
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{
** Syntax Error: Invalid string --
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{}.
** Where: (line 1)
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{}
because you have to balance »{» or escape it, and there is no escaped
»{» in old rebols.
/core 2.4.40 does it ok:
>> mold "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{"
==
{^{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^^^{^}}
also
>> mold %""
== "%"
>> load mold %""
** Syntax Error: Invalid file -- %
** Near: (line 1) %
and pathes have problems
>> a: first [this/that]
== this/that
>> mold a
** Script Error: this has no value
** Near: mold a
because they get evaluatet by mold.
Don't know if someone want to save pathes?
Then, 'save is similar to copy/deep, so if you have two references to
the same object,
there are two seperate objects after 'do .
And of course if you rely on contexts (hand-made bind), this will not
save correctly.
Knowing this, 'save / 'do is very handy, don't know of a better way.
(hope i have mentioned all?)
But, some while ago someone said he has written a serialisation which
handles some of this problems
and will post it if someone asks?
Volker
[7/13] from: gjones05:mail:orion at: 22-Feb-2001 18:57
From: Volker Nitsch
<snip>
> Note 'save of strings has some bugs before last /core-experimental,
> specially with »{». do not:
Thanks, Volker, I didn't know this. Rather I should say that I wasn't
aware of this, but that may explain why I had some problems in some
trials. No way to know now.
> Then, 'save is similar to copy/deep, so if you have two references to
> the same object,
> there are two seperate objects after 'do .
> And of course if you rely on contexts (hand-made bind), this will not
> save correctly.
Also good to know.
> Knowing this, 'save / 'do is very handy, don't know of a better way.
> (hope i have mentioned all?)
>
> But, some while ago someone said he has written a serialisation which
> handles some of this problems
I guess that this point was what I was getting at. I should go search
escribe for old posts on this topic. (I guess I should have done that
before asking in the first place. :)
Thanks. --Scott
[8/13] from: sharriff:aina:med-iq at: 23-Feb-2001 6:35
Great script Renaud! this would do till RT builds in Object serialisation
into REBOL or someone writes a module/ Library..
Regards
Sharriff Aina
"Renaud"
<[rgombert--esse] An: <[rebol-list--rebol--com]>
ntiel.net> Kopie:
Gesendet von: Thema: [REBOL] Re: Object "Serialization"
[rebol-bounce--r]
ebol.com
22.02.01 23:39
Bitte
antworten an
rebol-list
Maybe this script could be of some help. It's intended to allow to save and
retrieve a word/value pair in a file.
It is an early version i've made while learning REBOL.
An example : I put the script in the word 'file, then save this word, give
it another value then reload the initial one.
the scipt is 845 bytes long, and the disk data only 443.
Any comment welcome
Renaud
-----------------------------------------------------------------
sample session for the example:
-----------------------------------------------------------------
>> file: read %scripts/binutils.r
== {REBOL [
Title: "Nom du script"
File: %binutils.r
Date: 4-Jun-1999
Author: "Renaud GOMBERT"
Purpose: "Save...
>> put-bin file %data.bin
>> file: 456
== 456
>> file
== 456
>> get-bin %data.bin
== {REBOL [
Title: "Nom du script"
File: %binutils.r
Date: 4-Jun-1999
Author: "Renaud GOMBERT"
Purpose: "Save...
>> file
== {REBOL [
Title: "Nom du script"
File: %binutils.r
Date: 4-Jun-1999
Author: "Renaud GOMBERT"
Purpose: "Save...
>>
-----------------------------------------------------------------
The scipt itself:
-----------------------------------------------------------------
REBOL [
Title: "Nom du script"
File: %binutils.r
Date: 4-Jun-1999
Author: "Renaud GOMBERT"
Purpose: "Save and retrieve any word/value pair as binary"
To-do: {
Make a refinement to do compressions only if needed
Allow processing of multiple word/value pairs at one time
}
Release: 0.0.1
Category: []
]
put-bin: func [ "Save word/value pair as compressed binary"
'data [any-type!] "word to process"
filename [file!] "file to write to"
/local temp
][
temp: make object! [
value: get data
name: data
]
write/binary filename compress to-binary mold temp
]
get-bin: func [ "Save word/value pair as compressed binary"
filename [file!] "file to get word/value from"
/local temp
][
temp: do decompress read/binary filename
set temp/name temp/value
]
[9/13] from: coussement:c:itc:mil:be at: 23-Feb-2001 9:04
Hi Sharriff Aina:
If you're concerned about object serialization, I use it too in my 'OODB
foundations' I'm working on...
Just have a look at http://www.geocities.com/reboldev/ in 'OODB
Foundations', more precisely to the 'store function of the 'dbo object and
at the 'mediator object.
Hope it helps.
chr==
[10/13] from: sharriff:aina:med-iq at: 23-Feb-2001 8:36
Thanks Christophe! I´ll take a look as soon as possible
Sharriff Aina
med.iq information & quality in healthcare AG
CRS - Psy
Sel/SPO, An: [rebol-list--rebol--com]
COUSSEMENT Kopie:
Christophe, CPN Thema: [REBOL] Re: Object "Serialization"
<[COUSSEMENT--C--I]
TC.mil.be>
Gesendet von:
[rebol-bounce--re]
bol.com
23.02.01 08:04
Bitte antworten
an rebol-list
Hi Sharriff Aina:
If you're concerned about object serialization, I use it too in my 'OODB
foundations' I'm working on...
Just have a look at http://www.geocities.com/reboldev/ in 'OODB
Foundations', more precisely to the 'store function of the 'dbo object and
at the 'mediator object.
Hope it helps.
chr==
[11/13] from: rgombert:essentiel at: 23-Feb-2001 9:54
----- Original Message -----
From: <[Sharriff--Aina--med-iq--de]>
To: <[rebol-list--rebol--com]>
Sent: Friday, February 23, 2001 7:35 AM
Subject: [REBOL] Antwort: Re: Object "Serialization"
> Great script Renaud! this would do till RT builds in Object serialisation
> into REBOL or someone writes a module/ Library..
Thanks...
Here is the second version, wich can proceed with individual words or word
list. This script need more basic error checking (file existence, etc...)
but as i do not have yet a really deep understanding of REBOL, maybee some
of the wizards here may find some deeper hidden potential problem.
Renaud
ICQ# 2602184
REBOL [
Title: "Word/Value pair(s) binary saver"
File: %binutils.r
Date: 22-Feb-2001
Author: "Renaud GOMBERT"
Email: [rgombert--essentiel--net]
Purpose: "Save and retrieve any word/value pair(s) in binary files"
To-do: {
Make a refinement to do compression only if needed
}
Done: {
Allow processing of multiple word/value pairs at one time
}
Release: 0.1.0
Category: []
]
put-bin: func [ "Save word/value pair(s) as compressed binary"
'data [word! block!] "word or word list to process"
filename [file!] "file to write to"
/local temp
][
temp: make object! [
value: copy []
name: copy []
]
either (type? data) = word! [
temp/value: get data
temp/name: data
][
foreach item data [
append/only temp/value get item
append temp/name make lit-word! item
]
]
write/binary filename compress to-binary mold temp
]
get-bin: func [ "Load word/value pair(s) from a compressed binary"
filename [file!] "file to get word/value from"
/local temp i
][
temp: do decompress read/binary filename
either (type? temp/name) = word! [
set temp/name temp/value
][
i: 1
foreach item temp/value [
set temp/name/:i item
i: i + 1
]
]
]
[12/13] from: fsievert:uos at: 23-Feb-2001 9:46
You can try my 'enpack script, which not only saves a value, but all it's
binding information, too.
Example:
>> do http://proton.cl-ki.uni-osnabrueck.de/REBOL/enpack.r
>> use [a] [a: 9 mem: enpack [print a + 1]]
>> do depack mem
10
>> a
** Script Error: a has no value
** Near: a
Works with objects etc., too.
CU,
Frank
On Thu, 22 Feb 2001, GS Jones wrote:
[13/13] from: gjones05:mail:orion at: 23-Feb-2001 5:43
From: Frank Sievertsen
> You can try my 'enpack script, which not only saves a value, but all
it's
> binding information, too.
> Example:
<<quoted lines omitted: 6>>
> ** Near: a
> Works with objects etc., too.
Wow, Frank, I asked for a pence and you gave me a pound. Thanks! I can
readily appreciate the value of saving the context with the information
structure, especially in an application that is generating information
dynamically. In order to try it out, I set up some test objects with
methods that alter the static information, and, needless to say, it
worked great. I feel certain that this approach will come in handy
someday. To be honest, though, my REBOL skills are too new to be able
to understand *how* you did this, but that will come with time.
Thanks! --Scott
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted