B4R Question B4R serializator how to add array of data?

Michael1968

Active Member
Licensed User
Hi i have the problem that i want to save "settings" to the esp8266 spiff file system.
for better handling i want to convert it with B4Rserializator.

as example:
Custom Type:
Type daten ( value1 As Int,text As String)

Dim data_ar (2) As daten
    data_ar(0).value1=1
    data_ar(0).text="Text1"
    data_ar(1).value1=2
    data_ar(1).text="Text2"
   
    Dim data() As Byte = serializator.ConvertArrayToBytes(Array(data_ar(0).value1,data_ar(0).text,data_ar(1).value1,data_ar(1).text))

this works and i can read back the values:
B4X:
Dim Obj() As Object = serializator.ConvertBytesToArray(data, ObjectsBuffer)

the problem is that i have 8 array of type, with 14 number of variables each .
is there a way to built the data () stream like this ?

B4X:
For i = 0 To XX
        Dim data() As Byte = serializator.ConvertArrayToBytes(Array(data_ar(i).value1,data_ar(i))
       Log(fs.OpenReadWrite("/daten.dat"))
        Log ("write",fs.Stream.WriteBytes(data, fs.Position,data.Length))
        
    fs.Position = fs.Position + data.Length-1
Next

this did not work.. and i know there must be a better way.

Or is it better to save as Json ?

thx
 

miker2069

Active Member
Licensed User
I believe the serializator in B4R is limited to numeric types, array of bytes and strings only. Custom types cannot be serialized. If you could convert the whole thing to a char string and sve that ad bytes and then parse back when you read it, it's going to be simpler.
 
Upvote 0
Top