• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Writing a data structure to a buffer

Fern

Member
I have never tested it myself but I would like to know how safe it is to write a ds_list and/or a ds_map to a buffer as a string. Will this cause any problems?
 
B

bojack29

Guest
Not that I am aware of. You should be fine. But you do need to keep in mind that when writing to the buffer in 1 bit alignment (needed for string input) that you properly string real values before placing them into a buffer.
Code:
while(ds_list_size(list) > 0){
     buffer_write(buffer, buffer_string, string(ds_list[| 0]));
     ds_list_delete(list, 0);
}
 

FrostyCat

Redemption Seeker
Generally not if you use ds_*_write() and buffer_write() properly, but here are a few things that will make it unsafe:
  • Writing from a native export and reading from an HTML5-based export (or vice-versa)
  • Non-real, non-string entries in the data structures (e.g. arrays)
  • Nested data structures (JSON can help if only lists and maps are involved; everything else requires more deliberate handling)
  • Data structures with entries referencing dynamically allocated resources or anything not trivially serializable (e.g. buffers, surfaces, etc.)
 

Fern

Member
Not that I am aware of. You should be fine. But you do need to keep in mind that when writing to the buffer in 1 bit alignment (needed for string input) that you properly string real values before placing them into a buffer.
Code:
while(ds_list_size(list) > 0){
     buffer_write(buffer, buffer_string, string(ds_list[| 0]));
     ds_list_delete(list, 0);
}
Whoops, I just realized I did not ask the correct question. I know that does work. Thanks though. haha

I meant more like ds_list_write() or ds_map_write().
 

Fern

Member
Generally not if you use ds_*_write() and buffer_write() properly, but here are a few things that will make it unsafe:
  • Writing from a native export and reading from an HTML5-based export (or vice-versa)
  • Non-real, non-string entries in the data structures (e.g. arrays)
  • Nested data structures (JSON can help if only lists and maps are involved; everything else requires more deliberate handling)
  • Data structures with entries referencing dynamically allocated resources or anything not trivially serializable (e.g. buffers, surfaces, etc.)
Awesome, thanks. Perfect answer.
 
Top