Created
December 2, 2011 23:05
-
-
Save sritchie/1425255 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From c6d4838a4f1a8a261597c1885e8e92f19c4e9077 Mon Sep 17 00:00:00 2001 | |
From: Sam Ritchie <sritchie09@gmail.com> | |
Date: Fri, 2 Dec 2011 14:53:31 -0800 | |
Subject: [PATCH] Added default Kryo behavior to kryo-extend multimethod. | |
The current implementation doesn't necessarily allow `setRegistrationOptional` | |
to behave as expected (where unknown java classes are serialized using the FieldSerializer.) | |
This commit implements Kryo's default behavior as a separate function, `register-generic`, | |
and adds a default dispatch method to kryo-extend that calls `register-generic` if no custom | |
serialization made it. | |
--- | |
src/carbonite/api.clj | 11 +++++++++++ | |
1 files changed, 11 insertions(+), 0 deletions(-) | |
diff --git a/src/carbonite/api.clj b/src/carbonite/api.clj | |
index 20ad221..ec9a061 100644 | |
--- a/src/carbonite/api.clj | |
+++ b/src/carbonite/api.clj | |
@@ -13,9 +13,20 @@ | |
(.register registry klass serializer)) | |
registry) | |
+(defn register-generic | |
+ "Default behavior of Kryo's handleUnregisteredClass method." | |
+ [klass ^Kryo registry] | |
+ (let [serializer (.newSerializer registry klass)] | |
+ (.register registry klass serializer true))) | |
+ | |
;; first item *is* the class of the unregistered object type | |
(defmulti kryo-extend (fn [klass registry] klass)) | |
+;; kryo-extend defaults to standard behavior. | |
+(defmethod kryo-extend :default | |
+ [klass registry] | |
+ (register-generic klass registry)) | |
+ | |
(defn new-registry | |
"Create a new Kryo registry that supports unregistered classes and defers to the | |
kryo-extend multimethod if an unhandled Class serializer is requested." | |
-- | |
1.7.4.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment