Coder Social home page Coder Social logo

fressian-cljs's Introduction

fressian-cljs Build Status

Read and write fressian data by clojurescript.

Installation

Add the following to your project.clj

[net.unit8/fressian-cljs "0.1.0"]

Usage

Fressian-cljs uses ArrayBuffer to read/write fressian objects.

(ns myapp
  (:require [fressian-cljs.core :as fress])

(let [connection (js/WebSocket. "ws://websocket-host")]
  (set! connection -onmessage #(println (fress/read %)))
  (.send connection (fress/write {:a 1 :b 2})))

License

Copyright (C) 2014 kawasima

Distributed under the Eclipse Public License, the same as Clojure.

fressian-cljs's People

Contributors

jarohen avatar kawasima avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fressian-cljs's Issues

Error compiling

[net.unit8/fressian-cljs "0.1.0"]

(ns datascript-test.core
  (:require [fressian-cljs.core :as fress]))

(fress/write {:hi "there"})

Invalid :refer, var fressian-cljs.fns/lookup does not exist

Endian issue?

I noticed that when I send data from a backend server using data.fressian (https://github.com/clojure/data.fressian) over a websocket to the browser, fressian-cljs is deserializing decimal numbers incorrectly. Strings, integers, and keywords come through fine though.

I'm guessing this may be an endian issue. data.fressian serializes data in Java in big-endian format, but fressian-cljs uses js ArrayBuffer to deserialize into, and ArrayBuffer will use the machine endianness, which for me is little-endian (Intel).

Perhaps DataView could be applied to solve this issue? https://developer.mozilla.org/en-US/docs/Web/API/DataView

WebSocket needs arraybuffer binaryType

If I write binary fressian from the server to the host then this only works if the websocket has been configured to deliver messages as ArrayBuffer objects, since by default they arrive as Blob objects.

Doing this:

(set! (.-binaryType web-socket) "arraybuffer")

Fixed the problem.

I saw that you have an unimplemented method to handle reading js/Blob, but I don't think that will work with the same synchronous interface you've defined for reading arrays. Reading a Blob into an ArrayBuffer is asynchronous, so you would have to call a callback or write onto a channel to hand back the result.

Thanks for writing this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.