1
0
mirror of https://github.com/chylex/Brotli-Builder.git synced 2025-08-21 15:54:05 +02:00
Files
BrotliBuilder
BrotliCalc
BrotliImpl
BrotliLib
Brotli
Components
Dictionary
Default
Format
Index
Source
Transform
TransformType.cs
WordTransform.cs
BrotliDictionary.cs
Encode
Output
Parameters
Streaming
Utils
BrotliFileStructure.cs
BrotliGlobalState.cs
Collections
Exceptions
Markers
Numbers
Serialization
BrotliLib.csproj
LICENSE-BROTLI.txt
UnitTests
.gitignore
BrotliBuilder.sln
LICENSE
README.md

30 lines
1.1 KiB
C#

using System;
namespace BrotliLib.Brotli.Dictionary.Transform{
/// <summary>
/// Represents a combined transformation that modifies the bytes of a word using transform <see cref="Type"/>, and then surrounds it with a <see cref="Prefix"/> and a <see cref="Suffix"/>.
/// </summary>
public sealed class WordTransform{
public TransformType Type { get; }
internal byte[] Prefix { get; }
internal byte[] Suffix { get; }
public WordTransform(byte[] prefix, TransformType transform, byte[] suffix){
this.Type = transform;
this.Prefix = prefix;
this.Suffix = suffix;
}
public byte[] Process(byte[] rawWord){
byte[] middle = Type.Process(rawWord);
byte[] fullWord = new byte[Prefix.Length + middle.Length + Suffix.Length];
Buffer.BlockCopy(Prefix, 0, fullWord, 0, Prefix.Length);
Buffer.BlockCopy(middle, 0, fullWord, Prefix.Length, middle.Length);
Buffer.BlockCopy(Suffix, 0, fullWord, Prefix.Length + middle.Length, Suffix.Length);
return fullWord;
}
}
}