本文整理汇总了C++中Tlv::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ Tlv::GetType方法的具体用法?C++ Tlv::GetType怎么用?C++ Tlv::GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tlv
的用法示例。
在下文中一共展示了Tlv::GetType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetOffset
ThreadError Tlv::GetOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
{
ThreadError error = kThreadError_Parse;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset < end)
{
aMessage.Read(offset, sizeof(Tlv), &tlv);
// skip extended TLV
if (tlv.GetLength() == kExtendedLength)
{
uint16_t length = 0;
offset += sizeof(tlv);
aMessage.Read(offset, sizeof(length), &length);
offset += sizeof(length) + HostSwap16(length);
}
else if (tlv.GetType() == aType && (offset + sizeof(tlv) + tlv.GetLength()) <= end)
{
aOffset = offset;
ExitNow(error = kThreadError_None);
}
else
{
offset += sizeof(tlv) + tlv.GetLength();
}
}
exit:
return error;
}
示例2: Set
otError Dataset::Set(const Tlv &aTlv)
{
otError error = OT_ERROR_NONE;
uint16_t bytesAvailable = sizeof(mTlvs) - mLength;
Tlv * old = Get(aTlv.GetType());
if (old != NULL)
{
bytesAvailable += sizeof(Tlv) + old->GetLength();
}
VerifyOrExit(sizeof(Tlv) + aTlv.GetLength() <= bytesAvailable, error = OT_ERROR_NO_BUFS);
// remove old TLV
if (old != NULL)
{
Remove(reinterpret_cast<uint8_t *>(old), sizeof(Tlv) + old->GetLength());
}
// add new TLV
memcpy(mTlvs + mLength, &aTlv, sizeof(Tlv) + aTlv.GetLength());
mLength += sizeof(Tlv) + aTlv.GetLength();
mUpdateTime = TimerMilli::GetNow();
exit:
return error;
}
示例3: IsValid
bool Tlv::IsValid(const Tlv &aTlv)
{
bool rval = true;
switch (aTlv.GetType())
{
case Tlv::kChannel:
rval = static_cast<const ChannelTlv &>(aTlv).IsValid();
break;
case Tlv::kPanId:
rval = static_cast<const PanIdTlv &>(aTlv).IsValid();
break;
case Tlv::kExtendedPanId:
rval = static_cast<const ExtendedPanIdTlv &>(aTlv).IsValid();
break;
case Tlv::kNetworkName:
rval = static_cast<const NetworkNameTlv &>(aTlv).IsValid();
break;
case Tlv::kNetworkMasterKey:
rval = static_cast<const NetworkMasterKeyTlv &>(aTlv).IsValid();
break;
case Tlv::kPSKc:
rval = static_cast<const PSKcTlv &>(aTlv).IsValid();
break;
case Tlv::kMeshLocalPrefix:
rval = static_cast<const MeshLocalPrefixTlv &>(aTlv).IsValid();
break;
case Tlv::kSecurityPolicy:
rval = static_cast<const SecurityPolicyTlv &>(aTlv).IsValid();
break;
default:
break;
}
return rval;
}
示例4: while
Tlv *Dataset::Get(Tlv::Type aType)
{
Tlv *cur = reinterpret_cast<Tlv *>(mTlvs);
Tlv *end = reinterpret_cast<Tlv *>(mTlvs + mLength);
Tlv *rval = NULL;
while (cur < end)
{
if (cur->GetType() == aType)
{
ExitNow(rval = cur);
}
cur = cur->GetNext();
}
exit:
return rval;
}
示例5: GetOffset
otError Tlv::GetOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
{
otError error = OT_ERROR_NOT_FOUND;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset + sizeof(tlv) <= end)
{
uint32_t length = sizeof(tlv);
aMessage.Read(offset, sizeof(tlv), &tlv);
if (tlv.GetLength() != kExtendedLength)
{
length += tlv.GetLength();
}
else
{
uint16_t extLength;
VerifyOrExit(sizeof(extLength) == aMessage.Read(offset + sizeof(tlv), sizeof(extLength), &extLength));
length += sizeof(extLength) + HostSwap16(extLength);
}
VerifyOrExit(offset + length <= end);
if (tlv.GetType() == aType)
{
aOffset = offset;
ExitNow(error = OT_ERROR_NONE);
}
offset += static_cast<uint16_t>(length);
}
exit:
return error;
}
示例6: GetValueOffset
otError Tlv::GetValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset, uint16_t &aLength)
{
otError error = OT_ERROR_NOT_FOUND;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset + sizeof(tlv) <= end)
{
uint16_t length;
aMessage.Read(offset, sizeof(tlv), &tlv);
offset += sizeof(tlv);
length = tlv.GetLength();
if (length == kExtendedLength)
{
VerifyOrExit(offset + sizeof(length) <= end);
aMessage.Read(offset, sizeof(length), &length);
offset += sizeof(length);
length = HostSwap16(length);
}
VerifyOrExit(length <= end - offset);
if (tlv.GetType() == aType)
{
aOffset = offset;
aLength = length;
ExitNow(error = OT_ERROR_NONE);
}
offset += length;
}
exit:
return error;
}
示例7: Get
void DatasetManager::Get(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
Tlv tlv;
uint16_t offset = aMessage.GetOffset();
uint8_t tlvs[Dataset::kMaxSize];
uint8_t length = 0;
while (offset < aMessage.GetLength())
{
aMessage.Read(offset, sizeof(tlv), &tlv);
if (tlv.GetType() == Tlv::kGet)
{
length = tlv.GetLength();
aMessage.Read(offset + sizeof(Tlv), length, tlvs);
break;
}
offset += sizeof(tlv) + tlv.GetLength();
}
SendGetResponse(aHeader, aMessageInfo, tlvs, length);
}
示例8: GetOffset
ThreadError Tlv::GetOffset(const Message &aMessage, Type aType, uint16_t &aOffset)
{
ThreadError error = kThreadError_Parse;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset < end)
{
aMessage.Read(offset, sizeof(Tlv), &tlv);
if (tlv.GetType() == aType && (offset + sizeof(tlv) + tlv.GetLength()) <= end)
{
aOffset = offset;
ExitNow(error = kThreadError_None);
}
offset += sizeof(tlv) + tlv.GetLength();
}
exit:
return error;
}
示例9: GetValueOffset
ThreadError Tlv::GetValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset, uint16_t &aLength)
{
ThreadError error = kThreadError_Parse;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
while (offset < end)
{
Tlv tlv;
uint16_t length;
aMessage.Read(offset, sizeof(tlv), &tlv);
offset += sizeof(tlv);
length = tlv.GetLength();
if (length == kExtendedLength)
{
aMessage.Read(offset, sizeof(length), &length);
offset += sizeof(length);
length = HostSwap16(length);
}
if (tlv.GetType() == aType)
{
aOffset = offset;
aLength = length;
ExitNow(error = kThreadError_None);
}
offset += length;
}
exit:
return error;
}
示例10: switch
IpcsClassifierRecord::IpcsClassifierRecord (Tlv tlv)
{
NS_ASSERT_MSG (tlv.GetType () == CsParamVectorTlvValue::Packet_Classification_Rule, "Invalid TLV");
ClassificationRuleVectorTlvValue* rules = ((ClassificationRuleVectorTlvValue*)(tlv.PeekValue ()));
m_priority = 0;
m_index = 0;
m_tosLow = 0;
m_tosHigh = 0;
m_tosMask = 0;
m_cid = 0;
for (std::vector<Tlv*>::const_iterator iter = rules->Begin (); iter != rules->End (); ++iter)
{
switch ((*iter)->GetType ())
{
case ClassificationRuleVectorTlvValue::Priority:
{
m_priority = ((U8TlvValue*)((*iter)->PeekValue ()))->GetValue ();
break;
}
case ClassificationRuleVectorTlvValue::ToS:
{
NS_FATAL_ERROR ("ToS Not implemented-- please implement and contribute a patch");
break;
}
case ClassificationRuleVectorTlvValue::Protocol:
{
ProtocolTlvValue * list = (ProtocolTlvValue *)(*iter)->PeekValue ();
for (std::vector<uint8_t>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
{
AddProtocol (*iter2);
}
break;
}
case ClassificationRuleVectorTlvValue::IP_src:
{
Ipv4AddressTlvValue * list = (Ipv4AddressTlvValue *)(*iter)->PeekValue ();
for (std::vector<Ipv4AddressTlvValue::ipv4Addr>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
{
AddSrcAddr ((*iter2).Address, (*iter2).Mask);
}
break;
}
case ClassificationRuleVectorTlvValue::IP_dst:
{
Ipv4AddressTlvValue * list = (Ipv4AddressTlvValue *)(*iter)->PeekValue ();
for (std::vector<Ipv4AddressTlvValue::ipv4Addr>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
{
AddDstAddr ((*iter2).Address, (*iter2).Mask);
}
break;
}
case ClassificationRuleVectorTlvValue::Port_src:
{
PortRangeTlvValue * list = (PortRangeTlvValue *)(*iter)->PeekValue ();
for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
{
AddSrcPortRange ((*iter2).PortLow, (*iter2).PortHigh);
}
break;
}
case ClassificationRuleVectorTlvValue::Port_dst:
{
PortRangeTlvValue * list = (PortRangeTlvValue *)(*iter)->PeekValue ();
for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
{
AddDstPortRange ((*iter2).PortLow, (*iter2).PortHigh);
}
break;
}
case ClassificationRuleVectorTlvValue::Index:
{
m_index = ((U16TlvValue*)((*iter)->PeekValue ()))->GetValue ();
break;
}
}
}
}