/// <returns>array or null</returns> public static byte[] ReadBytesAndSize(this NetworkReader reader) { // dont need to ValidateSize here because ReadBytes does it return(ReadCountPlusOne(reader, out var count) ? reader.ReadBytes(count) : null); }
// Use checked() to force it to throw OverflowException if data is invalid // null support, see NetworkWriter public static byte[] ReadBytesAndSize(this NetworkReader reader) { // count = 0 means the array was null // otherwise count -1 is the length of the array uint count = reader.ReadPackedUInt32(); return(count == 0 ? null : reader.ReadBytes(checked ((int)(count - 1u)))); }
public static Guid ReadGuid(this NetworkReader reader) => new Guid(reader.ReadBytes(16));
public static byte[] ReadBytes(this NetworkReader reader, int count) { byte[] bytes = new byte[count]; reader.ReadBytes(bytes, count); return(bytes); }