size_t BuiltinProtocolHandlersLocal::write(const ByteStream &byteStream) { if (d->m_fd == -1) { return 0; } return ::write(d->m_fd, byteStream.data(), byteStream.size()); }
ByteStream EstFilterMessageFormat::buildCommand_set(const InertialChannels& channels, uint16 sampleRateBase) { //container to hold the command's field data ByteStream fieldData; //add the command selector byte fieldData.append_uint8(static_cast<uint8>(Inertial_Commands::cmd_setCurrent)); //add the number of channels fieldData.append_uint8(static_cast<uint8>(channels.size())); //loop through each channel in the vector of channels for(InertialChannel ch : channels) { //if we find a channel not in the descriptor set if(ch.descriptorSet() != DescriptorSet::DESC_SET_DATA_EST_FILTER) { throw Error("InertialChannel (" + Utils::toStr(ch.channelField()) + ") is not in the Estimation Filter descriptor set"); } //validate the sample rate for the channel ch.validateSampleRate(sampleRateBase); //add the field descriptor and rate decimation fieldData.append_uint8(ch.fieldDescriptor()); fieldData.append_uint16(ch.rateDecimation(sampleRateBase)); } //build and return the command bytes return GenericInertialCommand::buildCommand(CMD_ID, fieldData.data()); }
void MeshSaverImplv1_0::WriteIndexData(MeshBuffer* buffer, ChunkOutputStream& outStream) { ByteStream indices; buffer->GetOptimizedIndices(indices); OutputSerializer& ser = outStream.BeginChunk(MCID_INDEX_DATA); uint32 size = (uint32)indices.size(); uint32 count = buffer->GetIndexCount(); ser << size << count; if ((size / count) == 4) { OutputSerializer::UIntArray arr(reinterpret_cast<uint32*>(indices.data()), count); ser << arr; } else { OutputSerializer::UShortArray arr(reinterpret_cast<uint16*>(indices.data()), count); ser << arr; } outStream.EndChunk(); }
Matrix::Matrix(uint16 rows, uint16 columns, ValueType storedAs, const ByteStream& data): m_numRows(rows), m_numColumns(columns), m_data(data.data()), m_valuesType(storedAs), m_valuesTypeSize(Utils::valueTypeSize(storedAs)) { }
void BlockFile::copy(ByteStream const& buf, unsigned offset, unsigned nbytes) { //M_ASSERT(offset + nbytes <= m_buffer.m_capacity); unsigned char* data = m_buffer.m_data + offset; if (m_mode == ReadWriteLength) { ByteStream::set(data, ByteStream::uint24_t(nbytes)); ::memcpy(data + 3, buf.data(), nbytes - 3); } else { ::memcpy(data, buf.data(), nbytes); } }
void net::Server::sendChunkUpdate(const Client* to, const ChunkCoord& wcc, bool dirtyOnly) { auto chunk = world->getChunk(wcc); if (!dirtyOnly || clientChunkDirty(to, wcc)) { ByteStream bs; world->serializeChunk(bs, wcc); auto packet = enet_packet_create(bs.data(), bs.size(), ENET_PACKET_FLAG_RELIABLE); enet_peer_send(to->peer, CHAN_CHUNK, packet); } }
void net::Server::sendPlayerCameraUpdate(const Client* to, Entity::ID followID) { ByteStream bs; // TODO: put this somewhere better // TODO: for now, this is the only server->client message on CHAN_PLAYERCMD, // but this should have a message type later. bs.write(followID, LE); auto packet = enet_packet_create(bs.data(), bs.size(), ENET_PACKET_FLAG_RELIABLE); enet_peer_send(to->peer, CHAN_PLAYERCMD, packet); }
//========================================================================================== //ESTIMATION FILTER MESSAGE FORMAT ByteStream EstFilterMessageFormat::buildCommand_get() { //container to hold the command's field data ByteStream fieldData; //add the command selector byte fieldData.append_uint8(static_cast<uint8>(Inertial_Commands::cmd_getCurrent)); //"get" has no channels, so add 0 fieldData.append_uint8(0); //build and return the command bytes return GenericInertialCommand::buildCommand(CMD_ID, fieldData.data()); }
WirelessPacket buildAutoCalNodeRecResponse(int nodeAddress) { ByteStream payload; payload.append_uint16(0x0064); //cmd id payload.append_uint8(0x00); //status flag payload.append_float(5.0f); //time to completion WirelessPacket packet; packet.deliveryStopFlags(DeliveryStopFlags::fromByte(0x07)); packet.type(WirelessPacket::packetType_NodeReceived); packet.nodeAddress(nodeAddress); packet.payload(payload.data()); return packet; }
bool ByteStream::saveToFile(const ByteStream& byteStream, const std::string& fileName) { std::ofstream file(fileName.c_str(), std::ios_base::out | std::ios_base::binary); if(!file.is_open()) { return false; } file.write(byteStream.data(), byteStream.size()); file.flush(); return true; }
void MeshSaverImplv1_0::WriteVertexBufferData(MeshBuffer* buffer, uint32 numVB, ChunkOutputStream& outStream) { ByteStream bytes; for (uint32 i = 0; i < numVB; ++i) { OutputSerializer& ser = outStream.BeginChunk(MCID_VERTEX_BUFFER_DATA); uint32 vertexCount = buffer->GetVertexCount(); uint32 vertexStride = buffer->GetVertexStride(i); uint32 bufferSize = vertexCount * vertexStride; uint16 streamIndex = (uint16)i; ser << bufferSize << vertexCount << streamIndex << vertexStride; buffer->GetVertices(i, bytes); OutputSerializer::UByteArray arr(bytes.data(), (uint32)bytes.size()); NEX_ASSERT(arr.second == bufferSize); ser << arr; outStream.EndChunk(); } }
int main(int argc, char **argv) { Application app(argc, argv); const File f(Uri(app.getPath(Application::Home), ".bashrc"), &app); ProtocolHandler *const protocolHandler = f.protocolHandler(); IDEAL_SDEBUG("*** Contents following: "); protocolHandler->open(f.uri()); ByteStream read; int i = 0; while ((read = protocolHandler->read(BUFFER_SIZE)).size()) { std::cout << read.data(); ++i; } protocolHandler->close(); IDEAL_SDEBUG("*** I had to read " << i << " times"); return 0; }
WirelessPacket buildAutoCalCompletionResponse(int nodeAddress) { ByteStream payload; payload.append_uint16(0x0064); //cmd id payload.append_uint8(0x00); //completion flag payload.append_uint8(0x00); //ch1 error flag payload.append_float(0.0f); //ch1 offset payload.append_uint8(0x00); //ch2 error flag payload.append_float(0.0f); //ch2 offset payload.append_uint8(0x00); //ch3 error flag payload.append_float(0.0f); //ch3 offset payload.append_float(20.5f);//temperature //build the correct packet response first WirelessPacket packet; packet.deliveryStopFlags(DeliveryStopFlags::fromByte(0x07)); packet.type(WirelessPacket::packetType_reply); packet.nodeAddress(nodeAddress); packet.payload(payload.data()); return packet; }
void Client::start(){ bool hasHeader = false; Packet pak; ByteStream header; ByteStream* read = &header; pak.mData.reserve(1024); header.reserve(16); header.setDataSize(startHandshake()); bool error = false; while(!error){ if(mSocket->canRead()){ int result = mSocket->read(read->data() + read->tell(), read->size() - read->tell()); if(result == -1){ error = true; break; }else if(result > 0){ read->skip(result); if(read->tell() != read->size()) continue; if(mHandshakeStage != HS_COMPLETE){ read->setDataSize(onReceiveHandshake(read)); read->seek(0); continue; } if(!hasHeader){ uint32 hSize = Packet::getHeaderSize(*read); if(read->size() < hSize){ read->setDataSize(hSize); continue; } read->seek(0); pak.deserialise(*read); hasHeader = true; read = &pak.mData; read->seek(0); read->setDataSize(pak.mHeader.mBodySize + pak.mHeader.mBodySize / mChunkSize); }else{ read->dechunk(mChunkSize); read->seek(0); onReceivePacket(&pak); hasHeader = false; read = &header; read->seek(0); read->setDataSize(1); } } if(error) break; } if(mSocket->canWrite() && mSendData.size()){ mSendLock->lock(); while(mSendData.size()){ ByteStream* stream = mSendData.front(); mSocket->write(stream->data(), stream->size()); delete stream; mSendData.pop(); } mSendLock->unlock(); } }; mSocket->getLastError(); disconnect(); }
//appends the entire contents of a bytestream of the end of another bytestream void ByteStream::appendByteStream(const ByteStream& otherStream) { const Bytes& data = otherStream.data(); m_bytes.insert(m_bytes.end(), data.begin(), data.end()); }
//compares two byte streams to see if they are equal bool operator ==(ByteStream& stream1, ByteStream& stream2) { return stream1.data() == stream2.data(); }
void net::Server::sendDeletedEntityUpdate(const Client* to, Entity::ID id) { ByteStream bs; world->entityManager.serializeEntityDelete(bs, id); auto packet = enet_packet_create(bs.data(), bs.size(), ENET_PACKET_FLAG_RELIABLE); enet_peer_send(to->peer, CHAN_ENTITY, packet); }