forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManagedStreamHelpers.cs
More file actions
49 lines (44 loc) · 2.18 KB
/
Copy pathManagedStreamHelpers.cs
File metadata and controls
49 lines (44 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using UnityEngine.Scripting;
namespace UnityEngine
{
internal static class ManagedStreamHelpers
{
internal static void ValidateLoadFromStream(System.IO.Stream stream)
{
if (stream == null)
throw new System.ArgumentNullException("ManagedStream object must be non-null", "stream");
if (!stream.CanRead)
throw new System.ArgumentException("ManagedStream object must be readable (stream.CanRead must return true)", "stream");
if (!stream.CanSeek)
throw new System.ArgumentException("ManagedStream object must be seekable (stream.CanSeek must return true)", "stream");
}
[RequiredByNativeCode]
unsafe internal static void ManagedStreamRead(byte[] buffer, int offset, int count, System.IO.Stream stream, IntPtr returnValueAddress)
{
if (returnValueAddress == IntPtr.Zero)
throw new ArgumentException("Return value address cannot be 0.", "returnValueAddress");
ValidateLoadFromStream(stream);
(*(int*)returnValueAddress) = stream.Read(buffer, offset, count);
}
[RequiredByNativeCode]
unsafe internal static void ManagedStreamSeek(long offset, uint origin, System.IO.Stream stream, IntPtr returnValueAddress)
{
if (returnValueAddress == IntPtr.Zero)
throw new ArgumentException("Return value address cannot be 0.", "returnValueAddress");
ValidateLoadFromStream(stream);
(*(long*)returnValueAddress) = stream.Seek(offset, (System.IO.SeekOrigin)origin);
}
[RequiredByNativeCode]
unsafe internal static void ManagedStreamLength(System.IO.Stream stream, IntPtr returnValueAddress)
{
if (returnValueAddress == IntPtr.Zero)
throw new ArgumentException("Return value address cannot be 0.", "returnValueAddress");
ValidateLoadFromStream(stream);
(*(long*)returnValueAddress) = stream.Length;
}
}
}