0

I have a payload which is a lists of type bytes:

var payload : list of byte;
payload= {1;2;3;4;5;6};

var item1 :list of byte;
item = {3;4;5};


var item2 :list of byte;
item = {1;4};

I would like to implement a code that checks if a list is a sub-list of another. Using "if ..in.." doesn't quite work as it does not take into account the order of the items or if they appear successively or not. I want something that does the following:

  • if (item1 in payload) ...... should return TRUE. Items exist in payload in the same order.

  • if (item2 in payload) ...... should return FALSE because although each element in the list exists in the payload, but the item2 elements do not appear successively in the payload list.

Is there an easy way to achieve this? There must be a build -in function in specman for this.

Thanks

  • Actually, the order in `item2` is also the same (`1` is before `4`, like in `payload`). You possibly meant not just the order but also items that appear successively? Please clarify your question. – Yuri Tsoglin Nov 24 '15 at 07:57
  • @YuriTsoglin I think he means that he wants to check if a list is a sub-list of a bigger list. – Tudor Timi Nov 24 '15 at 08:44
  • @YuriTsoglin Yes, i would like to check if items they appear successively. Thanks – bobesfanchi Nov 24 '15 at 21:55

1 Answers1

1

The following code should work:

if (item.size()==0) {return TRUE};
for i from 0 to payload.size()-item.size() {
    if (item == payload[i..i+item.size()-1]) {
        return TRUE;
    };
};
return FALSE;

Note that this code is quite expensive memory-wise (the list[a..b] syntax creates a new list every time) so if you have memory considerations it should be modified.