Repo created
This commit is contained in:
parent
81b91f4139
commit
f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions
71
TMessagesProj/jni/tgnet/ByteArray.cpp
Normal file
71
TMessagesProj/jni/tgnet/ByteArray.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* This is the source code of tgnet library v. 1.1
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2015-2018.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include "ByteArray.h"
|
||||
#include "FileLog.h"
|
||||
|
||||
ByteArray::ByteArray() {
|
||||
bytes = nullptr;
|
||||
length = 0;
|
||||
}
|
||||
|
||||
ByteArray::ByteArray(uint32_t len) {
|
||||
bytes = new uint8_t[len];
|
||||
if (bytes == nullptr) {
|
||||
if (LOGS_ENABLED) DEBUG_E("unable to allocate byte buffer %u", len);
|
||||
exit(1);
|
||||
}
|
||||
length = len;
|
||||
}
|
||||
|
||||
|
||||
ByteArray::ByteArray(ByteArray *byteArray) {
|
||||
bytes = new uint8_t[byteArray->length];
|
||||
if (bytes == nullptr) {
|
||||
if (LOGS_ENABLED) DEBUG_E("unable to allocate byte buffer %u", byteArray->length);
|
||||
exit(1);
|
||||
}
|
||||
length = byteArray->length;
|
||||
memcpy(bytes, byteArray->bytes, length);
|
||||
}
|
||||
|
||||
ByteArray::ByteArray(uint8_t *buffer, uint32_t len) {
|
||||
bytes = new uint8_t[len];
|
||||
if (bytes == nullptr) {
|
||||
if (LOGS_ENABLED) DEBUG_E("unable to allocate byte buffer %u", len);
|
||||
exit(1);
|
||||
}
|
||||
length = len;
|
||||
memcpy(bytes, buffer, length);
|
||||
}
|
||||
|
||||
ByteArray::~ByteArray() {
|
||||
if (bytes != nullptr) {
|
||||
delete[] bytes;
|
||||
bytes = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ByteArray::alloc(uint32_t len) {
|
||||
if (bytes != nullptr) {
|
||||
delete[] bytes;
|
||||
bytes = nullptr;
|
||||
}
|
||||
bytes = new uint8_t[len];
|
||||
if (bytes == nullptr) {
|
||||
if (LOGS_ENABLED) DEBUG_E("unable to allocate byte buffer %u", len);
|
||||
exit(1);
|
||||
}
|
||||
length = len;
|
||||
}
|
||||
|
||||
bool ByteArray::isEqualTo(ByteArray *byteArray) {
|
||||
return byteArray->length == length && !memcmp(byteArray->bytes, bytes, length);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue