An Encoder class for protocol buffers (PB) that preserves sorting characteristics.
This is used by datastore_sqlite_stub and datastore_types to match the
ordering semantics of the production datastore. Broadly, there are four
changes from regular PB encoding:
Strings are escaped and null terminated instead of length-prefixed. The
escaping replaces \x00 with \x01\x01 and \x01 with \x01\x02, thus
preserving the ordering of the original string.
Variable length integers are encoded using a variable length encoding that
preserves order. The first byte stores the absolute value if it's between
-119 to 119, otherwise it stores the number of bytes that follow.
Numbers are stored big endian instead of little endian.
Negative doubles are entirely negated, while positive doubles have their sign
bit flipped.
Warning:
Due to the way nested Protocol Buffers are encoded, this encoder will NOT
preserve sorting characteristics for embedded protocol buffers!
Classes
class Decoder: Decoder that decodes a bytes buffer into a protocol buffer message.
class Encoder: Encodes protocol buffers in a form that sorts nicely.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-09-30 UTC."],[[["This module provides an Encoder class for protocol buffers that ensures sorting characteristics are maintained, unlike standard PB encoding."],["The encoder modifies string encoding by escaping special characters and adding null termination to preserve order, deviating from standard length-prefixed encoding."],["Variable-length integers are encoded in a way that maintains order, with a special first byte indicating the value's range or the length of subsequent bytes."],["Numbers are encoded in big-endian format instead of little-endian, and doubles are manipulated to preserve order."],["The encoder is incompatible with nested Protocol Buffers, as it cannot preserve sorting characteristics in those scenarios."]]],[]]