[Gambas-user] Issues when writing and reading structures
Brian G
brian at westwoodsvcs.com
Tue Mar 21 20:57:10 CET 2023
When a structure containing a string is written the first byte is the length
But when it is read back as the structure it does not use the length byte but does include the len byte into the string field.
I am not sure if this is correct or not.
p.s. is it possible to have varptr return the memory address of the structure as you can assign a pointer to a structure object.
Is this correct or is it a bug, not sure? But I would like to send structured data to another client and recieve it on that side
the follow script demonstrates:
#!/usr/bin/env gbs3
' Gambas Script File Created 03/21/2023 12:39:45
Public Struct elevation
a As Short
b As Long
c As Float
d As Short
e As String
End Struct
Public Sub main()
Dim a As Elevation
Dim aa As Elevation
Dim aaa As Elevation
Dim p As Pointer = Alloc(10000)
Dim pp As Pointer = Alloc(10000)
Dim ppp as pointer = Alloc(10000)
a = ppp
a.a = 45
a.b = 98765
a.c = 67.456
a.d = 1
a.e = "hello a.........."
aa = pp
aa.a = 45
aa.b = 98765
aa.c = 67.465
aa.d = 1
aa.e = "hello aa........"
Dim f As File
f = Memory p For Write
Write #f, a As Variant
Close #f
f = Memory p For Read
aaa = Read #f As Elevation
Print "Original :";
For i As Integer = 0 To 50
Print Hex(Byte@(ppp + i), 2);;
Next
Print
print "Write :";
For i As Integer = 0 To 50
Print Hex(Byte@(p + i), 2);;
Next
Print
Print "Check Block :";
For i As Integer = 0 To 50
Print Hex(Byte@(pp + i), 2);;
Next
Print
Print "a :";a.a, a.b, a.c, a.d, a.e
Print "aaa :";aaa.a, aaa.b, aaa.c, aaa.d, aaa.e
Print "aa :";aa.a, aa.b, aa.c, aa.d, aa.e
Free(p)
Free(pp)
Quit 0
Catch
error "Script Error >";;error.text & "\n" & error.where
end
"Failure is the key to success;
each mistake teaches us something" .. Morihei Ueshiba
Brian G
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230321/4d97df14/attachment.htm>
More information about the User
mailing list