Page 1 of 1
SaveStructuredData to File
Posted: Tue Jul 23, 2013 1:55 pm
by Rapido
Please add
Load/SaveStructuredData function, to recursive collect all fields in one memory buffer
or/and
ExamineStructure,
NextStructureField() .
Code: Select all
Structure CC
Array a.c(1,5)
b${5}
c.s[10]
;StructureUnion
;EndStructureUnion
EndStructure
Structure BB
;*Nextbb.BB
List a$()
Map b.CC()
EndStructure
Structure AA
a.b
b.l[4]
c$
d.BB
e.q
f.i
EndStructure
Define Test.AA
*Buff=SaveStructuredData(@Test,AA)
Define Test2.AA
LoadStructuredData(@Test2,AA,*Buff)
Re: SaveStructuredData to File
Posted: Tue Jul 23, 2013 2:18 pm
by Lebostein
Re: SaveStructuredData to File
Posted: Tue Jul 23, 2013 2:28 pm
by Shield
This would require additional information to be stored about the structure and all its fields,
therefore bloating up the program. I don't know what that fancy new "Runtime" library is doing,
maybe it contains something into that direction.
Also I am not sure if such a functionality really is that useful.
It might look cool at first but if you look closer you will see some flaws
that will come into play, such as version dependency (if something changes in a new
PB version, you can't load old serialized structures anymore).
This is also a problem in languages that natively support serialization and reflection.
Re: SaveStructuredData to File
Posted: Tue Jul 23, 2013 3:27 pm
by User_Russian
Shield wrote:This would require additional information to be stored about the structure and all its fields,
therefore bloating up the program. I don't know what that fancy new "Runtime" library is doing,
maybe it contains something into that direction.
Information fields structure is stored in the program. It uses many functions, for example, InitializeStructure(), CopyStructure(), etc.
Re: SaveStructuredData to File
Posted: Tue Jul 23, 2013 5:32 pm
by Shield
No, InitializeStructure and CopyStructure are compiler functions, which, to my understanding,
means that those aren't real functions but rather cause the compiler to generate code with
different behavior based on the arguments used.
Re: SaveStructuredData to File
Posted: Tue Jul 23, 2013 5:41 pm
by User_Russian
This is not the case.
For example.
Code: Select all
Structure y
x.l
y.l
EndStructure
Structure z
x.l
y.f
List ll.y()
Array aa.y(10)
EndStructure
x.z
ClearStructure(x, z)
InitializeStructure(x, z)
See part of the assembly code.
Code: Select all
; ClearStructure(x, z)
MOV eax,dword v_x
PUSH dword s_z
PUSH dword 20
PUSH eax
CALL _SYS_ClearStructure@12
;
; InitializeStructure(x, z)
MOV eax,dword v_x
PUSH dword s_z
PUSH eax
CALL _SYS_InitDynamicStructure@8
Description of the structure.
Code: Select all
s_s:
dd 0
dd -1
s_z:
dd -5,8,8,0,7
dd -4,16,8,11,7,0
dd -1
Re: SaveStructuredData to File
Posted: Tue Jul 23, 2013 10:30 pm
by Fred
It only store dynamic objects info, not all structure fields.
Re: SaveStructuredData to File
Posted: Wed Jul 24, 2013 1:43 pm
by User_Russian
But it function ClearStructure() somehow clears structure? Why then can not copy data from the structure in memory (for example, to write to a file or transmission over the network)?
Re: SaveStructuredData to File
Posted: Wed Jul 24, 2013 3:09 pm
by STARGĂ…TE
here a old example
for x86, to get structure from a array:
Code: Select all
Structure StructureData
StructureUnion
Position.i
Type.i
EndStructureUnion
StructureUnion
ArraySize.i
ListPosition.i
EndStructureUnion
StructureUnion
ArrayPosition.i
ListStructureSize.i
EndStructureUnion
StructureUnion
SubStructureSize.i
AData.i
*ListStructureData
EndStructureUnion
*SubStructureData
Laber.i
EndStructure
#StructureData_String = 0
#StructureData_End = -1
#StructureData_FixArary = -2
#StructureData_Sub = -3
#StructureData_Array = -4
#StructureData_List = -5
#StructureData_Map = -6
Procedure.s GetStructureData_Proc(*StructureData.StructureData, StructureSize)
Protected String$, Buffer, CurrentPosition
With *StructureData
While *StructureData And \Type <> #StructureData_End
If String$ : String$ + ", " : EndIf
Select \Type
Case #StructureData_List
Buffer = \ListPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
String$ + "List{"+GetStructureData_Proc(\ListStructureData, \ListStructureSize)+"}"
CurrentPosition + Buffer + 8
*StructureData + SizeOf(StructureData)-4
Case #StructureData_Map
Buffer = \ListPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
String$ + "Map{"+GetStructureData_Proc(\ListStructureData, \ListStructureSize)+"}"
CurrentPosition + Buffer + 4
*StructureData + SizeOf(StructureData)-4
Case #StructureData_Array
Buffer = \ListPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
If \AData > 1
String$ + "Array(" + Str(\AData) + "){"
String$ + GetStructureData_Proc(\Laber, \ListStructureSize)
String$ + "} "
Else
String$ + GetStructureData_Proc(\Laber, \ListStructureSize)
EndIf
CurrentPosition + Buffer +4
*StructureData + SizeOf(StructureData)
Case #StructureData_FixArary
Buffer = \ArrayPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
If \ArraySize > 1
String$ + "Sub(" + Str(\ArraySize) + "){"
String$ + GetStructureData_Proc(\SubStructureData, \SubStructureSize)
String$ + "} "
Else
String$ + GetStructureData_Proc(\SubStructureData, \SubStructureSize)
EndIf
CurrentPosition + Buffer + \ArraySize * \SubStructureSize
*StructureData + SizeOf(StructureData)-4
Case #StructureData_Sub
Buffer = \ListPosition - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
String$ + GetStructureData_Proc(\ListStructureData, \ListStructureSize)
CurrentPosition + Buffer + \ListStructureSize
*StructureData + SizeOf(StructureData)-8
Default
Buffer = \Position - CurrentPosition
If Buffer : String$ + "Data["+Str(Buffer)+"], " : EndIf
String$ + "String"
CurrentPosition + Buffer + SizeOf(String)
*StructureData + SizeOf(Integer)
EndSelect
Wend
Buffer = StructureSize - CurrentPosition
If String$ : String$ + ", " : EndIf
If Buffer : String$ + "Data["+Str(Buffer)+"]" : EndIf
EndWith
ProcedureReturn String$
EndProcedure
Macro GetArrayStructureData(ArrayName, StructureName)
GetStructureData_Proc(PeekI(@ArrayName-16), SizeOf(StructureName))
EndMacro
;- Beispiel
Structure SubComplex
Long.l
String.s
Map Words.w()
Float.f
EndStructure
Structure Complex
Long.l
Byte.b
String.s
FixArray.c[7]
FisString.s{3}
Array ComplexArray.SubComplex(40)
Double.d
List ComplexList.SubComplex()
Complex.SubComplex
EndStructure
Dim Beispiel.Complex(1)
Debug GetArrayStructureData(Beispiel(), Complex)