mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
GzipNoCompression for datagrams
This commit is contained in:
parent
7ebf2f010c
commit
648d035a0f
3 changed files with 25 additions and 2 deletions
|
@ -174,6 +174,28 @@ namespace data
|
|||
htole32buf (out + inLen + 19, inLen);
|
||||
return inLen + 23;
|
||||
}
|
||||
|
||||
size_t GzipNoCompression (const std::vector<std::pair<const uint8_t *, size_t> >& bufs, uint8_t * out, size_t outLen)
|
||||
{
|
||||
static const uint8_t gzipHeader[11] = { 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x01 };
|
||||
memcpy (out, gzipHeader, 11);
|
||||
uint32_t crc = 0;
|
||||
size_t len = 0, len1;
|
||||
for (const auto& it: bufs)
|
||||
{
|
||||
len1 = len;
|
||||
len += it.second;
|
||||
if (outLen < len + 23) return 0;
|
||||
memcpy (out + 15 + len1, it.first, it.second);
|
||||
crc = crc32 (crc, it.first, it.second);
|
||||
}
|
||||
if (len > 0xffff) return 0;
|
||||
htole32buf (out + len + 15, crc);
|
||||
htole32buf (out + len + 19, len);
|
||||
htole16buf (out + 11, len);
|
||||
htole16buf (out + 13, 0xffff - len);
|
||||
return len + 23;
|
||||
}
|
||||
|
||||
} // data
|
||||
} // i2p
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue