Skip to content

Latest commit

 

History

History
194 lines (113 loc) · 6.01 KB

reference.md

File metadata and controls

194 lines (113 loc) · 6.01 KB

Table of Contents

encode

src/index.js:15-20

Create a valid Buffer of bytes that can be sent to DeviceOS, typically used with "Request" messages.

Parameters

  • protobufMessageNameOrMessage (string | ProtobufMessage) Protobuf message name or actual message object. See getDefinitions() to valid options.
  • protobufMessageData Object An object containing key data/code to encode & decode protobufjs messages from Device OS (optional, default null)

Examples

Encoding a request to get serial number

// returns a zero length Buffer because there is no properties for this message, just the option type_id
const buffer = DeviceOSProtobuf.encode('GetSerialNumberRequest');

Returns Buffer A Buffer of bytes representing a valid protobuf message that Device OS can interpret

decode

src/index.js:45-48

Create a JavaScript object by decoding a Buffer representing a protobuf message from DeviceOS; typically used with "Reply" messages"

Parameters

  • protobufMessageNameOrMessage (string | ProtobufMessage) Protobuf message name or actual message object. See getDefinitions() to valid options.
  • buffer Buffer Buffer from DeviceOS representing valid non-decoded Protobuf message

Examples

Decode a GetSerialNumberReply

// returns a Javascript object with .serial property
const object = DeviceOSProtobuf.decode('GetSerialNumberReply', buffer);
// shows the serial number as a string
console.log(object.serial);

Returns Object A JavaScript object with properties for each data item declared in the *.proto file

getDefinition

src/index.js:54-71

Parameters

  • protobufMessageName string Protobuf definition from *.proto files like "GetSerialNumberRequest". To access definitions in a namespace, prefix with "."

Returns ProtobufDefinition protobufDefinition An object containing code to encode & decode protobufjs messages from Device OS

getDefinitions

src/index.js:93-107

Returns Array valid strings that can be passed to getDefinition(). Includes all Request/Reply style messages as well as non request messages and enums.

getNamespaces

src/index.js:112-120

Returns Array valid dot prefixes to getDefinition() arguments (i.e. the "cellular" from "cellular".GetIccidRequest, etc)

_pbjsJSON

src/index.js:173-173

Parsed JSON object generated via npm run build:json; this is how we get the type id associated with a given ctrl request

schema

src/index.js:179-179

All of the interesting auto-generated Javascript objects from *.proto files live in this definitions object (which is keyed by protobuf message name)

ProtobufDefinition

src/index.js:93-107

Type: Object

Properties

  • message Function protobufjs generated Javascript function that includes encode and decode methods.
  • id (number | null) integer request ID of the message for "Request" protobuf definitions, null otherwise.
  • replyMessage (Function | null) The corresponding reply message to a given "Request" message, null otherwise.

ProtobufMessage

src/index.js:93-107

This is typedef describing the auto-generated code that pbjs generates

Type: Object

Properties