network: Add Mac16Address constructor

This commit is contained in:
Alberto Gallegos Ramonet
2023-03-16 11:51:48 +09:00
parent 05af2f45e0
commit 7786a55ec4
2 changed files with 18 additions and 0 deletions

View File

@@ -104,6 +104,12 @@ Mac16Address::Mac16Address(const char* str)
NS_ASSERT(i == 2);
}
Mac16Address::Mac16Address(uint16_t addr)
{
m_address[1] = addr & 0xFF;
m_address[0] = (addr >> 8) & 0xFF;
}
void
Mac16Address::CopyFrom(const uint8_t buffer[2])
{

View File

@@ -50,24 +50,34 @@ class Mac16Address
*/
Mac16Address(const char* str);
/**
* \param addr The 16 bit integer used to create a Mac16Address object.
*
* Create a Mac16Address from an 16 bit integer.
*/
Mac16Address(uint16_t addr);
/**
* \param buffer address in network order
*
* Copy the input address to our internal buffer.
*/
void CopyFrom(const uint8_t buffer[2]);
/**
* \param buffer address in network order
*
* Copy the internal address to the input buffer.
*/
void CopyTo(uint8_t buffer[2]) const;
/**
* \returns a new Address instance
*
* Convert an instance of this class to a polymorphic Address instance.
*/
operator Address() const;
/**
* \param address a polymorphic address
* \returns a new Mac16Address from the polymorphic address
@@ -77,6 +87,7 @@ class Mac16Address
* Mac16Address.
*/
static Mac16Address ConvertFrom(const Address& address);
/**
* \returns a new Address instance
*
@@ -89,6 +100,7 @@ class Mac16Address
* \returns true if the address matches, false otherwise.
*/
static bool IsMatchingType(const Address& address);
/**
* Allocate a new Mac16Address.
* \returns newly allocated mac16Address