partial sync: segment hello and sync data
add segment publisher
refs: #4662
Change-Id: I62e7a2247bac58aeec364cd2a4e4d34259eae4af
diff --git a/src/detail/state.cpp b/src/detail/state.cpp
index e5c6c47..d245c0b 100644
--- a/src/detail/state.cpp
+++ b/src/detail/state.cpp
@@ -71,29 +71,46 @@
void
State::wireDecode(const ndn::Block& wire)
{
- if (!wire.hasWire()) {
- BOOST_THROW_EXCEPTION(ndn::tlv::Error("The supplied block does not contain wire format"));
+ auto blockType = wire.type();
+
+ if (blockType != tlv::PSyncContent && blockType != ndn::tlv::Content) {
+ BOOST_THROW_EXCEPTION(ndn::tlv::Error("Expected Content/PSyncContent Block, but Block is of a different type: #" +
+ ndn::to_string(blockType)));
+ return;
}
wire.parse();
+
m_wire = wire;
auto it = m_wire.elements_begin();
- if (it->type() != tlv::PSyncContent) {
- BOOST_THROW_EXCEPTION(ndn::tlv::Error("Unexpected TLV type when decoding Content: " +
- ndn::to_string(wire.type())));
+ if (it == m_wire.elements_end()) {
+ return;
}
- it->parse();
-
- for (auto val = it->elements_begin(); val != it->elements_end(); ++val) {
- if (val->type() == ndn::tlv::Name) {
- m_content.emplace_back(*val);
+ if (blockType == tlv::PSyncContent) {
+ while(it != m_wire.elements_end()) {
+ if (it->type() == ndn::tlv::Name) {
+ m_content.emplace_back(*it);
+ }
+ else {
+ BOOST_THROW_EXCEPTION(ndn::tlv::Error("Expected Name Block, but Block is of a different type: #" +
+ ndn::to_string(it->type())));
+ }
+ ++it;
}
- else {
- BOOST_THROW_EXCEPTION(ndn::tlv::Error("Expected Name Block, but Block is of a different type: #" +
- ndn::to_string(m_wire.type())));
+ }
+ else if (blockType == ndn::tlv::Content) {
+ it->parse();
+ for (auto val = it->elements_begin(); val != it->elements_end(); ++val) {
+ if (val->type() == ndn::tlv::Name) {
+ m_content.emplace_back(*val);
+ }
+ else {
+ BOOST_THROW_EXCEPTION(ndn::tlv::Error("Expected Name Block, but Block is of a different type: #" +
+ ndn::to_string(val->type())));
+ }
}
}
}