Namespace: CommonStructures

Protocol.CommonStructures

Shared Common Structures

See:

Examples

Packaging the RC data struct:

function rcPack(payloadType, messageId, body) {
  // Simple reference of common structures.
  var common = Protocol.CommonStructures
    // Set header size = 1 byte(payload.messageId) or += 4 bytes(payload.dataSize)
    , headerSize = headerSize = body && 5 || 1
    // Get body struct size if has body struct.
    , bodySize = body && body.byteLength || 0
    // Merge and update the header of packet(common.payload + common.dataSize)
    , packet = extend(
      // Update payload type, message id and packet size.
      common.payload.update({
        // Payload type of packet.
          type: payloadType
        , messageSize: bodySize + headerSize
        // Message id of packet.
        , messageId: messageId
      }),
      // Append body size header if has body struct.
      body && common.dataSize.update({
          dataSize: bodySize
      })
    );

  // Create the struct of RC packet with body struct.
  return new Struct(extend(packet, body && body.struct));
}

// return a Struct of RC packet.
var packet = rcPack(220, 0, {
  channelId: 1,
  guid: 'abcdef0123'
});

Using Struct.JS:

// return a Struct of Process Item.
var item = new Struct({
  // typed 'unit32'
  count: 'uint32',
  // typed 'unit8' and default value is '1'
  state: ['uint8', 1],
  // vary of string, offset type is 'unit16' and length type is 'unit16'
  name: ['uint16', String, 'uint16'],
  // vary of string, offset type is 'unit16' and length type is 'unit8'
  package: ['uint16', String, 'uint8'],
  // vary of string and ignore length header, offset typed = 'unit16'
  version: ['uint16', String, 'uint16', false]
});

Members

compress Struct

The compress header

Properties:
Name Type Description
compress typed

uint64

Deprecated
  • 쓰이지 않는 해더

    dataSize Struct

    The data size of message

    Properties:
    Name Type Description
    dataSize typed

    uint32

    json Struct

    Shared header of JSON type

    Properties:
    Name Type Description
    json vary

    uint16

    media Struct

    Shared header of media files

    Properties:
    Name Type Description
    kind typed

    uint8

    id typed

    uint32

    path vary

    uint16[, uint16]

    mimeType vary

    uint16[, uint16]

    title vary

    uint16[, uint16]

    size typed

    uint64

    added typed

    uint32

    modified typed

    uint32

    Music Struct

    PayloadType ? MessageId ? UnionId 3

    Properties:
    Name Type Description
    track typed

    uint16

    played typed

    uint16

    album vary

    uint16[, uint16]

    albumId typed

    uint32

    artist vary

    uint16[, uint16]

    artistId typed

    uint32

    year vary

    uint16[, uint16]

    genre vary

    uint16[, uint16]

    duration typed

    uint32

    bookmark typed

    uint32

    payload Struct

    The payload of message

    Properties:
    Name Type Description
    type typed

    uint8

    messageSize typed

    uint32

    messageId typed

    uint8

    Photo Struct

    PayloadType ? MessageId ? UnionId 1

    Properties:
    Name Type Description
    width typed

    uint32

    height typed

    uint32

    latitude typed

    uint64

    longitude typed

    uint64

    orientation typed

    uint16

    groupId typed

    uint32

    Video Struct

    PayloadType ? MessageId ? UnionId 2

    Properties:
    Name Type Description
    width typed

    uint32

    height typed

    uint32

    latitude typed

    uint64

    longitude typed

    uint64

    duration typed

    uint32

    bookmark typed

    uint32

    comments powered by Disqus