summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2023-09-03 20:11:35 -0600
committerKiritoDv <kiritodev01@gmail.com>2023-09-03 20:11:35 -0600
commit063224c69d564d6e10dd4febf25caa9f59fccfda (patch)
treec1edbd90c120d7b846490159540f68adfddfbb5a /lib
parent113472302904ac84d4ddf70df32ca245ad156bf2 (diff)
Fixed AIFC Extraction
Diffstat (limited to 'lib')
-rw-r--r--lib/binarytools/BinaryWriter.cpp13
-rw-r--r--lib/binarytools/BinaryWriter.h3
-rw-r--r--lib/hj/pyutils.h42
3 files changed, 49 insertions, 9 deletions
diff --git a/lib/binarytools/BinaryWriter.cpp b/lib/binarytools/BinaryWriter.cpp
index 362824f..6e0140f 100644
--- a/lib/binarytools/BinaryWriter.cpp
+++ b/lib/binarytools/BinaryWriter.cpp
@@ -132,10 +132,11 @@ void LUS::BinaryWriter::Write(double value) {
mStream->Write((char*)&value, sizeof(double));
}
-void LUS::BinaryWriter::Write(const std::string& str) {
- int strLen = str.size();
- Write(strLen);
-
+void LUS::BinaryWriter::Write(const std::string& str, bool writeLength) {
+ if(writeLength){
+ int strLen = str.size();
+ Write(strLen);
+ }
for (char c : str) {
mStream->WriteByte(c);
}
@@ -145,6 +146,10 @@ void LUS::BinaryWriter::Write(char* srcBuffer, size_t length) {
mStream->Write(srcBuffer, length);
}
+void LUS::BinaryWriter::WriteByte(char value) {
+ mStream->WriteByte(value);
+}
+
std::vector<char> LUS::BinaryWriter::ToVector() {
return mStream->ToVector();
}
diff --git a/lib/binarytools/BinaryWriter.h b/lib/binarytools/BinaryWriter.h
index fbd4f65..dca683f 100644
--- a/lib/binarytools/BinaryWriter.h
+++ b/lib/binarytools/BinaryWriter.h
@@ -33,8 +33,9 @@ class BinaryWriter {
void Write(uint64_t value);
void Write(float value);
void Write(double value);
- void Write(const std::string& str);
+ void Write(const std::string& str, bool writeLength = true);
void Write(char* srcBuffer, size_t length);
+ void WriteByte(char value);
std::vector<char> ToVector();
diff --git a/lib/hj/pyutils.h b/lib/hj/pyutils.h
index c5da4ee..f7dafbf 100644
--- a/lib/hj/pyutils.h
+++ b/lib/hj/pyutils.h
@@ -1,6 +1,7 @@
#pragma once
#include <vector>
+#include <unordered_map>
namespace PyUtils {
template<typename T>
@@ -12,12 +13,45 @@ std::vector<T> slice(std::vector<T> const &v, uint32_t m, uint32_t n = -1) {
return vec;
}
-std::vector<uint32_t> range(uint32_t start, uint32_t end) {
- std::vector<uint32_t> result;
- for (uint32_t i = start; i < end; ++i) {
- result.push_back(i);
+std::vector<uint32_t> range(uint32_t start, uint32_t end);
+
+template<typename T>
+T max(std::vector<T> const &v) {
+ T max = v[0];
+ for (auto const &value: v) {
+ if (value > max) {
+ max = value;
+ }
+ }
+ return max;
+}
+template<typename T>
+T min(std::vector<T> const &v) {
+ T min = v[0];
+ for (auto const &value: v) {
+ if (value < min) {
+ min = value;
+ }
+ }
+ return min;
+}
+
+template<typename T, typename X>
+std::vector<T> keys(std::unordered_map<T, X> const &map) {
+ std::vector<T> result;
+ for (auto const &pair: map) {
+ result.push_back(pair.first);
}
return result;
}
+}
+template <typename T>
+std::vector<T> operator+(std::vector<T> const &x, std::vector<T> const &y)
+{
+ std::vector<T> vec;
+ vec.reserve(x.size() + y.size());
+ vec.insert(vec.end(), x.begin(), x.end());
+ vec.insert(vec.end(), y.begin(), y.end());
+ return vec;
} \ No newline at end of file