You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
This is a binary patching and incremental downloading tool, similar to rsync or zsync. It aims to improve the large binary download processes that previously were served by robocopy (i.e. full packages produced by the build farm). The original code can be found in `//depot/usr/yuriy.odonnell/unsync`. This commit is a branch from the original location to preserve history. While the codebase is designed to be self-contained and does not depend on any engine libraries, it mostly follows the UE coding guidelines and can be built with UBT. Currently only Windows is supported, however the tool is expected to also work on Mac and Linux in the future. #rb Martin.Ridgers #preflight skip [CL 18993571 by Yuriy ODonnell in ue5-main branch]
100 lines
1.8 KiB
C++
100 lines
1.8 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "UnsyncCommon.h"
|
|
#include "UnsyncUtil.h"
|
|
|
|
namespace unsync {
|
|
|
|
inline uint32
|
|
MeasureVarUint(uint64 X)
|
|
{
|
|
return uint32(std::min(int32(FloorLog264(X)) / 7 + 1, 9));
|
|
}
|
|
|
|
inline uint32
|
|
MeasureVarUint(const void* X)
|
|
{
|
|
return CountLeadingZeros32(uint8(~*static_cast<const uint8*>(X))) - 23;
|
|
}
|
|
|
|
inline uint32
|
|
WriteVarUint(uint64 X, void* Output)
|
|
{
|
|
const uint32 Size = MeasureVarUint(X);
|
|
uint8* OutputBytes = static_cast<uint8*>(Output) + Size - 1;
|
|
switch (Size - 1)
|
|
{
|
|
case 8:
|
|
*OutputBytes-- = uint8(X);
|
|
X >>= 8;
|
|
case 7:
|
|
*OutputBytes-- = uint8(X);
|
|
X >>= 8;
|
|
case 6:
|
|
*OutputBytes-- = uint8(X);
|
|
X >>= 8;
|
|
case 5:
|
|
*OutputBytes-- = uint8(X);
|
|
X >>= 8;
|
|
case 4:
|
|
*OutputBytes-- = uint8(X);
|
|
X >>= 8;
|
|
case 3:
|
|
*OutputBytes-- = uint8(X);
|
|
X >>= 8;
|
|
case 2:
|
|
*OutputBytes-- = uint8(X);
|
|
X >>= 8;
|
|
case 1:
|
|
*OutputBytes-- = uint8(X);
|
|
X >>= 8;
|
|
default:
|
|
break;
|
|
}
|
|
*OutputBytes = uint8(0xff << (9 - Size)) | uint8(X);
|
|
return Size;
|
|
}
|
|
|
|
inline uint64
|
|
ReadVarUint(const void* Data, uint32& OutSize)
|
|
{
|
|
const uint32 Size = MeasureVarUint(Data);
|
|
OutSize = Size;
|
|
|
|
const uint8* DataBytes = static_cast<const uint8*>(Data);
|
|
uint64 Value = *DataBytes++ & uint8(0xff >> Size);
|
|
switch (Size - 1)
|
|
{
|
|
case 8:
|
|
Value <<= 8;
|
|
Value |= *DataBytes++;
|
|
case 7:
|
|
Value <<= 8;
|
|
Value |= *DataBytes++;
|
|
case 6:
|
|
Value <<= 8;
|
|
Value |= *DataBytes++;
|
|
case 5:
|
|
Value <<= 8;
|
|
Value |= *DataBytes++;
|
|
case 4:
|
|
Value <<= 8;
|
|
Value |= *DataBytes++;
|
|
case 3:
|
|
Value <<= 8;
|
|
Value |= *DataBytes++;
|
|
case 2:
|
|
Value <<= 8;
|
|
Value |= *DataBytes++;
|
|
case 1:
|
|
Value <<= 8;
|
|
Value |= *DataBytes++;
|
|
default:
|
|
return Value;
|
|
}
|
|
}
|
|
|
|
} // namespace unsync
|