IOUtil

Description

static class Tinman.Core.IO.IOUtil

Helper class for this namespace.

This class provides some helper methods, dealing with the following:

  • Base-85 coding of binary data, see FromBase85 and ToBase85.

  • Asynchronous flushing, see TaskFlush

  • Read and write 64-bit integer values using minimal byte count (between 1 and 9), see VarInt*.

Public / Methods

From​Base85


public static method FromBase85 → (1)

data in : string

[not-null]
The base-85 encoded string.

returns → int8 [ ]

The decoded binary data.

Decodes binary data from the given base-85 encoded string.

IOException

If data in is malformed.

See also

IOUtil.ToBase85

Task​Flush


public static method TaskFlush → (1)

parallel in : bool

Use parallel tasks for flushing? A parallel flush uses TaskPool.Parallelism background tasks to perform the flush.

returns → ITaskVoid<IFlushable>

The created ITaskVoid object.

A task that flushes the given object.

See also

IFlushable.Flush

To​Base85


public static method ToBase85 → (3)

data in : int8 [ ]

[not-null]
The binary data.

offset in : int32

[>=0]
Index of first array element to read.

count in : int32

[>=0]
Number of values to write.

returns → string

The base-85 encoded string.

Encodes the given binary data as base-85.

Var​Int32​Length


[Pure]
public static method VarInt32Length → (1)

value in : int32

The value to encode.

returns → int32

The number of required bytes.

Returns the number of bytes that are required to encode the given value using variable coding from one to five bytes.

These are the signed number ranges with a specific byte count:
1 byte : [-64 .. 63]
2 bytes : [-8192 .. 8191]
3 bytes : [-1048576 .. 1048575]
4 bytes : [-134217728 .. 134217727]
…​
5 bytes

Var​Int64​Length


[Pure]
public static method VarInt64Length → (2)

value in : int64

The value to encode.

shortcut opt : bool = true

Use shortcut coding?

returns → int32

The number of required bytes.

Returns the number of bytes that are required to encode the given value using variable coding from one to nine bytes.

These are the number ranges with a specific byte count:
1 byte : [-64 .. 63]
2 bytes : [-8192 .. 8191]
3 bytes : [-1048576 .. 1048575]
4 bytes : [-134217728 .. 134217727]
5 bytes : [-17179869184 .. 17179869183]
6 bytes : [-2199023255552 .. 2199023255551]
7 bytes : [-281474976710656 .. 281474976710655]
8 bytes : [-36028797018963968 .. 36028797018963967]
…​
9 bytes (with shortcut opt coding)
…​
9 bytes : [-4611686018427387904 .. 4611686018427387903]
10 bytes (without shortcut opt coding)

After emitting 8 bytes with 7 bits of payload each, there are 56 bits in total. With shortcut opt coding, the remaining 8 bits of a 64 bit value are always output without variable coding, as the ninth byte. For values with 56 bits or fewer, shortcut coding has no effect.

Var​UInt32​Length


[Pure]
public static method VarUInt32Length → (1)

value in : int32

The value to encode, which will be interpreted as an unsigned integer.

returns → int32

The number of required bytes.

Returns the number of bytes that are required to encode the given value using variable coding from one to five bytes.

These are the unsigned number ranges with a specific byte count:
1 byte : [0 .. 127]
2 bytes : [128 .. 16383]
3 bytes : [16384 .. 2097151]
4 bytes : [2097152 .. 268435455]
…​
5 bytes

Var​UInt64​Length


[Pure]
public static method VarUInt64Length → (2)

value in : int64

The value to encode.

shortcut opt : bool = true

Use shortcut coding?

returns → int32

The number of required bytes.

Returns the number of bytes that are required to encode the given value using variable coding from one to nine bytes.

These are the number ranges with a specific byte count:
1 byte : [0 .. 127]
2 bytes : [128 .. 16383]
3 bytes : [16384 .. 2097151]
4 bytes : [2097152 .. 268435455]
5 bytes : [268435456 .. 34359738367]
6 bytes : [34359738368 .. 4398046511103]
7 bytes : [4398046511104 .. 562949953421311]
8 bytes : [562949953421312 .. 72057594037927935]
…​
9 bytes (with shortcut opt coding)
…​
9 bytes : [72057594037927936 .. 9223372036854775807]
10 bytes (without shortcut opt coding)

After emitting 8 bytes with 7 bits of payload each, there are 56 bits in total. With shortcut opt coding, the remaining 8 bits of a 64 bit value are always output without variable coding, as the ninth byte. For values with 56 bits or fewer, shortcut coding has no effect.