Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved DataStreamReader.GetBytesRead is incorrect after nested read calls

Discussion in 'Unity Transport' started by cerestorm, Jun 30, 2023.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    685
    Edit: Ignore the below, I missed an intermediate step where I was passing the reader by value...

    I wanted to put a check in after a message has been deserialised that the total bytes read is the same as the length but the number of bytes read is incorrect.

    Example of what I'm seeing:

    OnReceiveMessage(reader)

    • ReadInt()
    • GetBytesRead = 4
    • message.Deserialise(ref reader)
      • ReadInt()
      • GetBytesRead = 8
      • subMessage.Deserialise(ref reader)
        • ReadInt()
        • GetBytesRead = 12
    • GetBytesRead = 8
    On return to the top level GetBytesRead is correct for the first Deserialise call but reads in the second call are not being added. Is it possible to have the true number of bytes read when there's more than one nested call?
     
    Last edited: Jul 1, 2023