[Lib] ObjDump / ObjLoad - Object Backup

Post your working scripts, libraries and tools for AHK v1.1 and older
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: [Lib] ObjDump / ObjLoad - Object Backup

25 Jul 2018, 15:56

Code: Select all

SendObject :=	{
                  x: 2
                }
                        
x:=objdump(sendObject)
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

25 Jul 2018, 15:58

Should be size:=ObjDump(sendObject,variable)
Data will be saved in variable!
Are you using v1 or v2?
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: [Lib] ObjDump / ObjLoad - Object Backup

25 Jul 2018, 16:18

Sorry - my bad. Example that fails using AHK v2 and objdump.ahk for v2:

Code: Select all

SendObject :=	{
                  x: 2
                }
                        
size := objdump(sendObject, variable)
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: [Lib] ObjDump / ObjLoad - Object Backup

26 Jul 2018, 10:41

HotKeyIt: Are you getting the same error?
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: [Lib] ObjDump / ObjLoad - Object Backup

26 Jul 2018, 11:22

@SAbboushi, when I run this code

Code: Select all

SendObject :=	{
                  x: 2
                }
                        
size := objdump(sendObject, variable)

msgbox("The variable is " . variable)

ExitApp
I get the value of the variable as a Unicode character the forum isn't printing. Are those your results too?
Capture.PNG
Capture.PNG (16.47 KiB) Viewed 3351 times
Regards,
burque505
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: [Lib] ObjDump / ObjLoad - Object Backup

26 Jul 2018, 13:57

Thanks for your efforts but no - I get the same error I posted earlier
Error in #include file "J:\StandaloneApps\AutoHotkeyV2\Lib\objdump.ahk":
Type mismatch.

Line#
046: objects[obj]:=1
047: For k,v in obj
048: {
049: if IsObject(k)
050: sz+=objects.HasKey(k)?9:RawObjectSize(k,buf,objects)+9
051: Else
051: if Type(k)="String"
---> 052: sz+=StrPut(k)*2+9
053: Else
053: sz+=InStr(k,".")||k>4294967295?9:k>65535?5:k>255?3:k>-129?2:k>-32769?3:k>-2147483649?5:9
054: if IsObject(v)
055: sz+=objects.HasKey(v)?9:RawObjectSize(v,buf,objects)+9
056: Else
056: if Type(v)="String"
057: sz+=(buf?obj.GetCapacity(k):StrPut(v)*2)+9

The current thread will exit.
sz is unitialized and the math operation throws an error. I started to update the code to make it compliant with latest version of AHK V2, but it's not the only line that needs correcting. And I started correcting the other 2 object serializers that seem to suffer similar problems - don't have the time to debug such compressed unfriendly code for my simple application.

If anyone knows of an object serializer/deserializer that works with latest version of AHK V2, please let me know.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

28 Jul 2018, 09:20

Should be fixed now:

Code: Select all

SendObject :=	{
                  x: 2
                }
                        
size := objdump(sendObject, variable)

msgbox("The size of dumped memory is " size " bytes")
obj:=ObjLoad(&variable)
MsgBox obj.x
ExitApp
bourdin07
Posts: 36
Joined: 23 Jun 2019, 12:57

Re: [Lib] ObjDump / ObjLoad - Object Backup

12 Aug 2019, 10:55

i'd like to dump a COM Object but the app crash

Code: Select all

objDump(A_ScriptDir "\test.bin", ComObjCreate("MSXML2.DOMDocument"))
It will be really nice.

It is possible and how?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [Lib] ObjDump / ObjLoad - Object Backup

12 Aug 2019, 11:03

no. this is meant for ahk arrays and objects
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: [Lib] ObjDump / ObjLoad - Object Backup

10 Mar 2023, 14:01

I would love to see this converted to the current V2 syntax
ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

21 Oct 2023, 05:12

a noob question : why use this method when we can convert objects into json and then file append ? can any body point out the pros and cons
teadrinker
Posts: 4370
Joined: 29 Mar 2015, 09:41
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

21 Oct 2023, 06:29

Not everything that AHK objects support also JSON supports. For example, an AHK object may contain a reference to itself, the object's key may be another object.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: jsong55 and 127 guests