MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ReadNumIncreasing

Method ReadNumIncreasing

tensorflow/core/lib/strings/ordered_code.cc:274–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274bool OrderedCode::ReadNumIncreasing(StringPiece* src, uint64* result) {
275 if (src->empty()) {
276 return false; // Not enough bytes
277 }
278
279 // Decode length byte
280 const size_t len = static_cast<unsigned char>((*src)[0]);
281
282 // If len > 0 and src is longer than 1, the first byte of "payload"
283 // must be non-zero (otherwise the encoding is not minimal).
284 // In opt mode, we don't enforce that encodings must be minimal.
285 DCHECK(0 == len || src->size() == 1 || (*src)[1] != '\0')
286 << "invalid encoding";
287
288 if (len + 1 > src->size() || len > 8) {
289 return false; // Not enough bytes or too many bytes
290 }
291
292 if (result) {
293 uint64 tmp = 0;
294 for (size_t i = 0; i < len; i++) {
295 tmp <<= 8;
296 tmp |= static_cast<unsigned char>((*src)[1 + i]);
297 }
298 *result = tmp;
299 }
300 src->remove_prefix(len + 1);
301 return true;
302}
303
304void OrderedCode::TEST_Corrupt(string* str, int k) {
305 int seen_seps = 0;

Callers

nothing calls this directly

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected