本文整理汇总了C#中DataSegment.Subsegment方法的典型用法代码示例。如果您正苦于以下问题:C# DataSegment.Subsegment方法的具体用法?C# DataSegment.Subsegment怎么用?C# DataSegment.Subsegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSegment
的用法示例。
在下文中一共展示了DataSegment.Subsegment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateInstance
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
int sourceEndpointIdentifierLength = data[Offset.SourceEndpointIdentifierLength];
int destinationEndpointIdentifierLength = data[Offset.DestinationEndpointIdentifierLength];
if (data.Length != OptionDataMinimumLength + sourceEndpointIdentifierLength + destinationEndpointIdentifierLength)
return null;
DataSegment sourceEndpointIdentifier = data.Subsegment(Offset.SourceEndpointIdentifier, sourceEndpointIdentifierLength);
int destinationEndpointIdentifierOffset = Offset.SourceEndpointIdentifier + sourceEndpointIdentifierLength;
DataSegment destinationEndpointIdentifier = data.Subsegment(destinationEndpointIdentifierOffset, destinationEndpointIdentifierLength);
return new IpV6OptionEndpointIdentification(sourceEndpointIdentifier, destinationEndpointIdentifier);
}
示例2: ParseData
internal static IpV6ExtensionHeaderRouting ParseData(IpV4Protocol nextHeader, DataSegment data)
{
if (data.Length < DataMinimumLength)
return null;
IpV6RoutingType routingType = (IpV6RoutingType)data[DataOffset.RoutingType];
byte segmentsLeft = data[DataOffset.SegmentsLeft];
DataSegment routingData = data.Subsegment(DataOffset.TypeSpecificData, data.Length - DataOffset.TypeSpecificData);
switch (routingType)
{
case IpV6RoutingType.SourceRoute:
return IpV6ExtensionHeaderRoutingSourceRoute.ParseRoutingData(nextHeader, segmentsLeft, routingData);
case IpV6RoutingType.Nimrod:
// Unused.
return null;
case IpV6RoutingType.Type2RoutingHeader:
return IpV6ExtensionHeaderRoutingHomeAddress.ParseRoutingData(nextHeader, segmentsLeft, routingData);
case IpV6RoutingType.RplSourceRouteHeader:
return IpV6ExtensionHeaderRoutingRpl.ParseRoutingData(nextHeader, segmentsLeft, routingData);
default:
return null;
}
}
示例3: CreateStandardInstance
private static IpV6ExtensionHeader CreateStandardInstance(IpV4Protocol nextHeader, DataSegment extensionHeaderData, out int numBytesRead)
{
numBytesRead = 0;
if (extensionHeaderData.Length < MinimumLength)
return null;
IpV4Protocol nextNextHeader = (IpV4Protocol)extensionHeaderData[Offset.NextHeader];
int length = (extensionHeaderData[Offset.HeaderExtensionLength] + 1) * 8;
if (extensionHeaderData.Length < length)
return null;
DataSegment data = extensionHeaderData.Subsegment(Offset.Data, length - Offset.Data);
numBytesRead = data.Length;
switch (nextHeader)
{
case IpV4Protocol.IpV6HopByHopOption: // 0
return IpV6ExtensionHeaderHopByHopOptions.ParseData(nextNextHeader, data);
case IpV4Protocol.IpV6Route: // 43
return IpV6ExtensionHeaderRouting.ParseData(nextNextHeader, data);
case IpV4Protocol.FragmentHeaderForIpV6: // 44
return IpV6ExtensionHeaderFragmentData.ParseData(nextNextHeader, data);
case IpV4Protocol.IpV6Opts: // 60
return IpV6ExtensionHeaderDestinationOptions.ParseData(nextNextHeader, data);
case IpV4Protocol.MobilityHeader: // 135
return IpV6ExtensionHeaderMobility.ParseData(nextNextHeader, data);
default:
throw new InvalidOperationException("Invalid nextHeader value" + nextHeader);
}
}
示例4: ParseMessageData
internal static IpV6ExtensionHeaderMobilityFastNeighborAdvertisement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
return null;
IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options));
return new IpV6ExtensionHeaderMobilityFastNeighborAdvertisement(nextHeader, checksum, options);
}
示例5: CreateInstance
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
DataSegment linkLayerIdentifier = data.Subsegment(Offset.LinkLayerIdentifier, data.Length - Offset.LinkLayerIdentifier);
return new IpV6MobilityOptionMobileNodeLinkLayerIdentifier(linkLayerIdentifier);
}
示例6: CreateInstance
internal override IpV6FlowIdentificationSubOption CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
IpV6FlowIdentificationTrafficSelectorFormat trafficSelectorFormat = (IpV6FlowIdentificationTrafficSelectorFormat)data[Offset.TrafficSelectorFormat];
DataSegment trafficSelector = data.Subsegment(Offset.TrafficSelector, data.Length - Offset.TrafficSelector);
return new IpV6FlowIdentificationSubOptionTrafficSelector(trafficSelectorFormat, trafficSelector);
}
示例7: CreateInstance
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
IpV6MobilityLinkLayerAddressCode code = (IpV6MobilityLinkLayerAddressCode)data[Offset.OptionCode];
DataSegment linkLayerAddress = data.Subsegment(Offset.LinkLayerAddress, data.Length - Offset.LinkLayerAddress);
return new IpV6MobilityOptionLinkLayerAddress(code, linkLayerAddress);
}
示例8: CreateInstance
internal override IpV6AccessNetworkIdentifierSubOption CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
IpV6AccessNetworkIdentifierOperatorIdentifierType identifierType = (IpV6AccessNetworkIdentifierOperatorIdentifierType)data[Offset.IdentifierType];
DataSegment identifier = data.Subsegment(Offset.Identifier, data.Length - Offset.Identifier);
return new IpV6AccessNetworkIdentifierSubOptionOperatorIdentifier(identifierType, identifier);
}
示例9: CreateInstance
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
uint vendorId = data.ReadUInt(Offset.VendorId, Endianity.Big);
byte subType = data[Offset.SubType];
DataSegment vendorSpecificData = data.Subsegment(Offset.Data, data.Length - Offset.Data);
return new IpV6MobilityOptionVendorSpecific(vendorId, subType, vendorSpecificData);
}
示例10: ReadString
internal static DataSegment ReadString(DataSegment data, ref int offset)
{
if (data.Length <= offset)
return null;
int stringLength = data[offset++];
if (data.Length < offset + stringLength)
return null;
DataSegment str = data.Subsegment(ref offset, stringLength);
return str;
}
示例11: CreateInstance
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
IpV6AuthenticationSubtype subtype = (IpV6AuthenticationSubtype)data[Offset.Subtype];
uint mobilitySecurityParameterIndex = data.ReadUInt(Offset.MobilitySecurityParameterIndex, Endianity.Big);
DataSegment authenticationData = data.Subsegment(Offset.AuthenticationData, data.Length - Offset.AuthenticationData);
return new IpV6MobilityOptionAuthentication(subtype, mobilitySecurityParameterIndex, authenticationData);
}
示例12: CreateInstance
internal override IpV6Option CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
int lineIdentificationLegnth = data[Offset.LineIdentificationLength];
if (data.Length != OptionDataMinimumLength + lineIdentificationLegnth)
return null;
DataSegment lineIdentification = data.Subsegment(Offset.LineIdentification, data.Length - Offset.LineIdentification);
return new IpV6OptionLineIdentificationDestination(lineIdentification);
}
示例13: CreateInstance
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
if (data.Length < OptionDataMinimumLength)
return null;
IpV6MobileNodeIdentifierSubtype subtype = (IpV6MobileNodeIdentifierSubtype)data[Offset.Subtype];
DataSegment identifier = data.Subsegment(Offset.Identifier, data.Length - Offset.Identifier);
if (subtype == IpV6MobileNodeIdentifierSubtype.NetworkAccessIdentifier && identifier.Length < MinNetworkAccessIdentifierLength)
return null;
return new IpV6MobilityOptionMobileNodeIdentifier(subtype, identifier);
}
示例14: CreateInstance
/// <summary>
/// Parses an option from the given data.
/// </summary>
/// <param name="data">The data to parse.</param>
/// <returns>The option if parsing was successful, null otherwise.</returns>
public IpV6Option CreateInstance(DataSegment data)
{
if (data == null)
throw new ArgumentNullException("data");
if (data.Length < OptionDataMinimumLength)
return null;
int lineIdentificationLegnth = data[Offset.LineIdentificationLength];
if (data.Length != OptionDataMinimumLength + lineIdentificationLegnth)
return null;
DataSegment lineIdentification = data.Subsegment(Offset.LineIdentification, data.Length - Offset.LineIdentification);
return new IpV6OptionLineIdentificationDestination(lineIdentification);
}
示例15: ParseRoutingData
internal static IpV6ExtensionHeaderRoutingRpl ParseRoutingData(IpV4Protocol nextHeader, byte segmentsLeft, DataSegment routingData)
{
if (routingData.Length < RoutingDataMinimumLength)
return null;
byte commonPrefixLengthForNonLastAddresses =
(byte)((routingData[RoutingDataOffset.CommonPrefixLengthForNonLastAddresses] & RoutingDataMask.CommonPrefixLengthForNonLastAddresses) >>
RoutingDataShift.CommonPrefixLengthForNonLastAddresses);
if (commonPrefixLengthForNonLastAddresses >= MaxCommonPrefixLength)
return null;
byte commonPrefixLengthForLastAddress =
(byte)(routingData[RoutingDataOffset.CommonPrefixLengthForLastAddress] & RoutingDataMask.CommonPrefixLengthForLastAddress);
if (commonPrefixLengthForLastAddress > MaxCommonPrefixLength)
return null;
byte padSize = (byte)((routingData[RoutingDataOffset.PadSize] & RoutingDataMask.PadSize) >> RoutingDataShift.PadSize);
if (padSize > MaxPadSize)
return null;
int numAddresses = (routingData.Length - RoutingDataOffset.Addresses - padSize - (IpV6Address.SizeOf - commonPrefixLengthForLastAddress)) /
(IpV6Address.SizeOf - commonPrefixLengthForNonLastAddresses) + 1;
if (numAddresses < 0)
return null;
IpV6Address[] addresses = new IpV6Address[numAddresses];
if (numAddresses > 0)
{
byte[] addressBytes = new byte[IpV6Address.SizeOf];
for (int i = 0; i < numAddresses - 1; ++i)
{
DataSegment addressSegment =
routingData.Subsegment(RoutingDataOffset.Addresses + i * (IpV6Address.SizeOf - commonPrefixLengthForNonLastAddresses),
commonPrefixLengthForNonLastAddresses);
addressSegment.Write(addressBytes, 0);
addresses[i] = addressBytes.ReadIpV6Address(0, Endianity.Big);
}
addressBytes = new byte[IpV6Address.SizeOf];
DataSegment lastAddressSegment =
routingData.Subsegment(RoutingDataOffset.Addresses + (numAddresses - 1) * (IpV6Address.SizeOf - commonPrefixLengthForNonLastAddresses),
commonPrefixLengthForLastAddress);
lastAddressSegment.Write(addressBytes, 0);
addresses[numAddresses - 1] = addressBytes.ReadIpV6Address(0, Endianity.Big);
}
return new IpV6ExtensionHeaderRoutingRpl(nextHeader, segmentsLeft, commonPrefixLengthForNonLastAddresses, commonPrefixLengthForLastAddress, padSize,
addresses);
}