Read/write map from/to AsyncStreams

knutf

Active Member
Licensed User
Longtime User
Is it possible to Read/write map from/to an AsyncStreams in the same way as you can with File.ReadMap/WriteMap?
 

derez

Expert
Licensed User
Longtime User
Use ReadObject and WriteObject, then it is one piece of data.
 
Last edited:
Upvote 0

knutf

Active Member
Licensed User
Longtime User
Thank you.

I'm not sure if I fully understand what you mean, but, based on your answers I have made the following code:

B4X:
Dim settings As Map

'**************************
some code to fill values in settings
'**************************

Dim bytesbuffer(100000) As Byte
Dim raf As RandomAccessFile
raf.Initialize3(bytesbuffer,True)
raf.WriteObject(settings,True,0)            
Dim bc As ByteConverter
Dim HexString As String = bc.HexFromBytes(bytesbuffer)      
stream.Write(HexString.SubString2(0,raf.CurrentPosition*2) & Chr(13) & Chr(10))


I convert the bytesbuffer to HexString because the stream is an AsyncStreamsText
The code seams to work as intended. My only concern is that the bytesbuffer must be
of fixed size. I do not want to oversize the buffer and the size of the written object could vary a lot. Is there a way around the buffer size concern?
 
Upvote 0
Top