Skip to content

Inconsistent encoding of Buffer values #1907

@bajtos

Description

@bajtos

Apparently we have two ways how to encode a buffer value:

  1. Method/callback arguments are encoded as { '$type': 'base64', '$data': 'MjM=' }, see see serialization and deserialization in strong-remoting
  2. Model properties are encoded as { type: 'Buffer', data: [50, 51] }, this is the behaviour of Node core's Buffer.prototype.toJSON

I am proposing to unify this behaviour and use only one encoding format. I think we should go with the format used by Node core, to make it easy to parse our output using JSON.parse.

In order to simplify the upgrade process, and also to support users that prefer Base64 (it uses less bandwidth), we can introduce a new flag in remoting-metadata that will instruct the response serializer to use Base64 encoding. The parser should always detect and support both base64 and array forms.

Example configuration:

{
  returns: { arg: 'data', type: 'Buffer', encoding: 'base64' }
}

Subtasks:

  • fix strong-remoting
  • fix iOS SDK

@raymondfeng @ritch @superkhau @STRML @fabien thoughts?
/cc @hideya

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions