MQTTPacket

Dependents:   MQTT

Fork of MQTTPacket by MQTT

Files at this revision

API Documentation at this revision

Comitter:
icraggs
Date:
Mon Apr 14 18:49:32 2014 +0000
Parent:
4:c502573c6016
Child:
6:68a06bea5429
Commit message:
Add a string comparison function

Changed in this revision

MQTTPacket.c Show annotated file Show diff for this revision Revisions of this file
MQTTPacket.h Show annotated file Show diff for this revision Revisions of this file
--- a/MQTTPacket.c	Fri Apr 11 23:44:15 2014 +0100
+++ b/MQTTPacket.c	Mon Apr 14 18:49:32 2014 +0000
@@ -249,6 +249,28 @@
 }
 
 
+int MQTTPacket_equals(MQTTString* a, char* bptr)
+{
+	int alen = 0,
+		blen = 0;
+	char *aptr;
+	
+	if (a->cstring)
+	{
+		aptr = a->cstring;
+		alen = strlen(a->cstring);
+	}
+	else
+	{
+		aptr = a->lenstring.data;
+		alen = a->lenstring.len;
+	}
+	blen = strlen(bptr);
+	
+	return (alen == blen) && (strncmp(aptr, bptr, alen) == 0);
+}
+
+
 /**
  * Helper function to read packet data from some source into a buffer
  * @param buf the buffer into which the packet will be serialized
@@ -282,4 +304,3 @@
 	return rc;
 }
 
-
--- a/MQTTPacket.h	Fri Apr 11 23:44:15 2014 +0100
+++ b/MQTTPacket.h	Mon Apr 14 18:49:32 2014 +0000
@@ -85,6 +85,7 @@
 int MQTTDeserialize_ack(int* type, int* dup, int* packetid, char* buf, int buflen);
 
 int MQTTPacket_len(int rem_len);
+int MQTTPacket_equals(MQTTString* a, char* b);
 
 int MQTTPacket_encode(char* buf, int length);
 int MQTTPacket_decode(int (*getcharfn)(char*, int), int* value);