Object serialization: Difference between revisions

Added FreeBASIC
(→‎Insitux: inclusion)
(Added FreeBASIC)
 
(One intermediate revision by one other user not shown)
Line 889:
}
</pre>
 
=={{header|FreeBASIC}}==
FreeBASIC does not support object-oriented programming such as classes and inheritance directly. However, we can simulate some aspects of object-oriented programming using procedures and user-defined types (UDTs).
 
For serialization, FreeBASIC does not have built-in support for this. We need to manually write and read each field of your UDTs to and from a file.
<syntaxhighlight lang="vbnet">Type Person
nombre As String
edad As Integer
End Type
 
Sub PrintPerson(p As Person)
Print "Name: "; p.nombre
Print "Age: "; p.edad
End Sub
 
Sub Serialize(p As Person, filename As String)
Open filename For Binary As #1
Put #1, , p.nombre
Put #1, , p.edad
Close #1
End Sub
 
Sub Deserialize(p As Person, filename As String)
Open filename For Binary As #1
Get #1, , p.nombre
Get #1, , p.edad
Close #1
End Sub
 
Dim pp As Person
pp.nombre = "Juan Hdez."
pp.edad = 52
 
Serialize(pp, "objects.dat")
Deserialize(pp, "objects.dat")
 
PrintPerson(pp)
 
Sleep</syntaxhighlight>
{{out}}
<pre>Name: Juan Hdez.
Age: 52</pre>
 
=={{header|Go}}==
Line 2,548 ⟶ 2,590:
{{libheader|Wren-json}}
Currently, Wren's only facility for serializing objects is to use the above JSON module. Also this module can only 'stringify' objects of built-in types so we need to provide a suitable string representation for each user-defined class.
<syntaxhighlight lang="ecmascriptwren">import "./json" for JSON
import "io" for File, FileFlags
 
2,122

edits