Jump to content

Autoit Serialize


 Share

Recommended Posts

 

About Serialize

Serialize a given value to get it's string representation, that you can later unSerialize back to its original value. Including nested arrays and objects. This is useful for storing and transferring data between applications.

2021-02-14 update: you can now serialize and unSerialize data in JavaScript as well. Checkout the official npm package or the github repo. This makes it possible to pass data between AutoIt and JavaScript applications. Eventually I will make an package for PHP aswell.

Limitations

  • Mutli dim arrays are not supported

Examples

Basic example

#include "Serialize.au3"
#include <Array.au3>
; Define some data
Global $array = [1,2,3]
; Serialize
Global $serialized = _Serialize($array)
MsgBox(64, "Serialized data", $serialized)
; Unserialize
Global $unSerialized = _UnSerialize($serialized)
_ArrayDisplay($unSerialized)

Objects and nesting

#include "Serialize.au3"
#include <Array.au3>
; Define some data
Global $preArray = [1, 2, 3]
Global $array = [5, 6, $preArray]
Global $obj = ObjCreate("Scripting.Dictionary")
$obj.add("firstName", "Tarre")
$obj.add("age", 29)
$obj.add("array", $array)
$obj.add("active", True)
; Serialize
Global $serialized = _Serialize($obj)
MsgBox(64, "Serialized data", $serialized)
; Unserialize
Global $unSerialized = _UnSerialize($serialized)
MsgBox(64, "Unserialized data", "firstName = " & $unSerialized.item("firstName") & @LF & "age = " & $unSerialized.item("age") & @LF & "active = " & $unSerialized.item("active"))
Global $array = $unSerialized.item("array")
Global $preArray = $array[2]
_ArrayDisplay($array, "$array")
_ArrayDisplay($preArray, "$preArray")

 

The code is also available on Github

Autoit-Serialize-1.0.0.zip

Edited by tarretarretarre
Link to comment
Share on other sites

2021-02-14 update: you can now serialize and unSerialize data in JavaScript as well. Checkout the official npm package or the github repo. This makes it possible to pass data between AutoIt and JavaScript applications. Eventually I will make an package for PHP aswell.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...