Sfoglia il codice sorgente

add pack_required_field(datagram, ...)

David Rose 21 anni fa
parent
commit
215d97d75f

+ 28 - 0
direct/src/dcparser/dcClass.cxx

@@ -459,6 +459,34 @@ direct_update(PyObject *distobj, const string &field_name,
 }
 #endif  // HAVE_PYTHON
 
+////////////////////////////////////////////////////////////////////
+//     Function: DCClass::pack_required_field
+//       Access: Published
+//  Description: Looks up the current value of the indicated field by
+//               calling the appropriate get*() function, then packs
+//               that value into the datagram.  This field is
+//               presumably either a required field or a specified
+//               optional field, and we are building up a datagram for
+//               the generate-with-required message.
+//
+//               Returns true on success, false on failure.
+////////////////////////////////////////////////////////////////////
+bool DCClass::
+pack_required_field(Datagram &datagram, PyObject *distobj, 
+                    const DCField *field) const {
+  DCPacker packer;
+  packer.begin_pack(field);
+  if (!pack_required_field(packer, distobj, field)) {
+    return false;
+  }
+  if (!packer.end_pack()) {
+    return false;
+  }
+
+  datagram.append_data(packer.get_data(), packer.get_length());
+  return true;
+}
+
 #ifdef HAVE_PYTHON
 ////////////////////////////////////////////////////////////////////
 //     Function: DCClass::pack_required_field

+ 2 - 0
direct/src/dcparser/dcClass.h

@@ -74,6 +74,8 @@ PUBLISHED:
                      const string &value_blob);
   void direct_update(PyObject *distobj, const string &field_name, 
                      const Datagram &datagram);
+  bool pack_required_field(Datagram &datagram, PyObject *distobj, 
+                           const DCField *field) const;
   bool pack_required_field(DCPacker &packer, PyObject *distobj, 
                            const DCField *field) const;
 

+ 1 - 2
direct/src/dcparser/dcField.cxx

@@ -482,9 +482,8 @@ receive_update(DCPacker &packer, PyObject *distobj) const {
       PyObject *result = PyObject_CallObject(func, args);
       Py_XDECREF(result);
       Py_DECREF(func);
+      Py_DECREF(args);
     }
-    
-    Py_DECREF(args);
   }
 }
 #endif  // HAVE_PYTHON

+ 2 - 2
direct/src/dcparser/dcPacker.cxx

@@ -1033,7 +1033,7 @@ enquote_string(ostream &out, char quote_mark, const string &str) {
 
     } else if (!isprint(*pi)) {
       char buffer[10];
-      sprintf(buffer, "%02x", (unsigned int)(*pi));
+      sprintf(buffer, "%02x", (unsigned char)(*pi));
       out << "\\x" << buffer;
 
     } else {
@@ -1055,7 +1055,7 @@ output_hex_string(ostream &out, const string &str) {
        pi != str.end();
        ++pi) {
     char buffer[10];
-    sprintf(buffer, "%02x", (unsigned int)(*pi));
+    sprintf(buffer, "%02x", (unsigned char)(*pi));
     out << buffer;
   }
   out << '>';