class EpsCopyInputStream

Defined at line 117 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

The basic abstraction the parser is designed for is a slight modification

of the ZeroCopyInputStream (ZCIS) abstraction. A ZCIS presents a serialized

stream as a series of buffers that concatenate to the full stream.

Pictorially a ZCIS presents a stream in chunks like so

[---------------------------------------------------------------]

[---------------------] chunk 1

[----------------------------] chunk 2

chunk 3 [--------------]

Where the '-' represent the bytes which are vertically lined up with the

bytes of the stream. The proto parser requires its input to be presented

similarly with the extra

property that each chunk has kSlopBytes past its end that overlaps with the

first kSlopBytes of the next chunk, or if there is no next chunk at least its

still valid to read those bytes. Again, pictorially, we now have

[---------------------------------------------------------------]

[-------------------....] chunk 1

[------------------------....] chunk 2

chunk 3 [------------------..**]

chunk 4 [--****]

Here '-' mean the bytes of the stream or chunk and '.' means bytes past the

chunk that match up with the start of the next chunk. Above each chunk has

4 '.' after the chunk. In the case these 'overflow' bytes represents bytes

past the stream, indicated by '*' above, their values are unspecified. It is

still legal to read them (ie. should not segfault). Reading past the

end should be detected by the user and indicated as an error.

The reason for this, admittedly, unconventional invariant is to ruthlessly

optimize the protobuf parser. Having an overlap helps in two important ways.

Firstly it alleviates having to performing bounds checks if a piece of code

is guaranteed to not read more than kSlopBytes. Secondly, and more

importantly, the protobuf wireformat is such that reading a key/value pair is

always less than 16 bytes. This removes the need to change to next buffer in

the middle of reading primitive values. Hence there is no need to store and

load the current position.

Public Methods

void EpsCopyInputStream (bool enable_aliasing)

Defined at line 120 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

void BackUp (const char * ptr)

Defined at line 123 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

LimitToken PushLimit (const char * ptr, int limit)

If return value is negative it's an error

Defined at line 171 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

bool PopLimit (LimitToken delta)

Defined at line 182 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

uint32_t LastTag ()

Defined at line 290 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

bool ConsumeEndGroup (uint32_t start_tag)

Defined at line 293 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

bool EndedAtLimit ()

Defined at line 298 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

bool EndedAtEndOfStream ()

Defined at line 301 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * ReadArray (const char * ptr, absl::Span<char> out)
const char * Skip (const char * ptr, int size)

Defined at line 193 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * ReadString (const char * ptr, int size, std::string * s)

Defined at line 199 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * AppendString (const char * ptr, int size, std::string * s)

Defined at line 213 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename Add>
const char * ReadPackedVarint (const char * ptr, Add add)

Defined at line 277 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

void SetLastTag (uint32_t tag)

Defined at line 304 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

void SetEndOfStream ()

Defined at line 305 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

bool IsExceedingLimit (const char * ptr)

Defined at line 306 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

bool AliasingEnabled ()

Defined at line 310 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

int BytesUntilLimit (const char * ptr)

Defined at line 313 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

int MaximumReadSize (const char * ptr)

Maximum number of sequential bytes that can be read starting from `ptr`.

Defined at line 318 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

bool DataAvailable (const char * ptr)

Returns true if more data is available, if false is returned one has to

call Done for further checks.

Defined at line 324 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

int BytesAvailable (const char * ptr)

Defined at line 328 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename DataT, typename SinkT, typename PeekFunc>
const char * AdvancePtrMaybeFlush (const char * ptr, int64_t count, SinkT & sink, PeekFunc && peek_func)

Advances "ptr" by "size" bytes and calls "peek_func" with the contiguous

"view" of the data. Adjusts the size of the "view" if sizeof(DataT) > 1 to

allow users to read `DataT` without worrying about fragmented input.

If the current buffer is exhausted, update "ptr" accordingly after reading

next buffers. Flush previous buffers to the sink if needed. Callers are

responsible for the final `Flush`.

The sink object must provide the following methods:

// Called when data is flushed from a buffer. `p` is the pointer up to

// which data is flushed. "sink" must track start pointer.

void Flush(const char* p);

// Called to append a view of data. "sink" must update its start pointer

// accordingly.

void Append(absl::string_view view);

// Called after advancing to new data, `p` is the new start pointer.

void Reset(const char* p);

Defined at line 372 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * VerifyUTF8 (const char * ptr, size_t size)
const char * ReadMicroString (const char * ptr, MicroString & str, Arena * arena)

Defined at line 1472 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * ReadMicroStringWithSize (const char * ptr, int size, MicroString & str, Arena * arena)

Defined at line 1481 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * ReadMicroStringFallback (const char * ptr, int size, MicroString & str, Arena * arena)
const char * ReadArenaString (const char * ptr, ArenaStringPtr * s, Arena * arena)

Implemented in arenastring.cc

const char * ReadCord (const char * ptr, int size, ::absl::Cord * cord)

Defined at line 238 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename FuncT>
const char * ReadChunkAndCallback (const char * ptr, int size, FuncT && callback)

Defined at line 250 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename Tag, typename T>
const char * ReadRepeatedFixed (const char * ptr, Arena * arena, Tag expected_tag, RepeatedField<T> * out)

Defined at line 1493 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename T>
const char * ReadPackedFixed (const char * ptr, Arena * arena, int size, RepeatedField<T> * out)

Defined at line 1517 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename Add>
const char * ReadPackedVarintArray (const char * ptr, const char * end, Add add)

Helpers for ReadPackedVarint and ReadPackedVarintWithField.

Defined at line 1560 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename Convert, typename T>
const char * ReadPackedVarintArrayWithField (const char * ptr, const char * end, Arena * arena, Convert conv, RepeatedField<T> & out)

Defined at line 1573 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename Add, typename SizeCb>
const char * ReadPackedVarint (const char * ptr, Add add, SizeCb size_callback)

Defined at line 1674 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename Convert, typename T>
const char * ReadPackedVarintWithField (const char * ptr, Arena * arena, Convert conv, RepeatedField<T> & out)

Same as above, but pass the field directly , so we can preallocate.

Defined at line 1634 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

template <typename SinkT>
const char * ReadArrayMaybeFlush (const char * ptr, absl::Span<char> out, SinkT & sink)
template <typename SinkT>
const char * SkipMaybeFlush (const char * ptr, int64_t size, SinkT & sink)

Defined at line 338 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

Protected Methods

template <typename SinkT>
bool DoneWithCheck (const char ** ptr, int d, SinkT & sink)

Returns true if limit (either an explicit limit or end of stream) is

reached. It aligns *ptr across buffer seams.

If limit is exceeded, it returns true and ptr is set to null.

Defined at line 453 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * InitFrom (absl::string_view flat)

Defined at line 477 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * InitFrom (io::ZeroCopyInputStream * zcis)
const char * InitFrom (io::ZeroCopyInputStream * zcis, int limit)

Defined at line 502 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

const char * InitFrom (const BoundedZCIS & bounded_zcis)

TODO Can V1 enjoy a code deduplication benefit by using this?

Defined at line 512 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

Enumerations

enum (unnamed)
Name Value
kMaxCordBytesToCopy 512

Defined at line 119 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

enum (unnamed)
Name Value
kSlopBytes 16
kPatchBufferSize 32

Defined at line 517 of file ../../third_party/protobuf/src/src/google/protobuf/parse_context.h

Records

Friends

pair EpsCopyInputStream (const char * p, uint32_t res)
class ImplicitWeakMessage