Android Question B4RSerializator serializing an array as a member?

miker2069

Active Member
Licensed User
Longtime User
I was wondering if it were possible to actually have an array as a member of the the source array that's being serialized by B4RSerializator . For example:

B4X:
    Dim my_array() As Int = Array As Int(100,200,300)
    Dim num As Int = 1111
  
  
    Dim byte_array() As Byte = serializator.ConvertArrayToBytes(Array(num,my_array))
    Dim length As Int = byte_array.Length
  
  
    Dim Objects() As Object = serializator.ConvertBytesToArray(byte_array, ObjectsBuffer)
    Dim tmp_array() As Int =  Objects(1) 'should be the same as my_array
    For Each o As Int In tmp_array
        Log(o)
    Next

I have an array my_array with the int type elements. I also have another value called num - I want to serialize both. Can I do that like the above? Using:

Dim byte_array() As Byte = serializator.ConvertArrayToBytes(Array(num,my_array))

Interestingly when I test it out, it compiles. When I de-serialize and get what I think is the de-serialized array, I seem to only get the first element (in this case 100) and the incorrect numbers for elments 2 and 3. Interestingly it seems to loop through the correct number of elements in the de-serialized array however all but the first element is correct. It obviously all compiles (I was a little surprised that it did). Should this work, can I make something like this work?

Ultimately I would use something like this to possibly send infrared codes which would be something like this:
B4X:
Private ircode() As Int = Array As Int(8950,4550,500,650,550,1750,500,1750,500,650,500,650,500,650,500,650,500,1750,500,1750,500,650,500,1750,500,650,500,650,500,650,500,650,500,650,500,1750,550,1750,500,1750,500,1750,500,650,500,650,500,650,550,650,500,650,500,650,500,650,500,650,500,1750,500,1750,500,1750,500,1750,550)

To my ESP8266 and have it blast that IR signal. I could potentially covert to string and send like this:
B4X:
Private ircode_str As String = "8950,4550,500,650,550,1750,500,1750,500,650,500,650,500,650,500,650,500,1750,500,1750,500,650,500,1750,500,650,500,650,500,650,500,650,500,650,500,1750,550,1750,500,1750,500,1750,500,650,500,650,500,650,550,650,500,650,500,650,500,650,500,650,500,1750,500,1750,500,1750,500,1750,550"

However that might save me the hassle of going through the convert form string to ULONG Array and vice/versa.

Thoughts?
 

miker2069

Active Member
Licensed User
Longtime User

So are you suggesting instead of:

B4X:
Dim my_array() As Int = Array As Int(100,200,300)

I do something like:

B4X:
Dim bc As ByteConverter
Dim my_array() As Byte = bc.IntsToBytes(Array As Int(100,200,300))

That way I can properly serialize?
 
Upvote 0

miker2069

Active Member
Licensed User
Longtime User

Oh I see what you're talking about now - I will try that out - thank you!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…