In encode methods, return a ptr_lib::shared_ptr<vector<unsigned char> >
diff --git a/ndn-cpp/ContentObject.hpp b/ndn-cpp/ContentObject.hpp
index 6bd5a80..794ef07 100644
--- a/ndn-cpp/ContentObject.hpp
+++ b/ndn-cpp/ContentObject.hpp
@@ -84,13 +84,13 @@
   
 class ContentObject {
 public:
-  void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) const 
+  ptr_lib::shared_ptr<std::vector<unsigned char> > encode(WireFormat &wireFormat) const 
   {
-    wireFormat.encodeContentObject(*this, output);
+    return wireFormat.encodeContentObject(*this);
   }
-  void encode(std::vector<unsigned char> &output) const 
+  ptr_lib::shared_ptr<std::vector<unsigned char> > encode() const 
   {
-    encode(output, BinaryXMLWireFormat::instance());
+    return encode(BinaryXMLWireFormat::instance());
   }
   void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) 
   {
diff --git a/ndn-cpp/Interest.hpp b/ndn-cpp/Interest.hpp
index 61d2510..76f3c17 100644
--- a/ndn-cpp/Interest.hpp
+++ b/ndn-cpp/Interest.hpp
@@ -129,13 +129,13 @@
   	construct();
   }
   
-  void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) const 
+  ptr_lib::shared_ptr<std::vector<unsigned char> > encode(WireFormat &wireFormat) const 
   {
-    wireFormat.encodeInterest(*this, output);
+    return wireFormat.encodeInterest(*this);
   }
-  void encode(std::vector<unsigned char> &output) const 
+  ptr_lib::shared_ptr<std::vector<unsigned char> > encode() const 
   {
-    encode(output, BinaryXMLWireFormat::instance());
+    return encode(BinaryXMLWireFormat::instance());
   }
   void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) 
   {
diff --git a/ndn-cpp/NDN.cpp b/ndn-cpp/NDN.cpp
index c25fff3..d41971e 100644
--- a/ndn-cpp/NDN.cpp
+++ b/ndn-cpp/NDN.cpp
@@ -16,14 +16,13 @@
 void NDN::expressInterest(const Name &name, const shared_ptr<Closure> &closure, const Interest *interestTemplate)
 {
   Interest interest(name);
-  vector<unsigned char> encoding;
-  interest.encode(encoding);  
+  shared_ptr<vector<unsigned char> > encoding = interest.encode();  
 
   // TODO: This should go in the PIT.
   tempClosure_ = closure;
   
   transport_->connect(*this);
-  transport_->send(&encoding[0], encoding.size());
+  transport_->send(*encoding);
 }
     
 void NDN::onReceivedElement(unsigned char *element, unsigned int elementLength)
diff --git a/ndn-cpp/encoding/BinaryXMLEncoder.hpp b/ndn-cpp/encoding/BinaryXMLEncoder.hpp
index 2ae5196..f31de46 100644
--- a/ndn-cpp/encoding/BinaryXMLEncoder.hpp
+++ b/ndn-cpp/encoding/BinaryXMLEncoder.hpp
@@ -7,6 +7,7 @@
 #define	NDN_BINARYXMLENCODER_HPP
 
 #include <vector>
+#include "../common.hpp"
 #include "../c/util/ndn_realloc.h"
 #include "../c/encoding/BinaryXMLEncoder.h"
 
@@ -27,12 +28,11 @@
   }
   
   /**
-   * Copy the encoded bytes to the end of the buffer.
-   * @param buffer a vector to receive the copy
+   * Return the output as a shared_ptr.
    */
-  void appendTo(std::vector<unsigned char> &buffer) 
+  ptr_lib::shared_ptr<std::vector<unsigned char> > getOutput() 
   {
-    buffer.insert(buffer.end(), output.array, output.array + offset);
+    return ptr_lib::shared_ptr<std::vector<unsigned char> >(new std::vector<unsigned char>(output.array, output.array + offset));
   }
 };
 
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
index 0c1f4d2..2faa4c3 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
@@ -18,7 +18,7 @@
 
 BinaryXMLWireFormat BinaryXMLWireFormat::instance_;
 
-void BinaryXMLWireFormat::encodeInterest(const Interest &interest, vector<unsigned char> &output) 
+ptr_lib::shared_ptr<vector<unsigned char> > BinaryXMLWireFormat::encodeInterest(const Interest &interest) 
 {
   struct ndn_NameComponent nameComponents[100];
   struct ndn_ExcludeEntry excludeEntries[100];
@@ -31,7 +31,7 @@
   BinaryXMLEncoder encoder;
   ndn_encodeBinaryXMLInterest(&interestStruct, &encoder);
      
-  encoder.appendTo(output);
+  return encoder.getOutput();
 }
 
 void BinaryXMLWireFormat::decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength)
@@ -51,7 +51,7 @@
   interest.set(interestStruct);
 }
 
-void BinaryXMLWireFormat::encodeContentObject(const ContentObject &contentObject, vector<unsigned char> &output) 
+ptr_lib::shared_ptr<vector<unsigned char> > BinaryXMLWireFormat::encodeContentObject(const ContentObject &contentObject) 
 {
   struct ndn_NameComponent nameComponents[100];
   struct ndn_ContentObject contentObjectStruct;
@@ -62,7 +62,7 @@
   BinaryXMLEncoder encoder;
   ndn_encodeBinaryXMLContentObject(&contentObjectStruct, &encoder);
      
-  encoder.appendTo(output);
+  return encoder.getOutput();
 }
 
 void BinaryXMLWireFormat::decodeContentObject(ContentObject &contentObject, const unsigned char *input, unsigned int inputLength)
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.hpp b/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
index d35660f..20ebacd 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
@@ -12,10 +12,10 @@
 
 class BinaryXMLWireFormat : public WireFormat {
 public:
-  virtual void encodeInterest(const Interest &interest, std::vector<unsigned char> &output);
+  virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeInterest(const Interest &interest);
   virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
 
-  virtual void encodeContentObject(const ContentObject &contentObject, std::vector<unsigned char> &output);
+  virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeContentObject(const ContentObject &contentObject);
   virtual void decodeContentObject(ContentObject &contentObject, const unsigned char *input, unsigned int inputLength);
   
   static BinaryXMLWireFormat &instance() { return instance_; }
diff --git a/ndn-cpp/encoding/WireFormat.cpp b/ndn-cpp/encoding/WireFormat.cpp
index 5d46241..238ce9c 100644
--- a/ndn-cpp/encoding/WireFormat.cpp
+++ b/ndn-cpp/encoding/WireFormat.cpp
@@ -9,7 +9,7 @@
 using namespace std;
 
 namespace ndn {
-void WireFormat::encodeInterest(const Interest &interest, vector<unsigned char> &output) 
+ptr_lib::shared_ptr<vector<unsigned char> > WireFormat::encodeInterest(const Interest &interest) 
 {
   throw logic_error("unimplemented");
 }
@@ -18,7 +18,7 @@
   throw logic_error("unimplemented");
 }
 
-void WireFormat::encodeContentObject(const ContentObject &contentObject, vector<unsigned char> &output) 
+ptr_lib::shared_ptr<vector<unsigned char> > WireFormat::encodeContentObject(const ContentObject &contentObject) 
 {
   throw logic_error("unimplemented");
 }
diff --git a/ndn-cpp/encoding/WireFormat.hpp b/ndn-cpp/encoding/WireFormat.hpp
index df532e9..1afe25f 100644
--- a/ndn-cpp/encoding/WireFormat.hpp
+++ b/ndn-cpp/encoding/WireFormat.hpp
@@ -6,6 +6,7 @@
 #ifndef NDN_WIREFORMAT_HPP
 #define	NDN_WIREFORMAT_HPP
 
+#include "../common.hpp"
 #include <vector>
 
 namespace ndn {
@@ -15,10 +16,10 @@
   
 class WireFormat {
 public:
-  virtual void encodeInterest(const Interest &interest, std::vector<unsigned char> &output);
+  virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeInterest(const Interest &interest);
   virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
 
-  virtual void encodeContentObject(const ContentObject &contentObject, std::vector<unsigned char> &output);
+  virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeContentObject(const ContentObject &contentObject);
   virtual void decodeContentObject(ContentObject &contentObject, const unsigned char *input, unsigned int inputLength);
 };
 
diff --git a/tests/test-encode-decode-ContentObject.cpp b/tests/test-encode-decode-ContentObject.cpp
index 852b2d0..665d097 100644
--- a/tests/test-encode-decode-ContentObject.cpp
+++ b/tests/test-encode-decode-ContentObject.cpp
@@ -74,12 +74,11 @@
     cout << "ContentObject timestamp " << timestamp.date().year() << "/" << timestamp.date().month() << "/" << timestamp.date().day() 
          << " " << timestamp.time_of_day().hours() << ":" << timestamp.time_of_day().minutes() << ":" << timestamp.time_of_day().seconds()  << endl;
     
-    vector<unsigned char> encoding;
-    contentObject.encode(encoding);
-    cout << "ContentObject encoding length " << encoding.size() << " vs. sizeof(ContentObject1) " << sizeof(ContentObject1) << endl;
+    ptr_lib::shared_ptr<vector<unsigned char> > encoding = contentObject.encode();
+    cout << "ContentObject encoding length " << encoding->size() << " vs. sizeof(ContentObject1) " << sizeof(ContentObject1) << endl;
     
     ContentObject reDecodedContentObject;
-    reDecodedContentObject.decode(encoding);
+    reDecodedContentObject.decode(*encoding);
     cout << "Re-decoded ContentObject name " << reDecodedContentObject.getName().to_uri() << endl;
     timestamp = UNIX_EPOCH_TIME + milliseconds(reDecodedContentObject.getSignedInfo().getTimestampMilliseconds());
     cout << "Re-decoded ContentObject timestamp " << timestamp.date().year() << "/" << timestamp.date().month() << "/" << timestamp.date().day() << endl;
diff --git a/tests/test-encode-decode-Interest.cpp b/tests/test-encode-decode-Interest.cpp
index d715c85..412f78e 100644
--- a/tests/test-encode-decode-Interest.cpp
+++ b/tests/test-encode-decode-Interest.cpp
@@ -44,12 +44,11 @@
     cout << "Interest excludeEntryCount " << interest.getExclude().getEntryCount() << endl;
     cout << "InterestLifetimeMilliseconds " << interest.getInterestLifetimeMilliseconds() << endl;
     
-    vector<unsigned char> encoding;
-    interest.encode(encoding);
-    cout << "Interest encoding length " << encoding.size() << " vs. sizeof(Interest1) " << sizeof(Interest1) << endl;
+    ptr_lib::shared_ptr<vector<unsigned char> > encoding = interest.encode();
+    cout << "Interest encoding length " << encoding->size() << " vs. sizeof(Interest1) " << sizeof(Interest1) << endl;
 
     Interest reDecodedInterest;
-    reDecodedInterest.decode(encoding);
+    reDecodedInterest.decode(*encoding);
     cout << "Re-decoded Interest name " << reDecodedInterest.getName().to_uri() << endl;
     cout << "Re-decoded Interest minSuffixComponents " << reDecodedInterest.getMinSuffixComponents() << endl;
     cout << "Re-decoded Interest publisherPublicKeyDigest length " << reDecodedInterest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() << endl;