29 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ValidityPeriod>));
30 BOOST_CONCEPT_ASSERT((WireEncodable<ValidityPeriod>));
31 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<ValidityPeriod>));
32 BOOST_CONCEPT_ASSERT((WireDecodable<ValidityPeriod>));
33 static_assert(std::is_base_of<tlv::Error, ValidityPeriod::Error>::value,
34 "ValidityPeriod::Error must inherit from tlv::Error");
36 static const size_t ISO_DATETIME_SIZE = 15;
37 static const size_t NOT_BEFORE_OFFSET = 0;
38 static const size_t NOT_AFTER_OFFSET = 1;
40 using boost::chrono::time_point_cast;
51 time::system_clock::TimePoint())
57 : m_notBefore(time_point_cast<TimePoint::
duration>(notBefore + TimePoint::
duration(1) -
58 time::system_clock::TimePoint::
duration(1)))
59 , m_notAfter(time_point_cast<TimePoint::
duration>(notAfter))
68 template<encoding::Tag TAG>
72 size_t totalLength = 0;
77 totalLength += encoder.prependVarNumber(totalLength);
96 m_wire = buffer.block();
106 NDN_THROW(
Error(
"The supplied block does not contain wire format"));
119 m_wire.
elements()[NOT_BEFORE_OFFSET].value_size() != ISO_DATETIME_SIZE ||
121 m_wire.
elements()[NOT_AFTER_OFFSET].value_size() != ISO_DATETIME_SIZE) {
126 m_notBefore = time_point_cast<TimePoint::duration>(
128 m_notAfter = time_point_cast<TimePoint::duration>(
131 catch (
const std::bad_cast&) {
132 NDN_THROW(
Error(
"Invalid date format in NOT-BEFORE or NOT-AFTER field"));
143 m_notAfter = time_point_cast<TimePoint::duration>(notAfter);
147 std::pair<time::system_clock::TimePoint, time::system_clock::TimePoint>
150 return {m_notBefore, m_notAfter};
156 return m_notBefore <= now && now <= m_notAfter;
Represents a TLV element of the NDN packet format.
size_t elements_size() const noexcept
Equivalent to elements().size().
const element_container & elements() const noexcept
Get container of sub-elements.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
void reset() noexcept
Reset the Block to a default-constructed state.
void parse() const
Parse TLV-VALUE into sub-elements.
Represents a ValidityPeriod TLV element.
ValidityPeriod()
Set validity period [UNIX epoch + 1 nanosecond, UNIX epoch] that is always invalid.
bool isValid(const time::system_clock::TimePoint &now=time::system_clock::now()) const
Check if now falls within the validity period.
void wireDecode(const Block &wire)
Decode ValidityPeriod from TLV block.
static ValidityPeriod makeRelative(time::seconds validFrom, time::seconds validUntil, const time::system_clock::TimePoint &now=time::system_clock::now())
Construct ValidityPeriod relative to a timepoint.
std::pair< time::system_clock::TimePoint, time::system_clock::TimePoint > getPeriod() const
Get the stored validity period.
ValidityPeriod & setPeriod(const time::system_clock::TimePoint ¬Before, const time::system_clock::TimePoint ¬After)
Set validity period [notBefore, notAfter].
const Block & wireEncode() const
Encode ValidityPeriod into TLV block.
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
EncodingImpl< EstimatorTag > EncodingEstimator
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
EncodingImpl< EncoderTag > EncodingBuffer
std::ostream & operator<<(std::ostream &os, const AdditionalDescription &desc)
std::string toIsoString(const system_clock::time_point &timePoint)
Convert to the ISO 8601 string representation, basic format (YYYYMMDDTHHMMSS,fffffffff).
boost::chrono::duration< Rep, Period > duration
system_clock::time_point fromIsoString(const std::string &isoString)
Convert from the ISO 8601 basic string format (YYYYMMDDTHHMMSS,fffffffff) to the internal time format...
boost::chrono::seconds seconds