UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
OodleDataCompressionUtil.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
7#include "HAL/Platform.h"
9
10// OodleDataCompressionUtil : utilities for common Unreal actions built on top of OodleDataCompression
11
28{
55
66 {
67 // At minimum we need 8 bytes.
68 if (InCompressed.Num() < sizeof(int32)*2)
69 {
70 return 0;
71 }
72
73 const int32* Sizes = (const int32*)InCompressed.GetData();
74 OutDecompressedSize = Sizes[0];
75 OutCompressedSize = Sizes[1];
76
77#if !PLATFORM_LITTLE_ENDIAN
80#endif
81
82 // If the compressed size has highest bit set, we are 64 bit,
83 // and need to call PeekSizes64.
84 if (OutCompressedSize & 0x80000000)
85 {
86 return 0;
87 }
88
89 return sizeof(int32) * 2;
90 }
92 {
93 if (InCompressed.Num() < sizeof(int32)*2)
94 {
95 return 0;
96 }
97
98 const int32* Sizes = (const int32*)InCompressed.GetData();
99 int32 DecompressedSize32 = Sizes[0];
100 int32 CompressedSize32 = Sizes[1];
101
102#if !PLATFORM_LITTLE_ENDIAN
105#endif
106
109
110 // If the compressed size has highest bit set, we are 64 bit. This
111 // is expected to be rare
112 if (CompressedSize32 & 0x80000000)
113 {
114 // Now two int64s.
115 if (InCompressed.Num() < sizeof(int64)*2)
116 {
117 return 0;
118 }
119
120 // So now the marker bit is the top bit from decompressed size
121 const int64* Sizes64 = (const int64*)InCompressed.GetData();
124
125#if !PLATFORM_LITTLE_ENDIAN
128#endif
129
130 // clear the 64 bit indicator from decompressed size
131 DecompressedSize64 &= ~0x8000000000000000ULL;
132
135
136 return sizeof(int64) * 2;
137 }
138
139 return sizeof(int32) * 2;
140 }
141
154
167
168
177 template <class T>
182 template <class T>
187
197 template <class T>
199 {
200 int32 DecompressedSize, CompressedSize;
201 if (PeekSizes(InCompressed, CompressedSize, DecompressedSize) == 0)
202 {
203 return false;
204 }
205
206 if ((DecompressedSize % sizeof(T)) != 0)
207 {
208 // We must be able to evenly fit our decompressed data in to the desired output.
209 return false;
210 }
211
212 OutDecompressed.SetNum(DecompressedSize / sizeof(T));
214 }
215 template <class T>
217 {
218 int64 DecompressedSize, CompressedSize;
219 if (PeekSizes64(InCompressed, CompressedSize, DecompressedSize) == 0)
220 {
221 return false;
222 }
223
224 if ((DecompressedSize % sizeof(T)) != 0)
225 {
226 // We must be able to evenly fit our decompressed data in to the desired output.
227 return false;
228 }
229
230 OutDecompressed.SetNum(DecompressedSize / sizeof(T));
232 }
233};
234
uint64 BYTESWAP_ORDER64(uint64 Value)
Definition ByteSwap.h:78
uint32 BYTESWAP_ORDER32(uint32 Val)
Definition ByteSwap.h:64
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition Array.h:670
Definition OodleDataCompressionUtil.cpp:9
bool CORE_API DecompressToExistingBuffer(void *InDestinationBuffer, int64 InDestinationBufferSize, TArray< uint8 > const &InCompressed)
Definition OodleDataCompressionUtil.cpp:112
bool CORE_API DecompressToAllocatedBuffer64(void *&OutDestinationBuffer, int64 &OutDestinationBufferSize, TArray64< uint8 > const &InCompressed)
Definition OodleDataCompressionUtil.cpp:187
bool DecompressToTArray(TArray< T > &OutDecompressed, TArray< uint8 > const &InCompressed)
Definition OodleDataCompressionUtil.h:198
bool CORE_API DecompressToExistingBuffer64(void *InDestinationBuffer, int64 InDestinationBufferSize, TArray64< uint8 > const &InCompressed)
Definition OodleDataCompressionUtil.cpp:134
bool CompressTArray(TArray< uint8 > &OutCompressed, const TArray< T > &InBuffer, FOodleDataCompression::ECompressor InCompressor, FOodleDataCompression::ECompressionLevel InLevel)
Definition OodleDataCompressionUtil.h:178
bool CORE_API CompressData(TArray< uint8 > &OutCompressed, const void *InData, int32 InDataSize, FOodleDataCompression::ECompressor InCompressor, FOodleDataCompression::ECompressionLevel InLevel)
Definition OodleDataCompressionUtil.cpp:10
int32 PeekSizes(TArray< uint8 > const &InCompressed, int32 &OutCompressedSize, int32 &OutDecompressedSize)
Definition OodleDataCompressionUtil.h:65
bool CompressTArray64(TArray64< uint8 > &OutCompressed, const TArray64< T > &InBuffer, FOodleDataCompression::ECompressor InCompressor, FOodleDataCompression::ECompressionLevel InLevel)
Definition OodleDataCompressionUtil.h:183
bool CORE_API DecompressToAllocatedBuffer(void *&OutDestinationBuffer, int32 &OutDestinationBufferSize, TArray< uint8 > const &InCompressed)
Definition OodleDataCompressionUtil.cpp:157
bool DecompressToTArray64(TArray64< T > &OutDecompressed, TArray64< uint8 > const &InCompressed)
Definition OodleDataCompressionUtil.h:216
bool CORE_API CompressData64(TArray64< uint8 > &OutCompressed, const void *InData, int64 InDataSize, FOodleDataCompression::ECompressor InCompressor, FOodleDataCompression::ECompressionLevel InLevel)
Definition OodleDataCompressionUtil.cpp:48
int32 PeekSizes64(TArray64< uint8 > const &InCompressed, int64 &OutCompressedSize, int64 &OutDecompressedSize)
Definition OodleDataCompressionUtil.h:91
ECompressor
Definition OodleDataCompression.h:49
ECompressionLevel
Definition OodleDataCompression.h:94