/// <summary> /// Parse a command by given the data /// </summary> /// <param name="data">Byte array value</param> /// <param name="index">The starting index</param> /// <returns>The size of the data structure</returns> private int ParseCommand(byte[] data, int index) { int cmdSize = 0; byte type = data[index++]; cmdSize++; // Push command if (type <= (byte)CommandType.PushCommand && type != (byte)CommandType.EndCommand) { GlobCnt globc = new GlobCnt { Type = CommandType.PushCommand }; byte[] cmdData = new byte[type]; Array.Copy(data, index, cmdData, 0, (int)type); index += (int)type; cmdSize += (int)type; globc.Command = new PushCommand(cmdData); this.globCntList.Add(globc); } else if (type == (byte)CommandType.PopCommand) { GlobCnt globc = new GlobCnt { Type = CommandType.PopCommand, Command = new PopCommand() }; this.globCntList.Add(globc); cmdSize = globc.Command.Size(); } else if (type == (byte)CommandType.RangCommand) { GlobCnt globc = new GlobCnt { Type = CommandType.RangCommand, Command = new RangeCommand() }; this.globCntList.Add(globc); cmdSize = globc.Command.Size(); } else if (type == (byte)CommandType.EndCommand) { // The End Command must occurs at the last if (index != data.Length) { throw new Exception("Not an valid IDSET"); } GlobCnt globc = new GlobCnt { Type = CommandType.EndCommand, Command = new EndCommand() }; this.globCntList.Add(globc); } else { throw new Exception("Currently, only support pushCommand"); } return(cmdSize); }
/// <summary> /// Generate a valid IDSETWithReplGuid structure /// </summary> /// <param name="bigData">The default value is false, if the value is true, this function will generate big data which length is greater than 4096</param> /// <returns>Return IDSETWithReplGuid</returns> protected IDSETWithReplGuid GenerateRandomValidIdset(bool bigData = false) { IDSETWithReplGuid idset = new IDSETWithReplGuid { ReplGuid = this.longTermIdFromIdResponse.LongTermId.DatabaseGuid, Globset = new Globset() }; List<GlobCnt> globCntList = new List<GlobCnt>(); GlobCnt globcnt = new GlobCnt(); // According to [MS-OXCFXICS] section 2.2.2.3.2. // In PushCommand, Command (1 byte): A value in the range "0x01" through "0x06". // CommonBytes (variable): Variable length byte array to be pushed onto the common byte stack. // The length of the byte array is equal to the Command value ("0x01" through "0x06"). // Here use 06 only PushCommand push = new PushCommand { Command = 0x06 }; System.Threading.Thread.Sleep(1); push.GenerateRandomCommandBytes(); // The first three byte must be zero push.CommandBytes[0] = 0x00; push.CommandBytes[1] = 0x00; push.CommandBytes[2] = 0x00; globcnt.Command = push; globCntList.Add(globcnt); if (bigData) { for (int i = 0; i < 1400; i++) { globcnt = new GlobCnt(); push = new PushCommand { Command = 0x06 }; System.Threading.Thread.Sleep(1); push.GenerateRandomCommandBytes(); // The first three byte must be zero push.CommandBytes[0] = 0x00; push.CommandBytes[1] = 0x00; push.CommandBytes[2] = 0x00; globcnt.Command = push; globCntList.Add(globcnt); } } GlobCnt globcnt1 = new GlobCnt(); // In EndCommand, the value of command is "0x00". EndCommand end = new EndCommand(); globcnt1.Command = end; globCntList.Add(globcnt1); idset.Globset.GlobCntList = globCntList; return idset; }
/// <summary> /// Parse a command by given the data /// </summary> /// <param name="data">Byte array value</param> /// <param name="index">The starting index</param> /// <returns>The size of the data structure</returns> private int ParseCommand(byte[] data, int index) { int cmdSize = 0; byte type = data[index++]; cmdSize++; // Push command if (type <= (byte)CommandType.PushCommand && type != (byte)CommandType.EndCommand) { GlobCnt globc = new GlobCnt { Type = CommandType.PushCommand }; byte[] cmdData = new byte[type]; Array.Copy(data, index, cmdData, 0, (int)type); index += (int)type; cmdSize += (int)type; globc.Command = new PushCommand(cmdData); this.globCntList.Add(globc); } else if (type == (byte)CommandType.PopCommand) { GlobCnt globc = new GlobCnt { Type = CommandType.PopCommand, Command = new PopCommand() }; this.globCntList.Add(globc); cmdSize = globc.Command.Size(); } else if (type == (byte)CommandType.RangCommand) { GlobCnt globc = new GlobCnt { Type = CommandType.RangCommand, Command = new RangeCommand() }; this.globCntList.Add(globc); cmdSize = globc.Command.Size(); } else if (type == (byte)CommandType.EndCommand) { // The End Command must occurs at the last if (index != data.Length) { throw new Exception("Not an valid IDSET"); } GlobCnt globc = new GlobCnt { Type = CommandType.EndCommand, Command = new EndCommand() }; this.globCntList.Add(globc); } else { throw new Exception("Currently, only support pushCommand"); } return cmdSize; }