Commit Graph

12 Commits

Author SHA1 Message Date
Alexei Frolov
b9fda58850 pw_hdlc: Multibyte address support
This extends the HDLC encoder and decoder in both C++ and Python to use
HDLC extended addressing, where the address field is a one-terminated
LSB varint.

Classes using HDLC, such as the HDLC ChannelOutput and WirePacketParser,
are updated accordingly.

Change-Id: I6affc4443079628567d33939d809218f7b7bdf41
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/38020
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
2021-03-19 18:36:03 +00:00
Alexei Frolov
247efd9d5a pw_varint: Configurable encoding options
This adds an additional varint encoding and decoding API that allows
configuring which bit indicates the continuation or termination of the
number.

Change-Id: I34df4b330341129322b2296f4f07b8ea397964ab
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/37320
Commit-Queue: Alexei Frolov <frolv@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
2021-03-17 00:00:47 +00:00
Ewout van Bekkum
dc6d984004 pw_protobuf: Adds serialized size of field keys
Adds size_t pw::protobuf::SizeOfFieldKey(uint32_t field_number) to
help better estimate the serialized size cost for specific fields
which can be much smaller than kMaxSizeOfFieldKey.

Note that the API does not ask for the wiretype which is in the
actual field key (AKA tag) as it does not impact the serialized
size and only makes the API more verbose.

To enable this, pw::varint::{EncodedSize,ZigZagEncodedSize} were
changed to be constexpr, where the C functions invoke C++ instead.

Change-Id: Icbe4250e7acc8131bec9ec5c145e0074591777f6
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/18848
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
2020-09-24 21:19:22 +00:00
Ewout van Bekkum
bd33812e82 pw_varint: expose kMaxVarint{32,64}SizeBytes
Renames the existing pw::varint::kMaxVarintSizeBytes to
pw::varint::kMaxVarint64SizeBytes and adds a new
pw::varint::kMaxVarint32SizeBytes.

Note this does not yet remove pw::varint::kMaxVarintSizeBytes, as
the existing users need to be migrated first.

Change-Id: Ie57e32b9526347df95282f7bba2d6f2ff34b4a08
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/18686
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
2020-09-23 00:38:55 +00:00
Alexei Frolov
388d4b9b03 pw_varint: Add EncodedSize function
This change adds functions to the varint module which return the size of
an integer when encoded as a varint.

Change-Id: I976e33835b1b6bece7ca586cd7f1c4d9ca17cdc8
2020-05-20 22:22:32 +00:00
Wyatt Hepler
588907ad42 Make span and varint C++11 compatible
Change-Id: Idb9f4e1563d4d4cfeb460b23c82d11fd9c298939
2020-01-17 15:04:43 -08:00
Alexei Frolov
8ecefe902b pw_varint: C support
This change exposes a subset of the pw::varint API for use in C code.

Change-Id: I7db2dd1d2622711785e23c8534de6119301c57c3
2020-01-14 00:13:55 +00:00
Alexei Frolov
5d63df9c0b
pw_varint: Expose zig-zag decoding
This change moves the ZigZagDecode function from varint.cc to varint.h
so that it is part of pw_varint's public interface.

Change-Id: I53a659f1e5c701465c277eab2082d57624c0e65c
2020-01-07 10:57:09 -08:00
Alexei Frolov
65ffd22d01 pw_varint: Rename varint functions
This change removes "Varint" from the names of the Encode and Decode
functions in the pw_varint module, as they are already namespaced by
pw::varint.

Change-Id: I8f1383e390624b677d161a2ac2a1327c5e7ba5b1
2020-01-07 18:55:55 +00:00
Alexei Frolov
311c620af6 pw_varint: use std::byte instead of uint8_t
This change switches pw_varint to using spans of std::byte instead of
uint8_t for encoding and decoding. The pw_protobuf module, which uses
pw_varint, is also updated.

A ToString formatter for std::byte is also added to pw_string (required
to use std::byte in unit test EXPECT statements).

Change-Id: I198370eecdabde32a85987dda98aed84c85b9c91
2020-01-06 19:47:54 +00:00
Wyatt Hepler
8c493bbf76 Fix the copyright notice on a few files
Change-Id: Ieff83592399946000fc806a037b0f5ffcaa3bd10
2019-12-03 00:00:28 +00:00
Alexei Frolov
82d3cb35d3 pw_varint: Add varint module
This change adds a pw_varint module containing functions for encoding
and decoding variable-length integers.

Change-Id: I50bdf6d9d6762bffb93ee638683de53afed9c849
2019-12-02 18:39:29 +00:00