Base protocol codec for comm::Engine. Supported retransmissions
[anna.git] / source / diameter / codec / functions.cpp
index 3e8ce1f..a58372d 100644 (file)
@@ -80,14 +80,34 @@ anna::diameter::CommandId functions::getCommandId(const anna::DataBlock & db) th
   return (anna::diameter::CommandId(code, (flags & Message::RBitMask) != 0x00));
 }
 
-
-bool functions::isRequest(const anna::DataBlock & db) throw(anna::RuntimeException) {
+bool functions::requestBit(const anna::DataBlock & db) throw(anna::RuntimeException) {
   if(db.getSize() < Message::HeaderLength)
     throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
 
   return (((db.getData())[4] & Message::RBitMask) != 0x00);
 }
 
+bool functions::proxiableBit(const anna::DataBlock & db) throw(anna::RuntimeException) {
+  if(db.getSize() < Message::HeaderLength)
+    throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
+
+  return (((db.getData())[4] & Message::PBitMask) != 0x00);
+}
+
+bool functions::errorBit(const anna::DataBlock & db) throw(anna::RuntimeException) {
+  if(db.getSize() < Message::HeaderLength)
+    throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
+
+  return (((db.getData())[4] & Message::EBitMask) != 0x00);
+}
+
+bool functions::potentiallyReTransmittedMessageBit(const anna::DataBlock & db) throw(anna::RuntimeException) {
+  if(db.getSize() < Message::HeaderLength)
+    throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
+
+  return (((db.getData())[4] & Message::TBitMask) != 0x00);
+}
+
 anna::diameter::ApplicationId functions::getApplicationId(const anna::DataBlock & db) throw(anna::RuntimeException) {
   if(db.getSize() < Message::HeaderLength)
     throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
@@ -279,4 +299,15 @@ void functions::setEndToEnd(anna::DataBlock & db, diameter::EndToEnd ete) throw(
   memcpy((char *)(db.getData() + 16), source, 4);
 }
 
+void functions::setPotentiallyReTransmittedMessageBit(const anna::DataBlock & db, bool activate) throw(anna::RuntimeException) {
+  if(db.getSize() < Message::HeaderLength) {
+    throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
+  }
+
+  static char flags[1];
+  flags[0] = *(db.getData() + 4);
+  if(activate) flags[0] |= Message::TBitMask; else flags[0] &= (~Message::TBitMask);
+  memcpy((char *)(db.getData() + 4), flags, 1);
+}
+