Skip to content

Comments

Add support for floating-point numbers#1

Closed
afilini wants to merge 1 commit intoelast0ny:masterfrom
afilini:fix/support-f64-numbers
Closed

Add support for floating-point numbers#1
afilini wants to merge 1 commit intoelast0ny:masterfrom
afilini:fix/support-f64-numbers

Conversation

@afilini
Copy link

@afilini afilini commented Aug 16, 2020

This adds support for floating-point numbers or negative integers that are not caught by WampInteger.

@elast0ny
Copy link
Owner

Is this part of the spec somewhere ? Not sure if things changed since I last looked at it but I don't remember the spec supporting either of these types (floating & negative).

@afilini
Copy link
Author

afilini commented Aug 17, 2020

I'm honestly not sure about the spec, but I'm working on a project where one of the rpc calls returns a negative number in a JSON and it fails to deserialize. I guess if they can return it, then it's probably allowed by the spec (?)

@frol
Copy link
Collaborator

frol commented Aug 30, 2020

Specification explicitly says:

WAMP is a message based protocol that requires serialization of messages to octet sequences to be sent out on the wire.

A message serialization format is assumed that (at least) provides the following types:

  • integer (non-negative)
  • string (UTF-8 encoded Unicode)
  • bool
  • list
  • dict (with string keys)

WAMP itself only uses the above types, e.g. it does not use the JSON data types number (non-integer) and null. The application payloads transmitted by WAMP (e.g. in call arguments or event payloads) may use other types a concrete serialization format supports.

You should report the spec violation to the project that uses floating-point numbers on the protocol level.

@frol
Copy link
Collaborator

frol commented Sep 5, 2020

Well, I just realized that wamp-async-rs tries to deserialize user payload into WAMP-specific limited set of types, and indeed floats just fail. As per the cited part ("The application payloads transmitted by WAMP (e.g. in call arguments or event payloads) may use other types a concrete serialization format supports."), we should use Vec<serde_json::Value> (*) instead of WampList as WampArgs type.

(*) Well, given WAMP supports msgpack and batched protocols, we should may need to implement our own "Value" type, but I suggest we only focus on JSON for now, so serde_json::Value should be good. I will send a PR for this.

@frol
Copy link
Collaborator

frol commented Sep 5, 2020

Well, I just noticed that MsgPack is supported in wamp-async-rs, and my trivial attempt of using serde_json::Value does not work with it. I am investigating it I misconfigured the router. It works fine with serde_json::Value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants