protected override bool CanParseTemplateCodeImpl(BinaryIterator binaryIterator) { if (binaryIterator.Length > MaxBitLength) { return(false); } // Get header var header = binaryIterator.GetBitSetValue(HeaderBitLength); if (header == LegacyVersion) { return(false); } if (header != ExpectedTemplateType) { return(false); } var version = binaryIterator.GetBitSetValue(VersionBitLength); if (version != ExpectedVersion) { return(false); } return(true); }
public void CannotIteratePastThenEndOfTheString() { var iterator = new BinaryIterator("1111"); Assert.AreEqual(0, iterator.GetBitSetValue(6)); Assert.AreEqual(0, iterator.GetBitSetValue(1)); }
public void CanIterateOverBinaryString() { var iterator = new BinaryIterator("00000001001000110100"); Assert.AreEqual(0, iterator.GetBitSetValue(4)); Assert.AreEqual(8, iterator.GetBitSetValue(4)); Assert.AreEqual(4, iterator.GetBitSetValue(4)); Assert.AreEqual(12, iterator.GetBitSetValue(4)); Assert.AreEqual(2, iterator.GetBitSetValue(4)); }
/// <summary> /// Implementation of parsing the binary extracted from the template code /// </summary> /// <param name="binaryIterator">The binary iterator to help navigatee the binary string</param> /// <param name="templaceCode">The original template code</param> /// <returns>The resulting object with data from the template</returns> protected override NativeEquipmentBuild ParseBinary(BinaryIterator binaryIterator, string templaceCode) { var header = binaryIterator.GetBitSetValue(HeaderBitLength); if (header != LegacyVersion) { if (header != ExpectedTemplateType) { return(null); } var version = binaryIterator.GetBitSetValue(VersionBitLength); if (version != ExpectedVersion) { return(null); } } var bitsPerItemId = binaryIterator.GetBitSetValue(ItemIdBitLength); var bitsPerModifierId = binaryIterator.GetBitSetValue(ModifierIdBitLength); var itemCount = binaryIterator.GetBitSetValue(ItemCountBitLength); var result = new NativeEquipmentBuild(); for (var i = 0; i < itemCount; i++) { var item = new NativeEquipmentItem { SlotId = binaryIterator.GetBitSetValue(EquipmentSlotBitLength), ItemId = binaryIterator.GetBitSetValue(bitsPerItemId) }; var modifierCount = binaryIterator.GetBitSetValue(ModifierCountBitLength); item.ColorId = binaryIterator.GetBitSetValue(ItemColorBitLength); var modifiers = new List <int>(); for (var m = 0; m < modifierCount; m++) { modifiers.Add(binaryIterator.GetBitSetValue(bitsPerModifierId)); } item.ModifierIds = modifiers; result.Add(item); } result.TemplateCode = templaceCode; return(result); }
/// <summary> /// Implementation of parsing the binary extracted from the template code /// </summary> /// <param name="binaryIterator">The binary iterator to help navigatee the binary string</param> /// <param name="templateCode">The original template code</param> /// <returns>The resulting object with data from the template</returns> protected override NativeSkillBuild ParseBinary(BinaryIterator binaryIterator, string templateCode) { if (binaryIterator.Length > MaxBitLength) { return(null); } // Get header var header = binaryIterator.GetBitSetValue(HeaderBitLength); if (header != LegacyVersion) { if (header != ExpectedTemplateType) { return(null); } var version = binaryIterator.GetBitSetValue(VersionBitLength); if (version != ExpectedVersion) { return(null); } } var result = new NativeSkillBuild(); // Get professions var professionBitSpace = binaryIterator.GetBitSetValue(ProfessionSpaceBitLength); professionBitSpace = (professionBitSpace * 2) + ProfessionBitPadding; result.PrimaryProfessionId = binaryIterator.GetBitSetValue(professionBitSpace); result.SecondaryProfessionId = binaryIterator.GetBitSetValue(professionBitSpace); // Get attributes var attributeCount = binaryIterator.GetBitSetValue(AttributeCountBitLength); var attributeBitSpace = binaryIterator.GetBitSetValue(AttributeSpaceBitLength) + AttributeBitPadding; for (var index = 0; index != attributeCount; index++) { var attributeId = binaryIterator.GetBitSetValue(attributeBitSpace); var attributeValue = binaryIterator.GetBitSetValue(AttributeValueBitLength); result.AddAttribute(attributeId, attributeValue); } // Get skills var skillBitSpace = binaryIterator.GetBitSetValue(SkillSpaceBitLength) + SkillBitPadding; for (var index = 0; index != SkillCount; index++) { var skillId = binaryIterator.GetBitSetValue(skillBitSpace); result.AddSkill(skillId); } result.TemplateCode = templateCode; return(result); }
public void CannotAskForLessThanZeroBits() { var iterator = new BinaryIterator("1111"); iterator.GetBitSetValue(0); }