Question about custom js encoder


#1

What uses the custom javascript encoder?

I understand where the decoder is used but not positive about the encoder.

thanks,
-Eric


#2

As you’ve seen, the decoder receives a byte array and decodes it to a json object that you can see at the live data tab or an integration. The encoder just does the opposite: it receives a json object and encodes it to a bytes array that gets enqueued for a downlink. You may see this explained at the proto definition of the device queue api service:

message DeviceQueueItem {
    // Device EUI (HEX encoded).
    string dev_eui = 1 [json_name = "devEUI"];

    // Set this to true when an acknowledgement from the device is required.
    // Please note that this must not be used to guarantee a delivery.
    bool confirmed = 2;

    // Downlink frame-counter.
    // This will be automatically set on enquue.
    uint32 f_cnt = 6;

    // FPort used (must be > 0)
    uint32 f_port = 3;

    // Base64 encoded data.
    // Or use the json_object field when an application codec has been configured.
    bytes data = 4;

    // JSON object (string).
    // Only use this when an application codec has been configured that can convert
    // this object into binary form.
    string json_object = 5;
}

#3

Ok, so is there a reference on what the cayenne encoder does and what messages/objects it expects?

I had to override the cayenne encoder/decoder to add some data types and want to know what I should do for the encoder portion.