You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/dns/question.cpp

51 lines
1.1 KiB
C++

#include <dns/question.hpp>
#include <logger.hpp>
6 years ago
namespace llarp
{
namespace dns
{
Question::Question(Question&& other)
: qname(std::move(other.qname))
, qtype(std::move(other.qtype))
, qclass(std::move(other.qclass))
{
}
Question::Question(const Question& other)
: qname(other.qname), qtype(other.qtype), qclass(other.qclass)
{
}
6 years ago
bool
Question::Encode(llarp_buffer_t* buf) const
{
if(!EncodeName(buf, qname))
return false;
if(!llarp_buffer_put_uint16(buf, qtype))
6 years ago
return false;
return llarp_buffer_put_uint16(buf, qclass);
6 years ago
}
bool
Question::Decode(llarp_buffer_t* buf)
{
if(!DecodeName(buf, qname))
{
llarp::LogError("failed to decode name");
return false;
}
if(!llarp_buffer_read_uint16(buf, &qtype))
{
llarp::LogError("failed to decode type");
6 years ago
return false;
}
if(!llarp_buffer_read_uint16(buf, &qclass))
{
llarp::LogError("failed to decode class");
6 years ago
return false;
}
return true;
6 years ago
}
} // namespace dns
} // namespace llarp