- encode
- decode
- getDefinition
- getDefinitions
- getNamespaces
- _pbjsJSON
- schema
- ProtobufDefinition
- ProtobufMessage
Create a valid Buffer of bytes that can be sent to DeviceOS, typically used with "Request" messages.
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, defaultnull
)
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
Create a JavaScript object by decoding a Buffer representing a protobuf message from DeviceOS; typically used with "Reply" messages"
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
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
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
Returns Array valid strings that can be passed to getDefinition(). Includes all Request/Reply style messages as well as non request messages and enums.
Returns Array valid dot prefixes to getDefinition() arguments (i.e. the "cellular" from "cellular".GetIccidRequest, etc)
Parsed JSON object generated via npm run build:json
; this is how we get the type id associated with
a given ctrl request
All of the interesting auto-generated Javascript objects from *.proto
files live in this definitions object
(which is keyed by protobuf message name)
Type: Object
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.
This is typedef describing the auto-generated code that pbjs generates
Type: Object