final class · System

ResourceData

public final class ResourceData

Read-only bytes of a resource, read in place from the program's static data (no copy): indexed, iterated, sliced.

Tipo
final class
Espacio de nombres
System
Ensamblado
System.Core
Acceso
public, final
Archivo fuente
Resources.ant

Herencia

Clases base
Any ResourceData

Propiedades

i32 Length { get; }
#

read-only

How many bytes.

Métodos

At(i32 index) : u8
#

The byte at index (data[index]).

ToArray() : u8[]
#

A copy of the bytes.

Text() : str
#

The bytes as UTF-8 text.

Iterator() : ResourceIterator
#

The bytes in order (loop (u8 b in data)).

Slice(i32 start, i32 count) : ResourceData
#

count bytes from start, in place (no copy).

Slice(i32 start) : ResourceData
#

The bytes from start on, in place.

Equals(u8[] bytes) : bool
#

Whether these are the same bytes as bytes (one comparison in memory).

Operadores y conversiones

op ==(ResourceData a, u8[] b) : bool
#

static

op !=(ResourceData a, u8[] b) : bool
#

static

op ==(u8[] a, ResourceData b) : bool
#

static

op !=(u8[] a, ResourceData b) : bool
#

static

Miembros privados e internos (3)

u8* data
#

private

i32 length
#

private

new(u8* data, i32 length)
#

internal

Miembros heredados (5)

Código fuente

ResourceData en Antril, descompilado a partir de su Larva HIR.

System.ResourceData.ant
// System.ResourceData — System.Core (decompiled from Larva HIR)

import System.Runtime.InteropServices;

into namespace System
{
	/// Read-only bytes of a resource, read in place from the program's static data (no copy): indexed, iterated, sliced.
	public final class ResourceData
	{
		u8* data;
		i32 length;

		internal:
			new(u8* data, i32 length)
			{
				this.data = data;
				this.length = length;
			}

		public:
			/// The byte at `index` (`data[index]`).
			At(i32 index) : u8
			{
				if ((u32)index >= (u32)length)
					Fail.Index();
				unsafe
				{
					return *(data + (i64)index);
				}
			}

			/// A copy of the bytes.
			ToArray() : u8[]
			{
				u8[] copy = new u8[length];
				if (length > 0)
				{
					unsafe
					{
						Memory.Copy(&copy[0], data, length);
					}
				}
				return copy;
			}

			/// The bytes as UTF-8 text.
			Text() : str => new str(ToArray());

			/// The bytes in order (`loop (u8 b in data)`).
			Iterator() : ResourceIterator => new ResourceIterator(data, length);

			/// `count` bytes from `start`, in place (no copy).
			Slice(i32 start, i32 count) : ResourceData
			{
				if ((u32)start > (u32)length || (u32)count > (u32)(length - start))
					Fail.Index();
				unsafe
				{
					return new ResourceData(data + (i64)start, count);
				}
			}

			/// The bytes from `start` on, in place.
			Slice(i32 start) : ResourceData => Slice(start, length - start);

			/// Whether these are the same bytes as `bytes` (one comparison in memory).
			Equals(u8[] bytes) : bool
			{
				if (bytes.Length != length)
					return false;
				if (length == 0)
					return true;
				unsafe
				{
					return Memory.Compare(data, &bytes[0], length) == 0;
				}
			}

			op ==(ResourceData a, u8[] b) : bool => a.Equals(b);

			op !=(ResourceData a, u8[] b) : bool => !a.Equals(b);

			op ==(u8[] a, ResourceData b) : bool => b.Equals(a);

			op !=(u8[] a, ResourceData b) : bool => !b.Equals(a);

			/// How many bytes.
			i32 Length
			{
				get => length;
			}
	}
}
Esc