BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Object Serialization
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Hechicero
Guest





PostPosted: Wed Feb 09, 2005 3:39 pm    Post subject: Object Serialization Reply with quote



Hi,
I am programing an object serializer that unses RTTI in Delphi 7 and
has the following functionality : it backups the state of every published
property so they can be restored later through this serializer. It also
transform the objecto to an XML string and Vice-Versa.
The thing is this. I want to serialize an object A wich has a reference
to another object B. The serializer creates an XML for A only contanining A
properties, but not B properties. The solution I found in the first version
of the serializer is to store Bs memory address in the XML. Something like
this

A to XML (XML is not exactly as it is shown)
....
<Propertie>
<PropertyName>StringProp</PropertyName>
<PropertyType>string</PropertyName>
<Value>John Doe</Value>
</Propertie>
<Propertie>
<PropertyName>ObjectProp</PropertyName>
<PropertyType>Object</PropertyName>
<Value>Address(#65E4286E)</Value>
</Propertie>
....

The serializer works perfectly. But the problem is this. I dont feel
very confortable using memory addres and most importantly, If I wanted to
migrate my serializer to .NET, how should I do it.
I am not a very experienced .NET programing but as far as I know you
cannot work with pointers in .NET.

Esteban Calabria



Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Wed Feb 09, 2005 3:42 pm    Post subject: Re: Object Serialization Reply with quote



"Hechicero" <accesosecuencial (AT) yahoo (DOT) com.ar> a écrit dans le message de news:
[email]420a2eaf (AT) newsgroups (DOT) borland.com[/email]...

Quote:
The serializer works perfectly. But the problem is this. I dont feel
very confortable using memory addres and most importantly, If I wanted to
migrate my serializer to .NET, how should I do it.

You cannoy serialize memory addresses as it is not guaranteed over multiple
executions.

You need to include an integer ID for every object and have a mechanism for
allocating those IDs uniquely to every object when it is first serialized.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Jim Cooper
Guest





PostPosted: Wed Feb 09, 2005 3:51 pm    Post subject: Re: Object Serialization Reply with quote




Quote:
I am not a very experienced .NET programing but as far as I know you
cannot work with pointers in .NET.

Umm, but there is already a serializer in .NET. Will that not work for you?

Cheers,
Jim Cooper

__________________________________________

Jim Cooper [email]jcooper (AT) tabdee (DOT) ltd.uk[/email]
Tabdee Ltd http://www.tabdee.ltd.uk

TurboSync - Connecting Delphi to your Palm
__________________________________________

Back to top
Hechicero
Guest





PostPosted: Wed Feb 09, 2005 4:29 pm    Post subject: Re: Object Serialization Reply with quote

Yes of course. As a matter of fact I would do that if i had to serlialize
objects in .NET. The thing that came to my mind if I wanted to translate it
to .NET just for the fun of doing it... Is it possible?




Back to top
Hechicero
Guest





PostPosted: Wed Feb 09, 2005 4:30 pm    Post subject: Re: Object Serialization Reply with quote

Thanks Johana,
I thought so but...
By the way... if the serializer is meant to be used
only in the same execution and you want to reutilize in many projects where
not necesarily every object has an ID, do you have a miracolus idea of how
to do it?
As far as I my see it cannot be done Sad .


Esteban Calabria



Back to top
Marc Rohloff [TeamB]
Guest





PostPosted: Thu Feb 10, 2005 2:46 am    Post subject: Re: Object Serialization Reply with quote

On Wed, 9 Feb 2005 12:39:17 -0300, Hechicero wrote:

Quote:
I am programing an object serializer that unses RTTI in Delphi 7 and
has the following functionality : it backups the state of every published
property so they can be restored later through this serializer. It also
transform the objecto to an XML string and Vice-Versa.
The thing is this. I want to serialize an object A wich has a reference
to another object B. The serializer creates an XML for A only contanining A
properties, but not B properties. The solution I found in the first version
of the serializer is to store Bs memory address in the XML. Something like
this

You may want to look at QuickRTTI (www.bigattichouse.com) which
already does a lot of this. I don't know how it handles the object
references though.

--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com

Back to top
Martin Harvey (Demon Acco
Guest





PostPosted: Sat Feb 12, 2005 8:22 am    Post subject: Re: Object Serialization Reply with quote

On Wed, 9 Feb 2005 13:30:04 -0300, "Hechicero"
<accesosecuencial (AT) yahoo (DOT) com.ar> wrote:

Quote:
Thanks Johana,
I thought so but...
By the way... if the serializer is meant to be used
only in the same execution and you want to reutilize in many projects where
not necesarily every object has an ID, do you have a miracolus idea of how
to do it?

Yes. It looks like we're working on very similar systems: I'm
developing an object streaming system which will encode / decode
to/from XML, and also a binary format, which I suspect will look
distinctly like a TLV / KLV encoding.

The only way to do it is to make every object instance call a
registration routine in the streaming system, and generate a unique ID
per transaction. Actually this isn't as bad as it sounds: if you want
to stream just about anything, you may have to make the objects
implement helper functions that will enumerate fields in records /
arrays recursively.

Just a couple of thoughts:

1. How are you doing your XML parsing?
2. Is the streamable clase class in your library going to be fixed or
are you going to write it in such a manner that the base class can be
changed from project to project?

MH.


Back to top
Martin Harvey (Demon Acco
Guest





PostPosted: Sat Feb 12, 2005 11:43 pm    Post subject: Re: Object Serialization Reply with quote

On Wed, 9 Feb 2005 12:39:17 -0300, "Hechicero"
<accesosecuencial (AT) yahoo (DOT) com.ar> wrote:


Quote:
PropertyName>ObjectProp</PropertyName
PropertyType>Object</PropertyName
Value>Address(#65E4286E)

I notice that this grammer is not neccesarily LL(1) - depending on
what's in the value field, you might end up having to look ahead more
than 1 token. How are you parsing it.. is your parser hand written?

MH.

Back to top
Hechicero
Guest





PostPosted: Tue Feb 15, 2005 1:10 pm    Post subject: Re: Object Serialization Reply with quote

Martin,
The idea of registering the objects that are going to be
serialized so that they are given an internal OID for serialization is a
good one!. I want the serializer to be independent from the base class of
each object and to be reutilizable in many projects..
For now the XML we use is actually a binary format so I havent
dealed with XML parsing yet. The serialized object, for now, is never
persisted to disk

Esteban


Back to top
Martin Harvey (Demon Acco
Guest





PostPosted: Tue Feb 15, 2005 11:38 pm    Post subject: Re: Object Serialization Reply with quote

On Tue, 15 Feb 2005 10:10:02 -0300, "Hechicero"
<accesosecuencial (AT) yahoo (DOT) com.ar> wrote:

Quote:
Martin,
The idea of registering the objects that are going to be
serialized so that they are given an internal OID for serialization is a
good one!. I want the serializer to be independent from the base class of
each object and to be reutilizable in many projects..

Ah, ok. In that case, you might want to consider an earlier set of
posts under the topic "WANTED! Object streaming system" where I
discussed a simple solution to this problem which I'll call (for the
sake of a better word) a "heirarchy plug-in". Google groups for the
subject, and I'm sure it'll pop up fairly quick.

My streaming system hasn't got far I'm afraid... I've been busy at
work. I got as far as defining an intermediate representation for all
the data I wanted, wich was doing to fit into the scheme like this:

Read from stream: Write to stream:
<stream> <stream>
<lexer> <token writer>
<parser> <grammar generator>
<intermed. rep> <intermed. rep>
<stream manager> <stream amanger>
<heirarchy plugin> <heirarchy plugin>
<datastructure> <datastructure>

Hopefully, this

I was going to allow the plug-in to support custom written streaing
stuff so that you can support nested records / arrays - although they
will of course not be backed by RTTI.

I've only spent an hour or so on it (miserably slow progress), but the
definition looks like this - as you can see, my ID's are simply an
integer - not much here yet!

What I think will interest you in the Defn's below is TSSI
transaction, and the declarations in TSSIPropertyData for record,
array and class types.

unit SSIntermediates;
{
Copyright (c) Martin Harvey 2005.

This unit defines the intermediate representation of data in the
streaming system.
}
interface

uses Trackables;

type
TSSIntermediate = class (TTrackable);
//TODO - Can't think of anythign to put here at the mo.

TSSIList = class(TSSIntermediate)
private
protected
public
destructor Destroy; override;
destructor DestroySelfOnly; override;
published
end;

TSSITransaction = class(TSSIntermediate)
private
FInstances: TSSIList; //List of TSSIInstance
FInstancesData: TSSIList; //List of TSSIInstanceData
protected
public
destructor Destroy; override;
destructor DestroySelfOnly; override;
published
end;

TSSIInstance = class(TSSIntermediate)
private
FClassTypeString: string;
FObjId: integer;
protected
public
published
end;

TSSIInstanceData = class(TSSIntermediate)
private
FObjId: integer;
FProperties: TSSIList; //List of TSSIProperty
protected
public
destructor Destroy; override;
destructor DestroySelfOnly; override;
published
end;

{
Quick reminder from TypInfo:
TTypeKind = (tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat,
tkString, tkSet, tkClass, tkMethod, tkWChar, tkLString, tkWString,
tkVariant, tkArray, tkRecord, tkInterface, tkInt64, tkDynArray);
TTypeKinds = set of TTypeKind;

TOrdType = (otSByte, otUByte, otSWord, otUWord, otSLong);

TFloatType = (ftSingle, ftDouble, ftExtended, ftComp, ftCurr);

Properties that can be got and set via TypInfo that concern us boil
down to:
Ord, str, Float, Int64 (no need to worry about variants, methods &c)
We also need to add support for records, arrays and class references
}

TSSIMajorType = (sMajOrd, sMajStr, sMajFloat, sMajInt64, sMajRec,
sMajArray, sMajClass);
TSSIMinorType = (mitNone, //Major types without a subtype
//Ordinals
mitOSbyte, mitOUByte, mitOSWord, mitOUword,
mitOSLong
//Floats
mitFSingle, mitFDouble, mitFExtended);


TSSIPropertyData = record
PropType: TSSIMajorType;
PropSubType: TSSIMinorType;
PropName: string; //Just the name of this property, not
considering
//enclosing properties.
case TSSIMajorType of
sMajOrd: ( OrdData: Longint );
sMajStr: ( StrData: string );
sMajFloat: ( FloatData: extended );
sMajInt64: ( Int64Data: Int64 );
sMajRec, sMajArray: ( Items: TSSIList; );
//Records contain a list of TSSIProperty where the prop name
corresponds
//to the field in the data.
//Arrays contain a list of TSSIProperty where the prop name is
the integer
//index in the array (e.g. "1", "2" etc).
sMajClass: ( ObjId: string );
end;
end;

TSSIProperty = class(TSSIntermediate)
private
FPropData: TSSIPropertyData;
protected
public
destructor Destroy; override;
destructor DestroySelfOnly; override;
published
end;

implementation

end.

Back to top
Guenther Wimpassinger
Guest





PostPosted: Thu Mar 10, 2005 1:29 pm    Post subject: Re: Object Serialization Reply with quote


"Joanna Carter (TeamB)" <joanna (AT) nospam (DOT) co.uk> schrieb

Quote:
"Hechicero" <accesosecuencial (AT) yahoo (DOT) com.ar> a écrit dans le message

The serializer works perfectly. But the problem is this. I dont feel
very confortable using memory addres and most importantly, If I wanted to
migrate my serializer to .NET, how should I do it.

You cannoy serialize memory addresses as it is not guaranteed over multiple
executions.

You need to include an integer ID for every object and have a mechanism for
allocating those IDs uniquely to every object when it is first serialized.


Is the memory address of an object usable as an ID? The IDs are not
ordered nor they are autoincrementing, but does that really matter?

In .NET maybe you have to reimplement the "ID" property.

just an idea
Guenther



Back to top
Jim Cooper
Guest





PostPosted: Thu Mar 10, 2005 2:06 pm    Post subject: Re: Object Serialization Reply with quote


Quote:
Is the memory address of an object usable as an ID?

No, since it will be different every time the object is loaded. You will
get different objects having the same ID in different sessions and so on
- a bit of a nightmare Smile You also could not make a copy of an object.
In the storage mechanism you need to link objects together by ID, so you
cannot go changing it all the time, and they need to be unique (at least
within an object type).

Quote:
The IDs are not ordered nor they are autoincrementing, but does that really matter?

IDs do not have to be ordered or autoincrementing (eg GUIDs are neither)

It isn't essential to use integers as IDs (although they tend to be
quicker used as primary keys in databases the difference is not usually
noticeable). I use GUIDs since disconnected users can still create
objects and there isn't the hassle of reconciling IDs later on.

Cheers,
Jim Cooper

__________________________________________

Jim Cooper [email]jcooper (AT) tabdee (DOT) ltd.uk[/email]
Tabdee Ltd http://www.tabdee.ltd.uk

TurboSync - Connecting Delphi to your Palm
__________________________________________

Back to top
Martin Harvey (Demon Acco
Guest





PostPosted: Thu Mar 10, 2005 9:05 pm    Post subject: Re: Object Serialization Reply with quote

On Thu, 10 Mar 2005 14:29:20 +0100, "Guenther Wimpassinger"
<gw_spam (AT) pickem (DOT) at> wrote:

Quote:
Is the memory address of an object usable as an ID?

It depends. For the sort of serialisation I am doing (streaming to and
from disk) in theory, Yes ... because the ID's are simply used to look
up in a table sufficient information to re-create the class.

However, if you want ID's where you want to be able to compare them on
the fly, and not simply perform a creation from disk or a save to
disk, then probably not.

MH.

Back to top
Martin Harvey (work)
Guest





PostPosted: Tue Mar 29, 2005 12:22 pm    Post subject: Re: Object Serialization Reply with quote

"Hechicero" <accesosecuencial (AT) yahoo (DOT) com.ar> wrote


Quote:
Hi,

I am programing an object serializer that unses RTTI in Delphi 7 and

has the following functionality : it backups the state of every published

property so they can be restored later through this serializer. It also

transform the objecto to an XML string and Vice-Versa.

By the way, I've just written mine. It's currently in testing. I still have
a few small bugs to fix. How far through have you got? I'd estimate,
depending on how extensible your system needs to be that you're looking at
about 5,000 lines of code roughly ....

MH.



Back to top
Martin Harvey (work)
Guest





PostPosted: Tue Mar 29, 2005 12:31 pm    Post subject: Re: Object Serialization Reply with quote

Quote:
Value>John Doe</Value

By the way ... are you "escaping" strings correctly? What happens if I put a
string in:

This ' is ' a string containing a
MH.



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.