B4R Question how to convert from Type to bytes() and then convert from bytes() to Type

Nator

Member
Licensed User
Longtime User
I would really appreciate if you could help me
The idea is to convert the type declaration to a byte and then convert it back to type.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public tiempo As Timer
    Public bc As ByteConverter
   
    Type confserver(ipserver() As Byte,port() As Byte,clave() As Byte )
    Public srv(1) As confserver
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    tiempo.Initialize("nuevo",5000)
    tiempo.Enabled=True
   
   
    srv(0).ipserver=JoinBytes(Array("149.90.90.23".GetBytes))
    srv(0).port="1234".GetBytes
    srv(0).clave="4567".GetBytes
End Sub

Sub nuevo

    Dim srv2(1) As confserver
   

    Dim ocb() As Byte =bc.ObjectToBytes(srv,srv.Length)

       
    Dim odb As Object=bc.ObjectFromBytes(ocb)
   
    srv2=odb
   
    Log(srv2(0).ipserver) 'does not return the previously loaded data
   
End Sub
 
Last edited:
Top