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>
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>
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>
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>
This change adds functions to the varint module which return the size of
an integer when encoded as a varint.
Change-Id: I976e33835b1b6bece7ca586cd7f1c4d9ca17cdc8
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
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
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
This change adds a pw_varint module containing functions for encoding
and decoding variable-length integers.
Change-Id: I50bdf6d9d6762bffb93ee638683de53afed9c849