lp: keep LpPacket parsed at all times
refs #4156
Change-Id: I21701ab0da2abacc8a84d6ee1a72c2b414e6669a
diff --git a/src/lp/packet.cpp b/src/lp/packet.cpp
index 751faa6..5714547 100644
--- a/src/lp/packet.cpp
+++ b/src/lp/packet.cpp
@@ -37,54 +37,17 @@
wireDecode(wire);
}
-template<encoding::Tag TAG>
-size_t
-Packet::wireEncode(EncodingImpl<TAG>& encoder) const
-{
- if (m_wire.hasWire()) {
- return m_wire.size();
- }
-
- size_t length = 0;
-
- for (const Block& element : boost::adaptors::reverse(m_wire.elements())) {
- length += encoder.prependBlock(element);
- }
-
- length += encoder.prependVarNumber(length);
- length += encoder.prependVarNumber(tlv::LpPacket);
-
- return length;
-}
-
-template size_t
-Packet::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder) const;
-
-template size_t
-Packet::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder) const;
-
Block
Packet::wireEncode() const
{
- if (m_wire.hasWire()) {
- return m_wire;
- }
-
// If no header or trailer, return bare network packet
Block::element_container elements = m_wire.elements();
if (elements.size() == 1 && elements.front().type() == FragmentField::TlvType::value) {
elements.front().parse();
- elements.front().elements().front().parse();
return elements.front().elements().front();
}
- EncodingEstimator estimator;
- size_t estimatedSize = wireEncode(estimator);
-
- EncodingBuffer buffer(estimatedSize, 0);
- wireEncode(buffer);
-
- m_wire = buffer.block();
+ m_wire.encode();
return m_wire;
}