Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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:
    290
    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:
    276
    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:
    290
    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:
    276
    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:
    290
    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.