Android Question [SOLVED] Send multiple types by b4xserializator

RAFA BRAVO

Active Member
Licensed User
Longtime User
Would it be possible to send several types by B4XSerializator? I would like to send and read a group of variables (this works fine)

but then a different set of variables. Thank you
 

DonManfred

Expert
Licensed User
Longtime User
You can send ONE serialized Type at once.
That said you can send any Type you want.

But be sure that you deserialize the type into the correct one.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I'm not sure about this part, any example to help me?
i don´t know a way to recognize the type. No.

I suggest to create ONE Type with all the infos you need or not need and always send the same type. So you can expect the same type coming in.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
...You can send your Type of DATA... for example:
B4X:
    Type theData (a1 as int, a2 as long, a3 as float, a4 as string) 'etc...
...
dim a as theData
a.initialize

a.a1=100
a.a2=10000000000
a.a3=0.0012
a.a4="my data, your data..."

Dim cx As B4XSerializator
dim b() as byte=cx.ConvertObjectToBytes(a)
 
Upvote 0

RAFA BRAVO

Active Member
Licensed User
Longtime User
I was asking about having a better organization, and not sending so many variables at once. But if it's the best solution, I'll work with only one type, thank you
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
I was asking about having a better organization, and not sending so many variables at once. But if it's the best solution, I'll work with only one type, thank you
you can have you own variables... those you want... only... and is just an idea... or you can make a map and send a map.... for example saying

dim a as map
a.initialize
a.put("typeofvar","string") 'so changing the typeofvar with a string... saying what is...
a.put("value","yourvalue")

just an idea...
 
Upvote 0

RAFA BRAVO

Active Member
Licensed User
Longtime User
It was my idea:
B4A:
Dim type As data1 (data1Ok As boolean, data1Num As int, data1Value As string)

Dim type As data2 (dataOk As boolean, data2Num As int, data2Value As string)

A
ssuming I have many types and many variables in each type. my question was if more than one type could be serialized. If it is not possible, I will serialize a single type with many variables
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You can create a List, add a Map to the list which also explains the type so you know what type is in the Map.

B4X:
dim l as List
l.initialize

Dim m as map
m.initialize
m.Put("Type", "Type1")
m.Put("TypeObject", mytype1object)
l.put(m)

Dim m as map
m.initialize
m.Put("Type", "Type2")
m.Put("TypeObject", mytype2object)
l.put(m)
and then serialize the list....
 
Upvote 2
Top