shared_data xcc_z::gzip(data_ref s) { unsigned long cb_d = s.size() + (s.size() + 999) / 1000 + 12; shared_data d(10 + cb_d + 8); unsigned char* w = d.data(); *w++ = 0x1f; *w++ = 0x8b; *w++ = Z_DEFLATED; *w++ = 0; *w++ = 0; *w++ = 0; *w++ = 0; *w++ = 0; *w++ = 0; *w++ = 3; { z_stream stream; stream.zalloc = NULL; stream.zfree = NULL; stream.opaque = NULL; deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); stream.next_in = const_cast<unsigned char*>(s.begin()); stream.avail_in = s.size(); stream.next_out = w; stream.avail_out = cb_d; deflate(&stream, Z_FINISH); deflateEnd(&stream); w = stream.next_out; } w = write_int_le(4, w, crc32(crc32(0, NULL, 0), s.data(), s.size())); w = write_int_le(4, w, s.size()); return d.substr(0, w - d.data()); }
void SER_Recorder::write_long_int_le(uint64_t *i) { if (is_little_endian()) { fwrite((const void *)((uint32_t *)i), sizeof(int), 1, f); fwrite((const void *)((uint32_t *)(i) + 1), sizeof(int), 1, f); } else { write_int_le((uint32_t *)(i) + 1); write_int_le((uint32_t *)(i)); } }
void Cxif_value::save(byte*& data) const { *data++ = m_type; switch (m_type) { case vt_bin32: case vt_int32: data = write_int_le(4, data, get_int()); break; case vt_float: data = write_float(data, get_float()); break; default: { int size = get_size(); data = write_int_le(4, data, size); memcpy(data, get_data(), size); data += size; } } }
void SER_Recorder::write_header(ser_header *s) { fwrite((const void *)(s->FileID), sizeof(char), 14, f); write_int_le(&(s->LuID)); write_int_le(&(s->ColorID)); write_int_le(&(s->LittleEndian)); write_int_le(&(s->ImageWidth)); write_int_le(&(s->ImageHeight)); write_int_le(&(s->PixelDepth)); write_int_le(&(s->FrameCount)); fwrite((const void *)(s->Observer), sizeof(char), 40, f); fwrite((const void *)(s->Instrume), sizeof(char), 40, f); fwrite((const void *)(s->Telescope), sizeof(char), 40, f); write_long_int_le(&(s->DateTime)); write_long_int_le(&(s->DateTime_UTC)); }