Lines Matching refs:s
246 void ParentDef::GenMembers(std::ostream& s) const { in GenMembers()
249 if (fields_[i]->GenBuilderMember(s)) { in GenMembers()
250 s << "_{};"; in GenMembers()
255 void ParentDef::GenSize(std::ostream& s) const { in GenSize()
259 s << "protected:"; in GenSize()
260 s << "size_t BitsOfHeader() const {"; in GenSize()
261 s << "return 0"; in GenSize()
265 s << " + " << parent_->name_ << "Builder::BitsOfHeader() "; in GenSize()
267 s << " + " << parent_->name_ << "::BitsOfHeader() "; in GenSize()
272 s << " + " << field->GetBuilderSize(); in GenSize()
274 s << ";"; in GenSize()
276 s << "}\n\n"; in GenSize()
278 s << "size_t BitsOfFooter() const {"; in GenSize()
279 s << "return 0"; in GenSize()
281 s << " + " << field->GetBuilderSize(); in GenSize()
286 s << " + " << parent_->name_ << "Builder::BitsOfFooter() "; in GenSize()
288 s << " + " << parent_->name_ << "::BitsOfFooter() "; in GenSize()
291 s << ";"; in GenSize()
292 s << "}\n\n"; in GenSize()
295 s << "size_t GetPayloadSize() const {"; in GenSize()
296 s << "if (payload_ != nullptr) {return payload_->size();}"; in GenSize()
297 s << "else { return size() - (BitsOfHeader() + BitsOfFooter()) / 8;}"; in GenSize()
298 s << ";}\n\n"; in GenSize()
311 s << "public:"; in GenSize()
312 s << "virtual size_t size() const override {"; in GenSize()
314 s << "return " << padded_size.bytes() << ";}"; in GenSize()
315 s << "size_t unpadded_size() const {"; in GenSize()
317 s << "return (BitsOfHeader() / 8)"; in GenSize()
319 s << "+ payload_->size()"; in GenSize()
326 s << "+ body_size_extracted_"; in GenSize()
331 s << " + (BitsOfFooter() / 8);"; in GenSize()
332 s << "}\n"; in GenSize()
335 void ParentDef::GenSerialize(std::ostream& s) const { in GenSerialize()
339 s << "protected:"; in GenSerialize()
340 s << "void SerializeHeader(BitInserter&"; in GenSerialize()
342 s << " i "; in GenSerialize()
344 s << ") const {"; in GenSerialize()
348 s << parent_->name_ << "Builder::SerializeHeader(i);"; in GenSerialize()
350 s << parent_->name_ << "::SerializeHeader(i);"; in GenSerialize()
362 s << "size_t payload_bytes = GetPayloadSize();"; in GenSerialize()
365 s << "static_assert((" << modifier << ")%8 == 0, \"Modifiers must be byte-aligned\");"; in GenSerialize()
366 s << "payload_bytes = payload_bytes + (" << modifier << ") / 8;"; in GenSerialize()
368 … s << "ASSERT(payload_bytes < (static_cast<size_t>(1) << " << field->GetSize().bits() << "));"; in GenSerialize()
369 …s << "insert(static_cast<" << field->GetDataType() << ">(payload_bytes), i," << field->GetSize().b… in GenSerialize()
371 s << field->GetName() << "_extracted_ = 0;"; in GenSerialize()
372 s << "size_t local_size = " << name_ << "::size();"; in GenSerialize()
374 …s << "ASSERT((size() - local_size) < (static_cast<size_t>(1) << " << field->GetSize().bits() << ")… in GenSerialize()
375 …s << "insert(static_cast<" << field->GetDataType() << ">(size() - local_size), i," << field->GetSi… in GenSerialize()
383 s << "size_t " << vector_name + "bytes = 0;"; in GenSerialize()
385 s << "for (auto elem : " << vector_name << ") {"; in GenSerialize()
386 s << vector_name + "bytes += elem.size(); }"; in GenSerialize()
388 s << vector_name + "bytes = "; in GenSerialize()
389 s << vector_name << ".size() * ((" << vector->element_size_ << ") / 8);"; in GenSerialize()
393 s << "static_assert((" << modifier << ")%8 == 0, \"Modifiers must be byte-aligned\");"; in GenSerialize()
394 s << vector_name << "bytes = "; in GenSerialize()
395 s << vector_name << "bytes + (" << modifier << ") / 8;"; in GenSerialize()
397 s << "ASSERT(" << vector_name + "bytes < (1 << " << field->GetSize().bits() << "));"; in GenSerialize()
398 s << "insert(" << vector_name << "bytes, i, "; in GenSerialize()
399 s << field->GetSize().bits() << ");"; in GenSerialize()
408 s << "auto shared_checksum_ptr = std::make_shared<" << started_field->GetDataType() << ">();"; in GenSerialize()
409 s << "shared_checksum_ptr->Initialize();"; in GenSerialize()
410 s << "i.RegisterObserver(packet::ByteObserver("; in GenSerialize()
411 s << "[shared_checksum_ptr](uint8_t byte){ shared_checksum_ptr->AddByte(byte);},"; in GenSerialize()
412 …s << "[shared_checksum_ptr](){ return static_cast<uint64_t>(shared_checksum_ptr->GetChecksum());})… in GenSerialize()
414 s << "ASSERT(unpadded_size() <= " << field->GetSize().bytes() << ");"; in GenSerialize()
415 s << "size_t padding_bytes = "; in GenSerialize()
416 s << field->GetSize().bytes() << " - unpadded_size();"; in GenSerialize()
417 s << "for (size_t padding = 0; padding < padding_bytes; padding++) {i.insert_byte(0);}"; in GenSerialize()
420 s << "insert(" << vector_name << ".size(), i, " << field->GetSize().bits() << ");"; in GenSerialize()
422 field->GenInserter(s); in GenSerialize()
425 s << "}\n\n"; in GenSerialize()
427 s << "void SerializeFooter(BitInserter&"; in GenSerialize()
429 s << " i "; in GenSerialize()
431 s << ") const {"; in GenSerialize()
434 field->GenInserter(s); in GenSerialize()
438 s << parent_->name_ << "Builder::SerializeFooter(i);"; in GenSerialize()
440 s << parent_->name_ << "::SerializeFooter(i);"; in GenSerialize()
443 s << "}\n\n"; in GenSerialize()
445 s << "public:"; in GenSerialize()
446 s << "virtual void Serialize(BitInserter& i) const override {"; in GenSerialize()
447 s << "SerializeHeader(i);"; in GenSerialize()
449 s << "payload_->Serialize(i);"; in GenSerialize()
451 s << "SerializeFooter(i);"; in GenSerialize()
453 s << "}\n"; in GenSerialize()
456 void ParentDef::GenInstanceOf(std::ostream& s) const { in GenInstanceOf()
458 s << "static bool IsInstance(const " << parent_->name_ << "& parent) {"; in GenInstanceOf()
470 s << "if (parent." << field->GetName() << "_ != "; in GenInstanceOf()
472 s << std::get<int64_t>(constraint->second) << ")"; in GenInstanceOf()
473 s << "{ return false;}"; in GenInstanceOf()
475 s << std::get<std::string>(constraint->second) << ")"; in GenInstanceOf()
476 s << "{ return false;}"; in GenInstanceOf()
482 s << "return true;}"; in GenInstanceOf()