Чтение базового типа из сообщения (Read a basic type from a message)
Имя (Name)
sd_bus_message_read_basic - Read a basic type from a message
Синопсис (Synopsis)
#include <systemd/sd-bus.h>
int sd_bus_message_read_basic(sd_bus_message *
m, char
type,
void *
p);
Описание (Description)
sd_bus_message_read_basic()
reads a basic type from a message and
advances the read position in the message. The set of basic types
and their ascii codes passed in type are described in the D-Bus
Specification
[1].
If p is not NULL
, it should contain a pointer to an appropriate
object. For example, if type is 'y'
, the object passed in p
should have type uint8_t *
. If type is 's'
, the object passed in
p should have type const char **
. Note that, if the basic type is
a pointer (e.g., const char *
in the case of a string), the
pointer is only borrowed and the contents must be copied if they
are to be used after the end of the message's lifetime.
Similarly, during the lifetime of such a pointer, the message
must not be modified. If type is 'h'
(UNIX file descriptor), the
descriptor is not duplicated by this call and the returned
descriptor remains in possession of the message object, and needs
to be duplicated by the caller in order to keep an open reference
to it after the message object is freed (for example by calling
"fcntl(fd, FD_DUPFD_CLOEXEC, 3)"). See the table below for a
complete list of allowed types.
Table 1. Item type specifiers
┌──────────┬─────────────────────────┬────────────────┬────────────────┐
│Specifier
│ Constant
│ Description
│ Expected C
│
│ │ │ │ Type
│
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"y" │ SD_BUS_TYPE_BYTE
│ 8bit unsigned │ uint8_t *
│
│ │ │ integer │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"b" │ SD_BUS_TYPE_BOOLEAN
│ boolean │ int *
(NB: not │
│ │ │ │ bool *
) │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"n" │ SD_BUS_TYPE_INT16
│ 16bit signed │ int16_t *
│
│ │ │ integer │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"q" │ SD_BUS_TYPE_UINT16
│ 16bit unsigned │ uint16_t *
│
│ │ │ integer │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"i" │ SD_BUS_TYPE_INT32
│ 32bit signed │ int32_t *
│
│ │ │ integer │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"u" │ SD_BUS_TYPE_UINT32
│ 32bit unsigned │ uint32_t *
│
│ │ │ integer │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"x" │ SD_BUS_TYPE_INT64
│ 64bit signed │ int64_t *
│
│ │ │ integer │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"t" │ SD_BUS_TYPE_UINT64
│ 64bit unsigned │ uint64_t *
│
│ │ │ integer │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"d" │ SD_BUS_TYPE_DOUBLE
│ IEEE 754 │ double *
│
│ │ │ double │ │
│ │ │ precision │ │
│ │ │ floating-point │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"s" │ SD_BUS_TYPE_STRING
│ UTF-8 string │ const char **
│
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"o" │ SD_BUS_TYPE_OBJECT_PATH
│ D-Bus object │ const char **
│
│ │ │ path string │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"g" │ SD_BUS_TYPE_SIGNATURE
│ D-Bus │ const char **
│
│ │ │ signature │ │
│ │ │ string │ │
├──────────┼─────────────────────────┼────────────────┼────────────────┤
│"h" │ SD_BUS_TYPE_UNIX_FD
│ UNIX file │ int *
│
│ │ │ descriptor │ │
└──────────┴─────────────────────────┴────────────────┴────────────────┘
If there is no object of the specified type at the current
position in the message, an error is returned.