mirror of
https://github.com/chylex/Brotli-Builder.git
synced 2024-12-22 16:42:46 +01:00
86 lines
2.8 KiB
C#
86 lines
2.8 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using BrotliLib.Brotli;
|
|
using BrotliLib.Brotli.Output;
|
|
using BrotliLib.Markers;
|
|
using BrotliLib.Serialization;
|
|
|
|
namespace BrotliBuilder.State{
|
|
abstract class BrotliFileState{
|
|
public abstract class TimedBrotliFileState : BrotliFileState{
|
|
public Stopwatch? Stopwatch { get; }
|
|
|
|
protected TimedBrotliFileState(Stopwatch? stopwatch){
|
|
this.Stopwatch = stopwatch;
|
|
}
|
|
}
|
|
|
|
// Concrete states
|
|
|
|
public sealed class NoFile : BrotliFileState{}
|
|
public sealed class Waiting : BrotliFileState{}
|
|
public sealed class Starting : BrotliFileState{}
|
|
|
|
public sealed class HasStructure : TimedBrotliFileState{
|
|
public BrotliFileStructure File { get; }
|
|
|
|
public HasStructure(BrotliFileStructure file, Stopwatch? stopwatch) : base(stopwatch){
|
|
this.File = file;
|
|
}
|
|
}
|
|
|
|
public sealed class HasBits : TimedBrotliFileState{
|
|
public string Bits { get; }
|
|
|
|
public HasBits(string bits, Stopwatch? stopwatch) : base(stopwatch){
|
|
this.Bits = bits;
|
|
}
|
|
}
|
|
|
|
public sealed class HasOutput : TimedBrotliFileState{
|
|
public byte[]? PreviousBytes { get; }
|
|
public byte[] OutputBytes { get; }
|
|
|
|
public HasOutput(byte[]? previousBytes, byte[] outputBytes, Stopwatch? stopwatch) : base(stopwatch){
|
|
this.PreviousBytes = previousBytes;
|
|
this.OutputBytes = outputBytes;
|
|
}
|
|
}
|
|
|
|
public sealed class HasMarkers : BrotliFileState{
|
|
public MarkerRoot MarkerRoot { get; }
|
|
public MarkerNode[] Markers { get; }
|
|
|
|
public HasMarkers(MarkerRoot markerRoot){
|
|
this.MarkerRoot = markerRoot;
|
|
this.Markers = markerRoot.ToArray();
|
|
}
|
|
}
|
|
|
|
public sealed class Loaded : BrotliFileState{
|
|
public BrotliFileStructure File { get; }
|
|
|
|
public int TotalCompressedBits { get; }
|
|
public int TotalOutputBytes { get; }
|
|
|
|
public Loaded(BrotliFileStructure file, BitStream bits, BrotliOutputStored output, MarkerRoot? markerRoot){
|
|
this.File = file;
|
|
|
|
this.TotalCompressedBits = markerRoot?.TotalBits ?? bits.Length; // use markers to account for padding whenever possible
|
|
this.TotalOutputBytes = output.OutputSize;
|
|
}
|
|
}
|
|
|
|
public sealed class Error : BrotliFileState{
|
|
public ErrorType Type { get; }
|
|
public Exception Exception { get; }
|
|
|
|
public Error(ErrorType type, Exception exception){
|
|
this.Type = type;
|
|
this.Exception = exception;
|
|
}
|
|
}
|
|
}
|
|
}
|