I am receining NSData in following way
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
char *ptr = (void *)[data bytes]; // set a pointer to the beginning of your data bytes
I am receiving the data then I need to compare this data with following array
char ch[3]={0x04,0x01,0X00};
becuase that data is coming from server, but data is dynamic i need to compare many such arrays with server data i found following method but it is static method but can no compare all arrays in following way
if(*ptr == 0x04) {
}
ptr++;
if(*ptr == 0x01) {
}
ptr++;
if(*ptr==0X00){
}
but i can not compare all array so please help how
i can compare
char *ptr = (void *)[data bytes];
with
char ch[3]={0x04,0x01,0X00};
please help
If you use an
NSDataobject for the data you are comparing (ch[3]), then you can use-[NSData rangeOfData:options:range:]to find the pattern.Here is an example