Permalink
Browse files

reposition marshaling code

  • Loading branch information...
1 parent 1187b14 commit d95f78b4b2a65247986d160e5dcb80a94e9e01c1 @videlalvaro committed Aug 14, 2010
Showing with 35 additions and 37 deletions.
  1. +35 −37 src/closerl/core.clj
View
@@ -21,7 +21,41 @@
OtpErlangList
OtpErlangTuple)))
-;; OtpNode wrapper
+;; Marshalling
+;; Based on trixx
+(defn parse-integer [s]
+ (try (Integer/parseInt s)
+ (catch NumberFormatException nfe 0)))
+
+(defmulti otp-value class)
+
+(defmethod otp-value OtpErlangBoolean [o] (.booleanValue o))
+(defmethod otp-value OtpErlangAtom [o] (.atomValue o))
+
+(defmethod otp-value OtpErlangBinary [o] (String. (.binaryValue o)))
+
+(defmethod otp-value OtpErlangChar [o] (parse-integer (str o)))
+(defmethod otp-value OtpErlangByte [o] (parse-integer (str o)))
+(defmethod otp-value OtpErlangShort [o] (parse-integer (str o)))
+(defmethod otp-value OtpErlangUShort [o] (parse-integer (str o)))
+(defmethod otp-value OtpErlangInt [o] (parse-integer (str o)))
+(defmethod otp-value OtpErlangUInt [o] (parse-integer (str o)))
+(defmethod otp-value OtpErlangLong [o]
+ (if (.isLong o)
+ (.longValue o)
+ (.bigIntegerValue o)))
+(defmethod otp-value OtpErlangFloat [o] (float (.floatValue o)))
+(defmethod otp-value OtpErlangDouble [o] (float (.floatValue o)))
+(defmethod otp-value OtpErlangString [o] (str (.stringValue o)))
+(defmethod otp-value OtpErlangList [o] (with-meta (map otp-value (.elements o)) {:otp-type "List"}))
+(defmethod otp-value OtpErlangTuple [o] (with-meta (map otp-value (.elements o)) {:otp-type "Tuple"}))
+(defmethod otp-value nil [o] "")
+(defmethod otp-value OtpErlangObject [o] o)
+
+(defmulti as-seq class)
+(defmethod as-seq OtpErlangList [o] (seq (.elements o)))
+(defmethod as-seq OtpErlangTuple [o] (seq (.elements o)))
+
(defn otp-node
"Creates an OtpNode"
[node-name]
@@ -105,42 +139,6 @@
(.sendRPC connection m f a)
(otp-value (.receiveRPC connection))))
-;; Marshalling
-;; Based on trixx
-(defn parse-integer [s]
- (try (Integer/parseInt s)
- (catch NumberFormatException nfe 0)))
-
-(defmulti otp-value class)
-
-(defmethod otp-value OtpErlangBoolean [o] (.booleanValue o))
-(defmethod otp-value OtpErlangAtom [o] (.atomValue o))
-
-(defmethod otp-value OtpErlangBinary [o] (String. (.binaryValue o)))
-
-(defmethod otp-value OtpErlangChar [o] (parse-integer (str o)))
-(defmethod otp-value OtpErlangByte [o] (parse-integer (str o)))
-(defmethod otp-value OtpErlangShort [o] (parse-integer (str o)))
-(defmethod otp-value OtpErlangUShort [o] (parse-integer (str o)))
-(defmethod otp-value OtpErlangInt [o] (parse-integer (str o)))
-(defmethod otp-value OtpErlangUInt [o] (parse-integer (str o)))
-(defmethod otp-value OtpErlangLong [o]
- (if (.isLong o)
- (.longValue o)
- (.bigIntegerValue o)))
-(defmethod otp-value OtpErlangFloat [o] (float (.floatValue o)))
-(defmethod otp-value OtpErlangDouble [o] (float (.floatValue o)))
-(defmethod otp-value OtpErlangString [o] (str (.stringValue o)))
-(defmethod otp-value OtpErlangList [o] (with-meta (map otp-value (.elements o)) {:otp-type "List"}))
-(defmethod otp-value OtpErlangTuple [o] (with-meta (map otp-value (.elements o)) {:otp-type "Tuple"}))
-(defmethod otp-value nil [o] "")
-(defmethod otp-value OtpErlangObject [o] o)
-
-(defmulti as-seq class)
-(defmethod as-seq OtpErlangList [o] (seq (.elements o)))
-(defmethod as-seq OtpErlangTuple [o] (seq (.elements o)))
-
-
;;Clojure to OtpErlang coercion
(defn otp-double [v] (OtpErlangDouble. (double v)))

0 comments on commit d95f78b

Please sign in to comment.