code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Binary markup serializator
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Binary markup serializator
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pichunkstream.h"
@@ -87,7 +87,7 @@
void PIChunkStream::setSource(const PIByteArray & data) {
data_ = const_cast<PIByteArray*>(&data);
data_ = const_cast<PIByteArray *>(&data);
_init();
}
@@ -110,13 +110,11 @@ PIByteArray PIChunkStream::data() const {
int PIChunkStream::read() {
switch (version_) {
case Version_1:
(*data_) >> last_id >> last_data;
break;
case Version_1: (*data_) >> last_id >> last_data; break;
case Version_2:
last_id = readVInt(*data_);
last_data.resize(readVInt(*data_));
//piCout << last_id << last_data.size();
// piCout << last_id << last_data.size();
(*data_) >> PIMemoryBlock(last_data.data(), last_data.size_s());
break;
default: break;
@@ -127,16 +125,14 @@ int PIChunkStream::read() {
int PIChunkStream::peekVInt(Version version_, uchar * data_, int sz, uint & ret) {
switch (version_) {
case Version_1:
memcpy(&ret, data_, 4);
return 4;
case Version_1: memcpy(&ret, data_, 4); return 4;
case Version_2: {
PIByteArray hdr(data_, piMini(4, sz));
hdr.resize(4);
uchar hsz = 0;
ret = readVInt(hdr, &hsz);
ret = readVInt(hdr, &hsz);
return hsz;
}
}
default: break;
}
return 0;
@@ -149,7 +145,7 @@ void PIChunkStream::replaceChunk(int id, const PIByteArray & v) {
PIByteArray nsba;
writeVInt(nsba, v.size());
int size_mod = (v.size_s() + nsba.size_s()) - (pos.length + pos.size_bytes);
pos.length = v.size_s();
pos.length = v.size_s();
if (size_mod != 0) {
auto it = data_map.makeIterator();
while (it.next()) {
@@ -176,7 +172,7 @@ void PIChunkStream::readAll() {
uint csz = 0, cid = 0;
while (pos < sz) {
pos += peekVInt((Version)version_, data_->data(pos), data_->size_s() - pos, cid);
hsz = peekVInt((Version)version_, data_->data(pos), data_->size_s() - pos, csz);
hsz = peekVInt((Version)version_, data_->data(pos), data_->size_s() - pos, csz);
pos += hsz;
data_map[cid] = CacheEntry(pos, csz, hsz);
pos += csz;
@@ -184,8 +180,7 @@ void PIChunkStream::readAll() {
}
PIChunkStream::~PIChunkStream() {
}
PIChunkStream::~PIChunkStream() {}
bool PIChunkStream::extract(PIByteArray & data, bool read_all) {
@@ -201,7 +196,7 @@ bool PIChunkStream::extract(PIByteArray & data, bool read_all) {
void PIChunkStream::_init() {
first_byte_taken = false;
last_id = -1;
last_id = -1;
last_data.clear();
if (!data_->isEmpty()) {
uchar v = data_->at(0);
@@ -212,10 +207,8 @@ void PIChunkStream::_init() {
version_ = (uchar)Version_2;
data_->pop_front();
first_byte_taken = true;
break;
default:
version_ = Version_1;
break;
break;
default: version_ = Version_1; break;
}
} else {
version_ = Version_1;
@@ -234,7 +227,8 @@ uint PIChunkStream::readVInt(PIByteArray & s, uchar * bytes_cnt) {
if ((bytes[0] & mask) == mask) {
bytes[0] &= (mask - 1);
s >> bytes[abc + 1];
} else break;
} else
break;
}
if (bytes_cnt) *bytes_cnt = (abc + 1);
uint ret = 0;