Struct CompressionResult<T>
Represents the outcome of a value-returning ScyllaCompression operation (such as byte-array compression or decompression) using the result pattern instead of exceptions.
Inherited Members
Namespace: Scylla.Core.Util.Compression
Assembly: ScyllaCore.dll
Syntax
public readonly struct CompressionResult<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value produced by the operation on success. Common types are
|
Remarks
The generic variant of CompressionResult adds a Value
property that holds the operation's output on success. On failure, Value
is default(T) (typically null for reference types). The recommended
usage pattern is:
var result = ScyllaCompression.CompressToResult(data);
if (!result.IsSuccess)
{
Debug.LogError($"[{result.ErrorCode}] {result.ErrorMessage}");
return;
}
byte[] compressed = result.Value;
Factory methods Success(T) and Failure(CompressionErrorCode, string, Exception) are the only way to construct instances; the constructor is private.
Properties
ErrorCode
Gets the structured error code that categorizes the failure when
IsFailure is true. Returns
Unknown on successful results as a neutral
sentinel - always check IsSuccess first.
Declaration
public CompressionErrorCode ErrorCode { get; }
Property Value
| Type | Description |
|---|---|
| CompressionErrorCode |
ErrorMessage
Gets a human-readable description of the failure when IsFailure is
true. Returns null for successful results.
Declaration
public string ErrorMessage { get; }
Property Value
| Type | Description |
|---|---|
| string |
Exception
Gets the underlying exception that caused the failure, if one was captured.
Returns null when the failure was generated without an underlying exception,
or when the operation succeeded.
Declaration
public Exception Exception { get; }
Property Value
| Type | Description |
|---|---|
| Exception |
IsFailure
Gets a value indicating whether the compression operation failed.
Equivalent to !IsSuccess. When true, Value is
default(T) and the error properties carry diagnostic information.
Declaration
public bool IsFailure { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsSuccess
Gets a value indicating whether the compression operation completed successfully.
When true, Value contains the valid operation output and all
error fields are unset.
Declaration
public bool IsSuccess { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Value
Gets the value produced by the operation on success. Returns default(T)
(typically null for reference types) when IsFailure is
true. Always check IsSuccess before reading this property.
Declaration
public T Value { get; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
Failure(CompressionErrorCode, string, Exception)
Creates a CompressionResult<T> that represents a failed operation.
Value is set to default(T).
Declaration
public static CompressionResult<T> Failure(CompressionErrorCode errorCode, string errorMessage = null, Exception exception = null)
Parameters
| Type | Name | Description |
|---|---|---|
| CompressionErrorCode | errorCode | The CompressionErrorCode that categorizes the failure. |
| string | errorMessage | A human-readable description of the failure. When |
| Exception | exception | The underlying exception that caused the failure, or |
Returns
| Type | Description |
|---|---|
| CompressionResult<T> | A CompressionResult<T> where IsSuccess is |
FromException(CompressionException)
Creates a CompressionResult<T> that represents a failure by extracting
all diagnostic information from an existing CompressionException.
Value is set to default(T).
Declaration
public static CompressionResult<T> FromException(CompressionException exception)
Parameters
| Type | Name | Description |
|---|---|---|
| CompressionException | exception | The CompressionException to convert. When |
Returns
| Type | Description |
|---|---|
| CompressionResult<T> | A CompressionResult<T> where IsSuccess is |
Success(T)
Creates a CompressionResult<T> that represents a successful operation and carries the produced value.
Declaration
public static CompressionResult<T> Success(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The output value of the operation (e.g., the compressed |
Returns
| Type | Description |
|---|---|
| CompressionResult<T> | A CompressionResult<T> where IsSuccess is |