jscdr

0.0.2 • Public • Published

jsDelivr License License

jscdr

A DDS-CDR encoder/decoder library in Javascript.

CDR stands for the O.M.G.'s Common Data Representation that is used in DDS (Data Distributed Service) implementations. It's specified by https://www.omg.org/spec/DDSI-RTPS/2.3/PDF (chapter 10) and https://www.omg.org/cgi-bin/doc?formal/02-06-51.

In the current version, this library only handles the basic types. It doesn't include an IDL compiler generating Javascript encoder/decoder for complex types.

Usage

Add the following to your HTML page:

<script src="https://cdn.jsdelivr.net/npm/jscdr@0.0.1/dist/index.umd.js"></script>

Assuming a DDS type is defined with the following IDL:

module HelloWorldData
{
  struct Msg
  {
    long userID;
    string message;
  };
  #pragma keylist Msg userID
};

The code to encode such type will be:

var m = Msg(1, "Hello World!");

var writer = new CDRWriter();
writer.writeInt32(m.userId);
writer.writeString(m.message);

// get the resulting dcodeIO.ByteBuffer
var byteBuffer = writer.buffer;

The code to decode such type will be:

// Get a dcodeIO.ByteBuffer of bytes to decode
var byteBuffer = ...;

CDRReader reader = new CDRReader(byteBuffer);
var userId = reader.readInt32();
var message = reader.readString();
var m = new HelloWorldData.Msg(userId, message);

Package Sidebar

Install

npm i jscdr

Weekly Downloads

2

Version

0.0.2

License

EPL-2.0 OR Apache-2.0

Unpacked Size

1.18 MB

Total Files

14

Last publish

Collaborators

  • julien.enoch