static class · System

Exchange

public static class Exchange
Kind
static class
Namespace
System
Assembly
System.Core
Access
public, static, abstract
Source file
Exchange.ant

Inheritance

Base classes
Any Exchange

Methods

PackBytes(u8[] bytes) : u8*
#

static

A packet with a copy of bytes.

Pack(str text) : u8*
#

static

A packet with a copy of the text's UTF-8 bytes.

Length(u8* packet) : i32
#

static

How many bytes a packet carries.

Bytes(u8* packet) : u8[]
#

static

The packet's bytes, copied into this domain; the packet is freed.

Text(u8* packet) : str
#

static

The packet's bytes as text of this domain; the packet is freed.

Free(u8* packet)
#

static

Frees a packet nobody takes.

Private and internal members (2)

unsafe extern("mem.alloc") Allocate(i64 bytes) : u8*
#

private static

unsafe extern("mem.free") Release(u8* block)
#

private static

Inherited members (5)

Source

Exchange as Antril, decompiled from its Larva HIR.

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

import System.Runtime.InteropServices;

into namespace System
{
	public static class Exchange
	{
		unsafe extern("mem.alloc") Allocate(i64 bytes) : u8*;

		unsafe extern("mem.free") Release(u8* block);

		public:
			/// A packet with a copy of `bytes`.
			PackBytes(u8[] bytes) : u8*
			{
				i64 n = bytes.Length;
				unsafe
				{
					u8* packet = Allocate(8 + n);
					loop (i32 i = 0..8)
						*(packet + (i64)i) = (u8)(n >> 8 * (i64)i);
					if (n > 0)
						Memory.Copy(packet + 8, &bytes[0], n);
					return packet;
				}
			}

			/// A packet with a copy of the text's UTF-8 bytes.
			Pack(str text) : u8* => PackBytes(text.Units());

			/// How many bytes a packet carries.
			Length(u8* packet) : i32
			{
				i64 n = 0;
				unsafe
				{
					loop (i32 i = 0..8)
						n = n | (i64)*(packet + (i64)i) << 8 * (i64)i;
				}
				return (i32)n;
			}

			/// The packet's bytes, copied into this domain; the packet is freed.
			Bytes(u8* packet) : u8[]
			{
				i32 n = Length(packet);
				u8[] copy = new u8[n];
				unsafe
				{
					if (n > 0)
						Memory.Copy(&copy[0], packet + 8, n);
					Release(packet);
				}
				return copy;
			}

			/// The packet's bytes as text of this domain; the packet is freed.
			Text(u8* packet) : str => new str(Bytes(packet));

			/// Frees a packet nobody takes.
			Free(u8* packet)
			{
				unsafe
				{
					Release(packet);
				}
			}
	}
}
Esc