Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Resolved How to directly access the buffer of the DataStreamReader

Discussion in 'Unity Transport' started by MariuszKowalczyk, Mar 21, 2023.

  1. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    I have my own serializer. After receiving the data over the network the data is in the DataStreamReader. I would like to get it and use in my own serializer. To do so I need to get the bytes from DataStreamReader.

    I know I can use ReadBytes() or ReadBytesUnsafe() but then the data will have to be copied, which I would prefer to avoid to get better performance. I saw that there were some extension methods available in the past that would allow me to do what I want, but looks like they were removed.

    Is there any way to access the buffer directly? If not in the DataStreamReader, then maybe there is a way to access it in the NetDriver itself?
     
    Last edited: Apr 7, 2023
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    What extension methods are you referring to? My understanding is that there is no way to directly access the backing memory of a
    DataStreamReader
    , and that this is on purpose to avoid giving direct memory access to
    NetworkDriver
    internals. But perhaps there was an escape hatch for this at some point and this was lost in the transition of these data structures to the collections package.
     
  3. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    I am referring to this:
    https://docs.unity.cn/Packages/com.....LowLevel.Unsafe.DataStreamUnsafeUtility.html
     
  4. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    These APIs were removed in 2019. Currently we don't plan on adding any similar functionality on the transport side. The team responsible for the collections package (where these types now live) might consider adding such a feature however, since they do have similar APIs for their native containers. I guess the best place to reach them would be the ECS forum. You could also submit the idea on the DOTS roadmap.
     
  5. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    301
    Thank you, I will first check the performance of the current solution, if I will not be happy with the results I will reach them.