1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 00:28:10 +00:00

bootloader: protobuf - add pb_add_bytes

This commit is contained in:
Pavol Rusnak 2017-05-02 19:49:56 +02:00
parent 6fd52dd36e
commit f345de1a4f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 12 additions and 9 deletions

View File

@ -49,20 +49,22 @@ static void pb_varint(PB_CTX *ctx, uint32_t val)
void pb_add_bool(PB_CTX *ctx, uint32_t field_number, bool val)
{
field_number = (field_number << 3) | 0;
pb_add_varint(ctx, field_number, val);
}
void pb_add_bytes(PB_CTX *ctx, uint32_t field_number, const uint8_t *val, uint32_t len)
{
field_number = (field_number << 3) | 2;
pb_varint(ctx, field_number);
pb_append(ctx, val);
pb_varint(ctx, len);
for (uint32_t i = 0; i < len; i++) {
pb_append(ctx, val[i]);
}
}
void pb_add_string(PB_CTX *ctx, uint32_t field_number, const char *val)
{
field_number = (field_number << 3) | 2;
pb_varint(ctx, field_number);
size_t len = strlen(val);
pb_varint(ctx, len);
for (size_t i = 0; i < len; i++) {
pb_append(ctx, val[i]);
}
pb_add_bytes(ctx, field_number, (const uint8_t *)val, strlen(val));
}
void pb_add_varint(PB_CTX *ctx, uint32_t field_number, uint32_t val)

View File

@ -16,6 +16,7 @@ void pb_start(PB_CTX *ctx, uint16_t msg_id);
void pb_end(PB_CTX *ctx);
void pb_add_bool(PB_CTX *ctx, uint32_t field_number, bool val);
void pb_add_bytes(PB_CTX *ctx, uint32_t field_number, const uint8_t *val, uint32_t len);
void pb_add_string(PB_CTX *ctx, uint32_t field_number, const char *val);
void pb_add_varint(PB_CTX *ctx, uint32_t field_number, uint32_t val);