Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest: message encoding #95

Closed
ricardopereira opened this issue Nov 30, 2015 · 4 comments
Closed

Rest: message encoding #95

ricardopereira opened this issue Nov 30, 2015 · 4 comments

Comments

@ricardopereira
Copy link
Contributor

I am implementing RSL4a.

Payloads must be binary, strings, or objects capable of JSON representation, or can be empty (omitted). Any other data type should not be permitted and an exception should be raised

Well, I dig into it and I found two places to setup the encoding (one for the payload and one for the client messages):

ARTChannel.payloadEncoder //I don't understand this property. Isn't supposed to encode the payload from the data type?
ARTRest.defaultEncoder //Message encoder

There are 4 payload encoders:

  • ARTBase64PayloadEncoder
  • ARTUtf8PayloadEncoder
  • ARTJsonPayloadEncoder
  • ARTCipherPayloadEncoder

and one ARTPayloadEncoderChain that allows "multi-encoding".

ARTChannel

When a ARTChannel is created it uses a private payload encoder [ARTPayload defaultPayloadEncoder] and I my opinion it is supposed to use the ARTRest.defaultEncoder. The private payload encoder (ARTChannel.payloadEncoder) is used to encode/decode the messages.

The [ARTPayload defaultPayloadEncoder] is an [ARTJsonPayloadEncoder instance] when the cipherParams is empty. If it is not then it uses a ARTPayloadEncoderChain with ARTJsonPayloadEncoder, ARTUtf8PayloadEncoder and finally ARTCipherPayloadEncoder.

ARTMessage

The ARTMessage when it is created it initialises the payload with an empty one where the encoding is nothing ([ARTPayload payloadWithPayload:data encoding:@""]).

ARTRest

The defaultEncoder is always an ARTJsonEncoder and it is used to publish a message ([rest.defaultEncoder encodeMessage:message]).

@ricardopereira
Copy link
Contributor Author

@mattheworiordan I need some orientation with this. I don't know what makes sense or not.

@ricardopereira
Copy link
Contributor Author

Message encoding

  • MessagePack (not implemented)
  • JSON

Payload encoding

  • Binary encoded as Base64
  • String encoded as JSON string
  • JSON encoded as JSON string (JSON Object or Array)
  • Int ? encoded as JSON string
  • Double ? encoded as JSON string
  • Empty ? no payload field

Payload encryption (after encoding)

  • AES 256
  • 128 CBC

Test with presence fixtures jsonCommon["post_apps"]["channels"][0]["presence"]

Messages received:

encoding: empty
expected: Bool
data: Optional(true) //Boolean

encoding: empty
expected: NSNumber
data: Optional(24) //Number

encoding: empty
expected: NSString
data: Optional(This is a string clientData payload) //UTF8

encoding: json/utf-8
expected: JSONObject
data: Optional({"example":{"json":"Object"}}) //JSON Object

encoding: empty
expected: JSONObject
data: Optional({ "test": "This is a JSONObject clientData payload"}) //Decoded

encoding: json/utf-8/cipher+aes-128-cbc/base64
expected: NSData
data: Optional(<1cee1c61 23fc2f26 cf6013d9 3c740eb6 e0f9df2a c3dd8577 341a1311 8061e14d 0dd505c7 6ed91fb0 37d3b292 9e2d016d>) //AES-128

@mattheworiordan
Copy link
Member

@ricardopereira lets chat tomorrow, probably easier to talk this through.

@tcard
Copy link
Contributor

tcard commented Feb 4, 2016

This has changed completely with #171. payloadEncoder and children are gone, now we have a single dataEncoder and the only state it has is the cipher params. Should I close?

maratal pushed a commit that referenced this issue Jul 19, 2023
Add Swift and Obj-C versions of the docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants