Skip to content

Commit

Permalink
Merge remote-tracking branch 'robux4/unsigned_size_length'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbunkus committed Feb 24, 2024
2 parents c58256e + 0c069c5 commit 12d94e0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ constexpr std::size_t countof(T const (&)[N]) noexcept
\param MinSizeLength minimum size length to encode the value (0 for shortest size)
\param bSizeIsFinite whether the size will be written as an infinite EBML size or not
*/
int EBML_DLL_API CodedSizeLength(std::uint64_t Value, unsigned int MinSizeLength, bool bSizeIsFinite = true);
unsigned int EBML_DLL_API CodedSizeLength(std::uint64_t Value, unsigned int MinSizeLength, bool bSizeIsFinite = true);

/*!
\brief The coded value of the EBML-coded integer
Expand Down Expand Up @@ -464,8 +464,8 @@ class EBML_DLL_API EbmlElement {
virtual const EbmlCallbacks & ElementSpec() const { return ClassInfo; }

/// Set the minimum length that will be used to write the element size (-1 = optimal)
void SetSizeLength(int NewSizeLength) {SizeLength = NewSizeLength;}
int GetSizeLength() const {return SizeLength;}
void SetSizeLength(unsigned int NewSizeLength) {SizeLength = NewSizeLength;}
unsigned int GetSizeLength() const {return SizeLength;}

static EbmlElement * FindNextElement(IOCallback & DataStream, const EbmlSemanticContext & Context, int & UpperLevel, std::uint64_t MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1);
static EbmlElement * FindNextID(IOCallback & DataStream, const EbmlCallbacks & ClassInfos, std::uint64_t MaxDataSize);
Expand Down Expand Up @@ -599,7 +599,7 @@ class EBML_DLL_API EbmlElement {
private:
std::uint64_t Size; ///< the size of the data to write
std::uint64_t DefaultSize; ///< Minimum data size to fill on rendering (0 = optimal)
int SizeLength{0}; /// the minimum size on which the size will be written (0 = optimal)
unsigned int SizeLength{0}; /// the minimum size on which the size will be written (0 = optimal)
bool bSizeIsFinite{true};
std::uint64_t ElementPosition{0};
std::uint64_t SizePosition{0};
Expand Down
2 changes: 1 addition & 1 deletion ebml/EbmlMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class EBML_DLL_API EbmlMaster : public EbmlElement {
/*!
\brief facility for Master elements to write only the head and force the size later
*/
filepos_t WriteHead(IOCallback & output, int SizeLength, const ShouldWrite& writeFilter = WriteSkipDefault);
filepos_t WriteHead(IOCallback & output, unsigned int SizeLength, const ShouldWrite& writeFilter = WriteSkipDefault);

void EnableChecksum(bool bIsEnabled = true) { bChecksumUsed = bIsEnabled; }
bool HasChecksum() const {return bChecksumUsed;}
Expand Down
10 changes: 5 additions & 5 deletions src/EbmlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace libebml {
/*!
\todo handle more than CodedSize of 5
*/
int CodedSizeLength(std::uint64_t Length, unsigned int SizeLength, bool bSizeIsFinite)
unsigned int CodedSizeLength(std::uint64_t Length, unsigned int SizeLength, bool bSizeIsFinite)
{
unsigned int CodedSize;
if (bSizeIsFinite) {
Expand All @@ -50,12 +50,12 @@ int CodedSizeLength(std::uint64_t Length, unsigned int SizeLength, bool bSizeIsF
else CodedSize = 5;
}

if (SizeLength > 0 && CodedSize < SizeLength) {
if (CodedSize < SizeLength) {
// defined size
CodedSize = SizeLength;
}

return static_cast<int>(CodedSize);
return CodedSize;
}

int CodedValueLength(std::uint64_t Length, int CodedSize, binary * OutBuffer)
Expand Down Expand Up @@ -524,7 +524,7 @@ filepos_t EbmlElement::MakeRenderHead(IOCallback & output, bool bKeepPosition)
FinalHeadSize = EBML_ID_LENGTH((const EbmlId&)*this);
EbmlId(*this).Fill(FinalHead.data());

const int CodedSize = CodedSizeLength(Size, SizeLength, bSizeIsFinite);
const unsigned int CodedSize = CodedSizeLength(Size, SizeLength, bSizeIsFinite);
CodedValueLength(Size, CodedSize, &FinalHead.at(FinalHeadSize));
FinalHeadSize += CodedSize;

Expand Down Expand Up @@ -568,7 +568,7 @@ bool EbmlElement::ForceSize(std::uint64_t NewSize)
return false;
}

const int OldSizeLen = CodedSizeLength(Size, SizeLength, bSizeIsFinite);
const auto OldSizeLen = CodedSizeLength(Size, SizeLength, bSizeIsFinite);
const std::uint64_t OldSize = Size;

Size = NewSize;
Expand Down
2 changes: 1 addition & 1 deletion src/EbmlMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ std::uint64_t EbmlMaster::UpdateSize(const ShouldWrite & writeFilter, bool bForc
return GetSize();
}

filepos_t EbmlMaster::WriteHead(IOCallback & output, int nSizeLength, const ShouldWrite& writeFilter)
filepos_t EbmlMaster::WriteHead(IOCallback & output, unsigned int nSizeLength, const ShouldWrite& writeFilter)
{
SetSizeLength(nSizeLength);
return RenderHead(output, false, writeFilter);
Expand Down

0 comments on commit 12d94e0

Please sign in to comment.