public Deserialize ( byte buffer ) : uint | ||
buffer | byte | Byte array contain data of a Restriction instance. |
리턴 | uint |
public uint Deserialize(byte[] buffer)
{
this.NamedPropertyInformation = new NamedPropertyInfo();
uint namedPropInfoLength = this.NamedPropertyInformation.Deserialize(buffer);
BufferReader bufferReader = new BufferReader(buffer);
byte[] tmpArray = bufferReader.ReadBytes(namedPropInfoLength, (uint)(buffer.Length - namedPropInfoLength));
RestrictionType restrictionType = (RestrictionType)tmpArray[0];
switch (restrictionType)
{
case RestrictionType.AndRestriction:
this.RuleRestriction = new AndRestriction(this.CountType);
break;
case RestrictionType.BitMaskRestriction:
this.RuleRestriction = new BitMaskRestriction();
break;
case RestrictionType.CommentRestriction:
this.RuleRestriction = new CommentRestriction(this.CountType);
break;
case RestrictionType.ComparePropertiesRestriction:
this.RuleRestriction = new ComparePropertiesRestriction();
break;
case RestrictionType.ContentRestriction:
this.RuleRestriction = new ContentRestriction();
break;
case RestrictionType.CountRestriction:
this.RuleRestriction = new CountRestriction(this.CountType);
break;
case RestrictionType.ExistRestriction:
this.RuleRestriction = new ExistRestriction();
break;
case RestrictionType.NotRestriction:
this.RuleRestriction = new NotRestriction(this.CountType);
break;
case RestrictionType.OrRestriction:
this.RuleRestriction = new OrRestriction(this.CountType);
break;
case RestrictionType.PropertyRestriction:
this.RuleRestriction = new PropertyRestriction();
break;
case RestrictionType.SizeRestriction:
this.RuleRestriction = new SizeRestriction();
break;
case RestrictionType.SubObjectRestriction:
this.RuleRestriction = new SubObjectRestriction(this.CountType);
break;
}
uint totalLength = this.RuleRestriction.Deserialize(tmpArray);
totalLength += namedPropInfoLength;
return totalLength;
}
}
/// <summary> /// This method help to convert the property value, which is of variable bytes, to ExtendedRuleCondition structure. /// </summary> /// <param name="byteArray">The byte array to be converted.</param> /// <returns>Return the ExtendedRuleCondition structure.</returns> public static ExtendedRuleCondition PropertyValueConvertToExtendedRuleCondition(byte[] byteArray) { // The first 2 bytes of byteArray only indicates the total number of subsequent bytes, // byteArrayTobeConvert is the actual bytes used to convert to the ExtendedRuleCondition structure, // which should not include the first 2 bytes of byteArray. byte[] byteArrayTobeConvert = new byte[byteArray.Length - 2]; Array.Copy(byteArray, 2, byteArrayTobeConvert, 0, byteArray.Length - 2); // Deserialize the byte array value into the ExtendedRuleCondition structure. ExtendedRuleCondition extendedRuleCondition = new ExtendedRuleCondition(); extendedRuleCondition.Deserialize(byteArrayTobeConvert); return extendedRuleCondition; }