entryToBencoded :: MonadIO m => Ptr C'BencodeEntry -> m Bencoded
entryToBencoded ePtr =
  liftIO $ bracket
  [CU.exp| VectorChar * { new std::vector<char>() } |]
  (\bufPtr -> [CU.exp| void { delete $(VectorChar * bufPtr)} |]) $
  \bufPtr ->
    alloca $ \clenPtr ->
    alloca $ \cstrPtr -> do
      [C.block| void {
          bencode(std::back_inserter(*$(VectorChar * bufPtr)), *$(entry * ePtr));
          *$(size_t * clenPtr) = $(VectorChar * bufPtr)->size();
          *$(char ** cstrPtr) = $(VectorChar * bufPtr)->data();
         }
      |]
      clen <- peek clenPtr
      cstr <- peek cstrPtr
      Bencoded <$> BS.packCStringLen (cstr, fromIntegral clen)
entryToBencoded :: MonadIO m => Ptr C'BencodeEntry -> m Bencoded
entryToBencoded ePtr =
  liftIO $ bracket
  [CU.exp| VectorChar * { new std::vector<char>() } |]
  (\bufPtr -> [CU.exp| void { delete $(VectorChar * bufPtr)} |]) $
  \bufPtr ->
    alloca $ \clenPtr ->
    alloca $ \cstrPtr -> do
      [C.block| void {
          bencode(std::back_inserter(*$(VectorChar * bufPtr)), *$(entry * ePtr));
          *$(size_t * clenPtr) = $(VectorChar * bufPtr)->size();
          *$(char ** cstrPtr) = $(VectorChar * bufPtr)->data();
         }
      |]
      clen <- peek clenPtr
      cstr <- peek cstrPtr
      Bencoded <$> BS.packCStringLen (cstr, fromIntegral clen)
entryToBencoded ePtr =
  liftIO $ bracket
  [CU.exp| VectorChar * { new std::vector<char>() } |]
  (\bufPtr -> [CU.exp| void { delete $(VectorChar * bufPtr)} |]) $
  \bufPtr ->
    alloca $ \clenPtr ->
    alloca $ \cstrPtr -> do
      [C.block| void {
          bencode(std::back_inserter(*$(VectorChar * bufPtr)), *$(entry * ePtr));
          *$(size_t * clenPtr) = $(VectorChar * bufPtr)->size();
          *$(char ** cstrPtr) = $(VectorChar * bufPtr)->data();
         }
      |]
      clen <- peek clenPtr
      cstr <- peek cstrPtr
      Bencoded <$> BS.packCStringLen (cstr, fromIntegral clen)