const char*
LabelSequence::getData(size_t *len) const {
+ *len = getDataLength();
+ return (&name_->ndata_[name_->offsets_[first_label_]]);
+}
+
+size_t
+LabelSequence::getDataLength() const {
// If the labelsequence is absolute, the current last_label_ falls
// out of the vector (since it points to the 'label' after the
// root label, which doesn't exist; in that case, return
// the length for the 'previous' label (the root label) plus
// one (for the root label zero octet)
if (isAbsolute()) {
- *len = name_.offsets_[last_label_ - 1] - name_.offsets_[first_label_] + 1;
+ return (name_->offsets_[last_label_ - 1] -
+ name_->offsets_[first_label_] + 1);
} else {
- *len = name_.offsets_[last_label_] - name_.offsets_[first_label_];
+ return (name_->offsets_[last_label_] - name_->offsets_[first_label_]);
}
- return (&name_.ndata_[name_.offsets_[first_label_]]);
}
bool
bool
LabelSequence::isAbsolute() const {
- return (last_label_ == name_.offsets_.size());
+ return (last_label_ == name_->offsets_.size());
}
} // end namespace dns
/// to the labels in the Name object).
///
/// \param name The Name to construct a LabelSequence for
- LabelSequence(const Name& name): name_(name),
+ LabelSequence(const Name& name): name_(&name),
first_label_(0),
last_label_(name.getLabelCount())
{}
/// \return Pointer to the wire-format data of this label sequence
const char* getData(size_t* len) const;
+ /// \brief Return the length of the wire-format data of this LabelSequence
+ ///
+ /// This method returns the number of octets for the data that would
+ /// be returned by the \c getData() method.
+ ///
+ /// Note that the return value of this method is always positive.
+ /// Note also that if the return value of this method is 1, it means the
+ /// sequence consists of the null label, i.e., a single "dot", and vice
+ /// versa.
+ ///
+ /// \note The data pointed to is only valid if the original Name
+ /// object is still in scope
+ ///
+ /// \return The length of the data of the label sequence in octets.
+ size_t getDataLength() const;
+
/// \brief Compares two label sequences.
///
/// Performs a (optionally case-insensitive) comparison between this
/// LabelSequence itself.
///
/// \return Reference to the original Name object
- const Name& getName() const { return (name_); }
+ const Name& getName() const { return (*name_); }
/// \brief Checks whether the label sequence is absolute
///
bool isAbsolute() const;
private:
- const Name& name_;
+ const Name* name_;
size_t first_label_;
size_t last_label_;
};
const char* data = ls.getData(&len);
ASSERT_EQ(expected_len, len) << "Expected data: " << expected_data <<
" name: " << ls.getName().toText();
+ EXPECT_EQ(expected_len, ls.getDataLength()) <<
+ "Expected data: " << expected_data <<
+ " name: " << ls.getName().toText();
for (size_t i = 0; i < len; ++i) {
EXPECT_EQ(expected_data[i], data[i]) << "Difference at pos " << i <<
": Expected data: " <<