| 401 | } |
| 402 | |
| 403 | void |
| 404 | DataSampleHeader::split(const ACE_Message_Block& orig, size_t size, |
| 405 | Message_Block_Ptr& head, Message_Block_Ptr& tail) |
| 406 | { |
| 407 | Message_Block_Ptr dup (orig.duplicate()); |
| 408 | const Encoding encoding(dsh_encoding_kind); |
| 409 | |
| 410 | const size_t length = dup->total_length(); |
| 411 | DataSampleHeader hdr(*dup); // deserialize entire header (with cfentries) |
| 412 | const size_t hdr_len = length - dup->total_length(); |
| 413 | const size_t this_max_serialized_size = get_max_serialized_size(); |
| 414 | |
| 415 | ACE_Message_Block* payload = dup.get(); |
| 416 | //skip zero length message blocks |
| 417 | ACE_Message_Block* prev = 0; |
| 418 | for (; payload->length() == 0; payload = payload->cont()) { |
| 419 | prev = payload; |
| 420 | } |
| 421 | Message_Block_Ptr payload_head; |
| 422 | if (prev) { |
| 423 | prev->cont(0); |
| 424 | payload_head.reset(payload); |
| 425 | } else { |
| 426 | payload_head.reset(payload->duplicate()); |
| 427 | } |
| 428 | |
| 429 | if (size < hdr_len) { // need to fragment the content_filter_entries_ |
| 430 | head.reset(alloc_msgblock(*dup, this_max_serialized_size, true)); |
| 431 | hdr.more_fragments_ = true; |
| 432 | hdr.message_length_ = 0; // no room for payload data |
| 433 | *head << hdr; |
| 434 | const size_t avail = size - head->length() - 4 /* sequence length */; |
| 435 | const CORBA::ULong n_entries = static_cast<CORBA::ULong>(avail / guid_cdr_size); |
| 436 | GUIDSeq entries(n_entries); |
| 437 | entries.length(n_entries); |
| 438 | // remove from the end of hdr's entries (order doesn't matter) |
| 439 | for (CORBA::ULong i(0), x(hdr.content_filter_entries_.length()); |
| 440 | i < n_entries; ++i) { |
| 441 | entries[i] = hdr.content_filter_entries_[--x]; |
| 442 | hdr.content_filter_entries_.length(x); |
| 443 | } |
| 444 | add_cfentries(&entries, head.get()); |
| 445 | |
| 446 | tail.reset(alloc_msgblock(*dup, this_max_serialized_size, true)); |
| 447 | hdr.more_fragments_ = false; |
| 448 | hdr.content_filter_ = (hdr.content_filter_entries_.length() > 0); |
| 449 | hdr.message_length_ = static_cast<ACE_UINT32>(payload->total_length()); |
| 450 | *tail << hdr; |
| 451 | tail->cont(payload_head.release()); |
| 452 | if (hdr.content_filter_) { |
| 453 | add_cfentries(&hdr.content_filter_entries_, tail.get()); |
| 454 | } |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | Message_Block_Ptr payload_tail; |
| 459 | split_payload(*payload, size - hdr_len, payload_head, payload_tail); |
| 460 | |