Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Add zmq_z85_decode support
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorbernard committed Aug 9, 2014
1 parent 67e6e8c commit 6b0d25d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/c++/zmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,15 @@ Java_org_zeromq_jni_ZMQ_zmq_1z85_1encode (JNIEnv *env, jclass c, jobject dest, j
JNIEXPORT jboolean JNICALL
Java_org_zeromq_jni_ZMQ_zmq_1z85_1decode (JNIEnv *env, jclass c, jbyteArray dest, jstring data)
{
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4,0,0)
jbyte *buf = env->GetByteArrayElements (dest, 0);
const char *encoded = env->GetStringUTFChars (data, NULL);
zmq_z85_decode((uint8_t *) buf, const_cast<char *>(encoded));
env->ReleaseByteArrayElements (dest, buf, 0);
return true;
#else
return false;
#endif
}

JNIEXPORT jboolean JNICALL
Expand Down
3 changes: 3 additions & 0 deletions src/test/clojure/zeromq/zmq.clj
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
(defn z85-encode [dest buf]
(ZMQ/zmq_z85_encode dest buf))

(defn z85-dencode [dest buf]
(ZMQ/zmq_z85_decode dest buf))

(defn socket [context socket-type]
(if-let [type (socket-types socket-type)]
(->ManagedSocket (ZMQ/zmq_socket (:address context) type))
Expand Down
6 changes: 6 additions & 0 deletions src/test/clojure/zeromq/zmq_tcp.clj
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@
char-buffer (CharBuffer/allocate 10)]
(zmq/z85-encode char-buffer raw-bytes)
(is (= "HelloWorld") (str char-buffer))))

(deftest z85-dencoding-test
(let [expected (byte-array (map unchecked-byte [0x86 0x4F 0xD2 0x6F 0xB5 0x59 0xF7 0x5B]))
dest (byte-array 8)]
(zmq/z85-dencode dest "HelloWorld")
(is (java.util.Arrays/equals expected dest))))

0 comments on commit 6b0d25d

Please sign in to comment.