Loading...
Searching...
No Matches
wire_read.h File Reference

Reads the values the phone packs into a message. More...

#include <stdbool.h>
#include <stdint.h>
#include "io/bytes_le.h"

Go to the source code of this file.

Functions

static int32_t wire_int_or (bool is_signed, uint16_t length, const uint8_t *value, int32_t fallback)
 Reads a little-endian integer of exactly length bytes.
static bool wire_cstring_terminated (const char *s, uint16_t length)
 Whether a string of length bytes carries its terminator inside itself.
static int32_t wire_digits_or (const char *text, int32_t fallback)
 Reads text holding only digits as the whole number it spells, such as a select's "3".

Detailed Description

Reads the values the phone packs into a message.

The phone is free to send an integer one, two, or four bytes wide, and it says which by the length it puts beside the value rather than by the type. The values sit back to back with nothing between them, so a reader that takes the type's word for the width and grabs four bytes off a one-byte value walks straight into whatever is packed behind it. That is what these are for: the width decides how many bytes get read, and anything else is refused. A number sent as text is read here too, so a setting takes it whichever way the phone sent it.

Header only on purpose. There is one caller on the watch (tuple_read.c), so each body folds into it and nothing is spent on getting there.