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

Method ReadSignedNumIncreasing

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

Source from the content-addressed store, hash-verified

486}
487
488bool OrderedCode::ReadSignedNumIncreasing(StringPiece* src, int64* result) {
489 if (src->empty()) return false;
490 const uint64 xor_mask = (!((*src)[0] & 0x80)) ? ~0ULL : 0ULL;
491 const unsigned char first_byte = (*src)[0] ^ (xor_mask & 0xff);
492
493 // now calculate and test length, and set x to raw (unmasked) result
494 int len;
495 uint64 x;
496 if (first_byte != 0xff) {
497 len = 7 - Log2Floor64(first_byte ^ 0xff);
498 if (src->size() < static_cast<size_t>(len)) return false;
499 x = xor_mask; // sign extend using xor_mask
500 for (int i = 0; i < len; ++i)
501 x = (x << 8) | static_cast<unsigned char>((*src)[i]);
502 } else {
503 len = 8;
504 if (src->size() < static_cast<size_t>(len)) return false;
505 const unsigned char second_byte = (*src)[1] ^ (xor_mask & 0xff);
506 if (second_byte >= 0x80) {
507 if (second_byte < 0xc0) {
508 len = 9;
509 } else {
510 const unsigned char third_byte = (*src)[2] ^ (xor_mask & 0xff);
511 if (second_byte == 0xc0 && third_byte < 0x80) {
512 len = 10;
513 } else {
514 return false; // either len > 10 or len == 10 and #bits > 63
515 }
516 }
517 if (src->size() < static_cast<size_t>(len)) return false;
518 }
519 x = LoadBigEndian64(src->data() + len - 8);
520 }
521
522 x ^= kLengthToMask[len]; // remove spurious header bits
523
524 DCHECK_EQ(len, SignedEncodingLength(x)) << "invalid encoding";
525
526 if (result) *result = x;
527 src->remove_prefix(len);
528 return true;
529}
530
531} // namespace strings
532} // namespace tensorflow

Callers

nothing calls this directly

Calls 6

LoadBigEndian64Function · 0.85
SignedEncodingLengthFunction · 0.85
Log2Floor64Function · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected