Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using K4os.Compression.LZ4;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- unsafe
- {
- float[] array = new float[1024];
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = i;
- }
- fixed (void* ptr = &array[0])
- {
- byte* dataPrt = (byte*) ptr;
- var encodedBytes = new byte[LZ4Codec.MaximumOutputSize(array.Length*4)];
- int encodedLength = 0;
- fixed(byte* output = &encodedBytes[0])
- {
- encodedLength = LZ4Codec.Encode(
- dataPrt, array.Length*4,
- output, encodedBytes.Length);
- }
- //--
- var decodedBytes = new byte[array.Length*4]; // or source.Length * 255 to be safe
- var decodedLength = LZ4Codec.Decode(
- encodedBytes, 0, encodedLength,
- decodedBytes, 0, decodedBytes.Length);
- float[] uncompressed = new float[array.Length];
- fixed (void* decodedVoidPtr = &decodedBytes[0])
- {
- float* decodedPtr = (float*) decodedVoidPtr;
- for (int i = 0; i < array.Length; i++)
- {
- uncompressed[i] = *decodedPtr;
- decodedPtr++;
- }
- }
- Console.WriteLine("Finished");
- }
- }
- //compressAboba();
- }
- private static void compressAboba()
- {
- var data = "bibaandbobaisabobaAAAAAAAAAAAAAkurwa";
- var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(data);
- var string64 = System.Convert.ToBase64String(plainTextBytes);
- var bytes64 = System.Text.Encoding.UTF8.GetBytes(string64);
- var encodedBytes = new byte[LZ4Codec.MaximumOutputSize(bytes64.Length)];
- var encodedLength = LZ4Codec.Encode(
- bytes64, 0, bytes64.Length,
- encodedBytes, 0, encodedBytes.Length);
- var decodedBytes = new byte[string64.Length]; // or source.Length * 255 to be safe
- var decodedLength = LZ4Codec.Decode(
- encodedBytes, 0, encodedLength,
- decodedBytes, 0, decodedBytes.Length);
- Console.WriteLine(System.Text.Encoding.UTF8.GetString(bytes64));
- Console.WriteLine(System.Text.Encoding.UTF8.GetString(decodedBytes, 0, decodedLength));
- }
- }
- }
Add Comment
Please, Sign In to add comment