astarte_core v0.11.3 Astarte.Core.Device View Source
Utility functions to deal with Astarte devices
Link to this section Summary
Functions
Decodes a Base64 url encoded device id and returns it as a 128-bit binary (usable as uuid).
Decodes an extended Base64 url encoded device id.
Encodes a device id with the standard encoding (Base64 url encoding, no padding). The device id must be exactly 16 bytes (128 bits) long.
Generate a random Astarte device id.
Link to this section Types
Link to this section Functions
decode_device_id(encoded_device_id, opts \\ [])
View Sourcedecode_device_id(encoded_device_id :: encoded_device_id(), opts :: options) :: {:ok, device_id :: device_id()} | {:error, atom()} when options: [option], option: {:allow_extended_id, boolean()}
Decodes a Base64 url encoded device id and returns it as a 128-bit binary (usable as uuid).
By default, it will fail with {:error, :extended_id_not_allowed} if the size of the encoded device_id is > 128 bit.
You can pass allow_extended_id: true as second argument to allow longer device ids (the returned binary will still be 128 bit long, but the function will not return an error and will instead drop the extended id).
Returns {:ok, device_id} or {:error, reason}.
decode_extended_device_id(encoded_device_id)
View Sourcedecode_extended_device_id(encoded_device_id :: encoded_device_id()) :: {:ok, device_id :: device_id(), extended_id :: binary()} | {:error, atom()}
Decodes an extended Base64 url encoded device id.
Returns {:ok, device_id, extended_id} (where device_id is a binary with the first 128 bits of the decoded id and extended_id the rest of the decoded binary) or {:error, reason}.
encode_device_id(device_id)
View Sourceencode_device_id(device_id :: device_id()) :: encoded_device_id :: encoded_device_id()
Encodes a device id with the standard encoding (Base64 url encoding, no padding). The device id must be exactly 16 bytes (128 bits) long.
Returns the encoded device id.
Generate a random Astarte device id.
The generated device id is also a valid UUID v4.