Beispiel #1
0
	void Inventory::save(Stream &sr) const {
		encodeInt(sr, size());
		for(int n = 0; n < size(); n++) {
			encodeInt(sr, m_entries[n].count);
			sr << m_entries[n].item;
		}
	}
Beispiel #2
0
	void Entity::save(Stream &sr) const {
		EntityWorldProxy::save(sr);

		bool can_compress =
			m_seq_idx >= 0 && m_seq_idx <= 255 &&
			m_frame_idx >= 0 && m_frame_idx <= 255 &&
			m_dir_idx >= 0 && m_dir_idx <= 255;

		u8 flags =	(can_compress? flag_compressed : 0) |
					(m_is_seq_looped? flag_is_looped : 0) |
					(m_is_seq_finished? flag_is_finished : 0) |
					(m_oframe_idx != -1 || m_oseq_idx != -1? flag_has_overlay : 0);

		sr.pack(flags, m_pos, m_dir_angle);

		if(can_compress)
			sr.pack(u8(m_seq_idx), u8(m_frame_idx), u8(m_dir_idx));
		else
			sr.pack(m_seq_idx, m_frame_idx, m_dir_idx);

		if(flags & flag_has_overlay) {
			encodeInt(sr, m_oseq_idx);
			encodeInt(sr, m_oframe_idx);
		}
	}
Beispiel #3
0
	void EntityRef::save(Stream &sr) const {
		if(m_index == -1)
			encodeInt(sr, -1);
		else {
			encodeInt(sr, m_index);
			encodeInt(sr, m_unique_id);
		}
	}
Beispiel #4
0
int64_t LogEncoderDecoder::encodeFileInvalidationEntry(char *dest,
                                                       const int64_t &seqId) {
  char *ptr = dest + sizeof(int16_t);
  int64_t size = 0;
  ptr[size++] = TransferLogManager::FILE_INVALIDATION;
  encodeInt(ptr, size, timestampInMicroseconds());
  encodeInt(ptr, size, seqId);
  folly::storeUnaligned<int16_t>(dest, size);
  return (size + sizeof(int16_t));
}
Beispiel #5
0
int64_t LogEncoderDecoder::encodeFileResizeEntry(char *dest,
                                                 const int64_t seqId,
                                                 const int64_t fileSize) {
  char *ptr = dest + sizeof(int16_t);
  int64_t size = 0;
  ptr[size++] = TransferLogManager::FILE_RESIZE;
  encodeInt(ptr, size, timestampInMicroseconds());
  encodeInt(ptr, size, seqId);
  encodeInt(ptr, size, fileSize);

  folly::storeUnaligned<int16_t>(dest, size);
  return (size + sizeof(int16_t));
}
Beispiel #6
0
int64_t LogEncoderDecoder::encodeBlockWriteEntry(char *dest,
                                                 const int64_t seqId,
                                                 const int64_t offset,
                                                 const int64_t blockSize) {
  char *ptr = dest + sizeof(int16_t);
  int64_t size = 0;
  ptr[size++] = TransferLogManager::BLOCK_WRITE;
  encodeInt(ptr, size, timestampInMicroseconds());
  encodeInt(ptr, size, seqId);
  encodeInt(ptr, size, offset);
  encodeInt(ptr, size, blockSize);

  folly::storeUnaligned<int16_t>(dest, size);
  return (size + sizeof(int16_t));
}
Beispiel #7
0
int64_t LogEncoderDecoder::encodeFileCreationEntry(char *dest,
                                                   const std::string &fileName,
                                                   const int64_t seqId,
                                                   const int64_t fileSize) {
  // increment by 2 bytes to later store the total length
  char *ptr = dest + sizeof(int16_t);
  int64_t size = 0;
  ptr[size++] = TransferLogManager::FILE_CREATION;
  encodeInt(ptr, size, timestampInMicroseconds());
  encodeString(ptr, size, fileName);
  encodeInt(ptr, size, seqId);
  encodeInt(ptr, size, fileSize);

  folly::storeUnaligned<int16_t>(dest, size);
  return (size + sizeof(int16_t));
}
Beispiel #8
0
    static uint32_t writeStrictArray(std::vector<uint8_t>& buffer, const std::vector<Node>& value)
    {
        uint32_t size = 0;

        uint32_t ret = encodeInt(buffer, 4, value.size());

        if (ret == 0)
        {
            return 0;
        }

        size += ret;

        for (const auto& i : value)
        {
            ret = i.encode(buffer);

            if (ret == 0)
            {
                return 0;
            }

            size += ret;
        }

        return size;
    }
Beispiel #9
0
int64_t LogEncoderDecoder::encodeLogHeader(char *dest,
                                           const std::string &recoveryId,
                                           const std::string &senderIp,
                                           int64_t config) {
  // increment by 2 bytes to later store the total length
  char *ptr = dest + sizeof(int16_t);
  int64_t size = 0;
  ptr[size++] = TransferLogManager::HEADER;
  encodeInt(ptr, size, timestampInMicroseconds());
  encodeInt(ptr, size, TransferLogManager::LOG_VERSION);
  encodeString(ptr, size, recoveryId);
  encodeString(ptr, size, senderIp);
  encodeInt(ptr, size, config);

  folly::storeUnaligned<int16_t>(dest, size);
  return (size + sizeof(int16_t));
}
Beispiel #10
0
    void OStream::writeVersionStamp()
    {

        if (mRuntimeVersion >= 6)
        {
            const std::size_t BufferLen = 1+5+5;
            char buffer[BufferLen] = {0};
            buffer[0] = BeginVersionStamp;

            RCF::ByteBuffer byteBuffer(&buffer[0], BufferLen);
            std::size_t pos = 1;
            encodeInt(mRuntimeVersion, byteBuffer, pos);
            encodeInt(mArchiveVersion, byteBuffer, pos);

            writeRaw(&buffer[0], static_cast<UInt32>(pos));
        }
    }
Beispiel #11
0
int64_t LogEncoderDecoder::encodeDirectoryInvalidationEntry(char *dest) {
  char *ptr = dest + sizeof(int16_t);
  int64_t size = 0;
  ptr[size++] = TransferLogManager::DIRECTORY_INVALIDATION;
  encodeInt(ptr, size, timestampInMicroseconds());
  folly::storeUnaligned<int16_t>(dest, size);
  return (size + sizeof(int16_t));
}
Beispiel #12
0
void LZWC::encodeAndWrite(int node, int sizeInBits) {
	int encodedSize;	
	ull token = encodeInt(node, sizeInBits, &encodedSize);
	if(encodedSize <= 0 || encodedSize > 64) {
		printf("EncodedSize %d Node %d SizeInBits %d\n", encodedSize, node, sizeInBits);
	}
	assert(encodedSize > 0 && encodedSize <= 64);
	writeTokenToFile(token, encodedSize);
}
Beispiel #13
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
std::string generateEventID(int year, uint64_t x, const std::string &prefix,
                            const string &pattern, std::string &textBlock, uint64_t *width) {
	string evtID;
	textBlock = "";

	for ( size_t i = 0; i < pattern.size(); ++i ) {
		if ( pattern[i] != '%' )
			evtID += pattern[i];
		else {
			++i;
			int len = 0;
			while ( i < pattern.size() ) {
				if ( pattern[i] >= '0' && pattern[i] <= '9' ) {
					len *= 10;
					len += int(pattern[i] - '0');
					++i;
					continue;
				}
				else if ( pattern[i] == '%' ) {
					evtID += pattern[i];
				}
				else if ( pattern[i] == 'c' ) {
					textBlock = encodeChar(x, len, width);
					evtID += textBlock;
				}
				else if ( pattern[i] == 'C' ) {
					textBlock = makeUpper(encodeChar(x, len, width));
					evtID += textBlock;
				}
				else if ( pattern[i] == 'd' ) {
					textBlock = encodeInt(x, len, width);
					evtID += textBlock;
				}
				else if ( pattern[i] == 'x' ) {
					textBlock = encodeHex(x, len, width);
					evtID += textBlock;
				}
				else if ( pattern[i] == 'X' ) {
					textBlock = makeUpper(encodeHex(x, len, width));
					evtID += textBlock;
				}
				else if ( pattern[i] == 'Y' )
					evtID += toString(year);
				else if ( pattern[i] == 'p' )
					evtID += prefix;
				else
					return "";

				break;
			}
		}
	}

	return evtID;
}
 void TSaslTransport::sendSaslMessage(const NegotiationStatus status,
     const uint8_t* payload, const uint32_t length, bool flush) {
   uint8_t messageHeader[STATUS_BYTES + PAYLOAD_LENGTH_BYTES];
   uint8_t dummy = 0;
   if (payload == NULL) {
     payload = &dummy;
   }
   messageHeader[0] = (uint8_t)status;
   encodeInt(length, messageHeader, STATUS_BYTES);
   transport_->write(messageHeader, HEADER_LENGTH);
   transport_->write(payload, length);
   if (flush) transport_->flush();
 }
Beispiel #15
0
    void OStream::writeArchiveMetadata()
    {
        if (mRuntimeVersion >= 6)
        {
            // Max possible size.
            const std::size_t BufferLen = 1+5+5+1;

            char buffer[BufferLen] = {0};
            buffer[0] = BeginArchiveMetadata;

            RCF::ByteBuffer byteBuffer(&buffer[0], BufferLen);
            std::size_t pos = 1;
            encodeInt(mRuntimeVersion, byteBuffer, pos);
            encodeInt(mArchiveVersion, byteBuffer, pos);

            if (mRuntimeVersion >= 10)
            {
                encodeBool(getTrackingContext().getEnabled(), byteBuffer, pos);
            }

            writeRaw(&buffer[0], static_cast<UInt32>(pos));
        }
    }
Beispiel #16
0
Vector<char> KeyPrefix::encode() const
{
    ASSERT(m_databaseId != InvalidId);
    ASSERT(m_objectStoreId != InvalidId);
    ASSERT(m_indexId != InvalidId);

    Vector<char> databaseIdString = encodeInt(m_databaseId);
    Vector<char> objectStoreIdString = encodeInt(m_objectStoreId);
    Vector<char> indexIdString = encodeInt(m_indexId);

    ASSERT(databaseIdString.size() <= 8);
    ASSERT(objectStoreIdString.size() <= 8);
    ASSERT(indexIdString.size() <= 4);


    unsigned char firstByte = (databaseIdString.size() - 1) << 5 | (objectStoreIdString.size() - 1) << 2 | (indexIdString.size() - 1);
    Vector<char> ret;
    ret.append(firstByte);
    ret.append(databaseIdString);
    ret.append(objectStoreIdString);
    ret.append(indexIdString);

    return ret;
}
Beispiel #17
0
	void ActorInventory::save(Stream &sr) const {
		Inventory::save(sr);
		sr << u8(	(!m_weapon.isDummy()? 1 : 0) |
					(!m_armour.isDummy()? 2 : 0) |
					(!m_ammo.item.isDummy()? 4 : 0) );

		if(!m_weapon.isDummy())
			sr << m_weapon;
		if(!m_armour.isDummy())
			sr << m_armour;
		if(!m_ammo.item.isDummy()) {
			sr << m_ammo.item;
			encodeInt(sr, m_ammo.count);
		}
	}
void SshOutgoingPacket::generatePtyRequestPacket(quint32 remoteChannel,
    const SshPseudoTerminal &terminal)
{
    init(SSH_MSG_CHANNEL_REQUEST).appendInt(remoteChannel)
        .appendString("pty-req").appendBool(false)
        .appendString(terminal.termType).appendInt(terminal.columnCount)
        .appendInt(terminal.rowCount).appendInt(0).appendInt(0);
    QByteArray modeString;
    for (SshPseudoTerminal::ModeMap::ConstIterator it = terminal.modes.constBegin();
         it != terminal.modes.constEnd(); ++it) {
        modeString += char(it.key());
        modeString += encodeInt(it.value());
    }
    modeString += char(0); // TTY_OP_END
    appendString(modeString).finalize();
}
Beispiel #19
0
    void Sender::sendSetChunkSize()
    {
        rtmp::Packet packet;
        packet.channel = rtmp::Channel::SYSTEM;
        packet.timestamp = 0;
        packet.messageType = rtmp::MessageType::SET_CHUNK_SIZE;

        encodeInt(packet.data, 4, outChunkSize);

        std::vector<uint8_t> buffer;
        encodePacket(buffer, outChunkSize, packet, sentPackets);

#ifdef DEBUG
        std::cout << "Sending SET_CHUNK_SIZE" << std::endl;
#endif

        socket.send(buffer);
    }
Beispiel #20
0
    static uint32_t writeXMLDocument(std::vector<uint8_t>& buffer, const std::string& value)
    {
        uint32_t ret = encodeInt(buffer, 4, value.size());

        if (ret == 0)
        {
            return 0;
        }

        uint32_t size = ret;

        for (char i : value)
        {
            buffer.push_back(static_cast<uint8_t>(i));
            size += 1;
        }

        return size;
    }
Beispiel #21
0
    static uint32_t writeECMAArray(std::vector<uint8_t>& buffer, const std::map<std::string, Node>& value)
    {
        uint32_t size = 0;

        uint32_t ret = encodeInt(buffer, 4, value.size());

        if (ret == 0)
        {
            return 0;
        }

        size += ret;

        for (const auto& i : value)
        {
            ret = writeString(buffer, i.first);

            if (ret == 0)
            {
                return 0;
            }

            size += ret;

            ret = i.second.encode(buffer);

            if (ret == 0)
            {
                return 0;
            }

            size += ret;
        }

        return size;
    }
Beispiel #22
0
    static uint32_t writeDate(std::vector<uint8_t>& buffer, const Date& value)
    {
        uint32_t size = 0;

        uint32_t ret = encodeDouble(buffer, value.ms);

        if (ret == 0) // date in milliseconds from 01/01/1970
        {
            return 0;
        }

        size += ret;

        ret = encodeInt(buffer, 4, value.timezone);

        if (ret == 0) // unsupported timezone
        {
            return 0;
        }

        size += ret;

        return size;
    }
Beispiel #23
0
void LZWC::feedRawByte(Byte arg) {
	int nextNode = hashTable->get(make_pair(currentNode, arg));
	if(nextNode == -1) {
		int encodedNodeSize;
		ull token = encodeInt(currentNode, SIZE_IN_BITS(currentNode), &encodedNodeSize);
	
		int sizeOfUncompressedSeq = 1 + 9*seq.size(); //(1 + seq.size()) + 8 * seq.size();
		if(1 + encodedNodeSize <= sizeOfUncompressedSeq){ //verifica se vale a pena codificar os tokens ou enviar a sequência descomprimida
			writeTokenToFile(1, 1);
			writeTokenToFile(token, encodedNodeSize);
		}else {
			writeTokenToFile(1ULL << (seq.size()), 1+seq.size());
			for(int i = 0; i < seq.size(); ++i)
				writeTokenToFile(seq[i], 8);
		}
	
		//Insere o termo no dicionário	
		hashTable->put(make_pair(currentNode, arg), size);
		size++;
		if(size >= dictionaryMaxSize) {
			hashTable->clear();
			size = 1;
			for(int i = 0; i < 256; ++i) {
				hashTable->put(make_pair(0,i), size);
				size++;
			}
		}
	
		currentNode = hashTable->get(make_pair(0,arg));
		seq.clear();
		seq.push_back(arg);
	} else {
		currentNode = nextNode;
		seq.push_back(arg);
	}
}
  void TSaslTransport::writeLength(uint32_t length) {
    uint8_t lenBuf[PAYLOAD_LENGTH_BYTES];

    encodeInt(length, lenBuf, 0);
    transport_->write(lenBuf, PAYLOAD_LENGTH_BYTES);
  }
SshOutgoingPacket &SshOutgoingPacket::appendInt(quint32 val)
{
    m_data.append(encodeInt(val));
    return *this;
}
Beispiel #26
0
	void EntityWorldProxy::save(Stream &sr) const {
		encodeInt(sr, m_unique_id);
	}
Beispiel #27
0
	void ServerStatusChunk::save(Stream &sr) const {
		sr.pack(address.ip, address.port, game_mode, is_passworded);
		sr << server_name << map_name;
		encodeInt(sr, num_players);
		encodeInt(sr, max_players);
	}
bool BlinkyPendantUploader::startUpload(BlinkyController &controller,
                                        QList<PatternWriter> &patternWriters)
{
    // TODO: push the image conversions into here so they are less awkward.
    #define PIXEL_COUNT 10

    // Probe for the blinkypendant version
    // TODO: Update the firmware first!
    QSerialPortInfo portInfo;
    if (!controller.getPortInfo(portInfo)) {
        errorString = "Couln't get port information!";
        return false;
    }

    int version = getVersionForDevice(portInfo.vendorIdentifier(),
                                      portInfo.productIdentifier());

    QByteArray data;
    if (version == BLINKY_PENDANT_VERSION_1) {
        qDebug() << "Using version 1 upload mechanism, please update firmware!";

        // Make sure we have an image compatible with the BlinkyPendant
        if (patternWriters.front().getLedCount() != 10) {
            errorString = "Wrong pattern size- must be 10 pixels high!";
            return false;
        }
        if (patternWriters.front().getEncoding() != PatternWriter::RGB24) {
            errorString = "Wrong encoding type- must be RGB24!";
            return false;
        }

        if(patternWriters.front().getFrameCount() > 255) {
            errorString = "Pattern too long, must be < 256 frames";
            return false;
        }

        // Create the data structure to write to the device memory
        data.append((char)0x13);    // header
        data.append((char)0x37);
        data.append((char)patternWriters.front().getFrameCount());  // frame count
        data += patternWriters.front().getData();       // image data (RGB24, uncompressed)
    } else {
        // Create the data structure to write to the device memory
        // Animation table

        QByteArray patternData;

        data.append((char)0x31);    // header
        data.append((char)0x23);
        data.append((char)patternWriters.size()); // Number of patterns in the table
        data.append((char)PIXEL_COUNT);     // Number of LEDs in the pattern

        foreach (PatternWriter pattern, patternWriters) {
            // Make sure we have an image compatible with the BlinkyPendant
            if (pattern.getLedCount() != 10) {
                errorString = "Wrong pattern size- must be 10 pixels high!";
                return false;
            }
            if (pattern.getEncoding() != PatternWriter::RGB24) {
                errorString = "Wrong encoding type- must be RGB24!";
                return false;
            }

            if(pattern.getFrameCount() > 65535) {
                errorString = "Pattern too long, must be < 65535 frames";
                return false;
            }

            // Animation entry
            data.append((char)0);             // Encoding type (1 byte) (RGB24, uncompressed) (TODO)
            data += encodeInt(patternData.length());        // Data offset (4 bytes)
            data += encodeWord(pattern.getFrameCount());   // Frame count (2 bytes)
            data += encodeWord(0);                          // Frame delay (2 bytes) TODO

            // Make sure we have an image compatible with the BlinkyPendant
            patternData += pattern.getData();       // image data (RGB24, uncompressed)
        }

        data += patternData;
    }

    // TODO: Check if the data can fit in the device memory

    // Set up the commandQueue using the serial descriptor, and close the tape connection
    controller.close();
    commandQueue.open(portInfo);

    setProgress(0);

    // Queue the following commands:
    // 1. start write
    commandQueue.enqueue(BlinkyPendantCommands::startWrite());

    // 2-n. write data (aligned to 1024-byte sectors, 64 bytes at a time)
    commandQueue.enqueue(BlinkyPendantCommands::writeData(data));

    // n+1 stop write
    commandQueue.enqueue(BlinkyPendantCommands::stopWrite());

    return true;
}