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
-
AnyExchange
Methods
A packet with a copy of bytes.
A packet with a copy of the text's UTF-8 bytes.
How many bytes a packet carries.
The packet's bytes, copied into this domain; the packet is freed.
The packet's bytes as text of this domain; the packet is freed.
Frees a packet nobody takes.
Private and internal members (2)
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
Exchange as Antril, decompiled from its Larva HIR.
// 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(©[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);
}
}
}
}