Comments (7)
Try master. should be fn<rdr,tag, field-count,name->map-ctor>
from fress.
can probably get rid of the name->map-ctor arg
from fress.
yeah without name->map-ctor arg would be awesome. And also if the record is not match could it be possible to return an custom object like your taggedObject?
from fress.
Can you explain your use case alittle bit for me? Are you trying to instantiate stuff before calling the record constructor? If so it may be better to read/write as custom types rather than records
from fress.
Good morning!
Sorry for the delayed response.
Best way to explain the case is with the following code:
(defrecord IncognitoTaggedLiteral [tag value])
(defn incognito-write-handlers [write-handlers]
{"record" (fn [w rec]
(let [{:keys [tag] :as r} (if (isa? (type rec) incognito.base.IncognitoTaggedLiteral)
(into {} rec)
(incognito-writer @write-handlers rec))]
(write-tag w "record" 2)
(write-object w (str tag))
(write-tag w "map" 1)
(beginClosedList w)
(doseq [[field value] r]
(write-object w field true)
(write-object w value))
(endList w)))})
(defn incognito-reader [read-handlers m]
(if (read-handlers (:tag m))
((read-handlers (:tag m)) (:value m))
(map->IncognitoTaggedLiteral m)))
(defn incognito-read-handlers [read-handlers]
{"record" (fn [rdr tag _]
(let [tag (read-object rdr)
value (read-object rdr)]
(incognito-reader @read-handlers
{:tag tag :value val})))})
(defrecord SomeRecord [f1 f2])
(def rec (SomeRecord. "field1" "field2"))
(def buf (fress.api/byte-stream))
(def writer (fress.api/create-writer buf :handlers (incognito-write-handlers (atom {'incognito.fressian.SomeRecord (fn [foo] (println "foos") (assoc foo :c "donkey"))}))))
(fress.api/write-object writer rec)
(fress.api/read buf :handlers (incognito-read-handlers (atom {})))
;read returns => #fress.reader.TaggedObject{:tag "record", :value #js ["incognito.fressian/SomeRecord" {:value {:f1 "field1", :c "donkey", :f2 "field2"}, :tag incognito.fressian/SomeRecord}]}
;it should return => #incognito.base.IncognitoTaggedLiteral{:tag incognito.fressian/SomeRecord, :value {:f1 "field1", :c "donkey", :f2 "field2"}}
The custom read-handler for "record" is somehow ignored. Sorry for the confusion. I hope the answer can help.
Best Regards F
from fress.
I had it set to look for :record, you are right it should have been a string
from fress.
Big thanks! Well done!
It's working! I think the issue can be closed.
Best Regards F
from fress.
Related Issues (6)
- Not working with CIDER 0.17.0 and nREPL 0.2.13 HOT 4
- Maven Upload Request HOT 1
- Unexpected behavior at reading a PersitentVector with record elements HOT 2
- Getting wrong return values from read-object function HOT 4
- Warning "References to the global RegExp object prevents optimization of regular expressions." HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fress.