New utility int GDU::get_size
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 29 Jun 2009 14:44:43 +0000 (16:44 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 29 Jun 2009 14:44:43 +0000 (16:44 +0200)
include/yazpp/gdu.h
src/gdu.cpp

index 1e253a8..5450a28 100644 (file)
@@ -42,6 +42,7 @@ namespace yazpp_1 {
         GDU &operator=(const GDU &);
         Z_GDU *get() const;
         void move_away_gdu(ODR dst, Z_GDU **gdu);
+        int get_size();
     private:
         void base(Z_GDU *gdu, ODR o);
         Z_GDU *m_gdu;
index 8df705e..10860cf 100644 (file)
@@ -46,6 +46,15 @@ void GDU::base(Z_GDU *gdu, ODR encode)
     odr_destroy(encode);
 }
 
+int GDU::get_size()
+{
+    int len = 0;
+    ODR encode = odr_createmem(ODR_ENCODE);
+    if (m_gdu && z_GDU(encode, &m_gdu, 0, "encode"))
+        odr_getbuf(encode, &len, 0);
+    odr_destroy(encode);
+    return len;
+}
 
 GDU &GDU::operator=(const GDU &g)
 {