MCPcopy Create free account
hub / github.com/apache/thrift / writeI64

Method writeI64

lib/php/lib/Protocol/TCompactProtocol.php:703–763  ·  view source on GitHub ↗
($value)

Source from the content-addressed store, hash-verified

701 }
702
703 public function writeI64($value)
704 {
705 // If we are in an I32 range, use the easy method below.
706 if (($value > 4294967296) || ($value < -4294967296)) {
707 // Convert $value to $hi and $lo
708 $neg = $value < 0;
709
710 if ($neg) {
711 $value *= -1;
712 }
713
714 $hi = (int)$value >> 32;
715 $lo = (int)$value & 0xffffffff;
716
717 if ($neg) {
718 $hi = ~$hi;
719 $lo = ~$lo;
720 if (($lo & (int)0xffffffff) == (int)0xffffffff) {
721 $lo = 0;
722 $hi++;
723 } else {
724 $lo++;
725 }
726 }
727
728 // Now do the zigging and zagging.
729 $xorer = 0;
730 if ($neg) {
731 $xorer = 0xffffffff;
732 }
733 $lowbit = ($lo >> 31) & 1;
734 $hi = ($hi << 1) | $lowbit;
735 $lo = ($lo << 1);
736 $lo = ($lo ^ $xorer) & 0xffffffff;
737 $hi = ($hi ^ $xorer) & 0xffffffff;
738
739 // now write out the varint, ensuring we shift both hi and lo
740 $out = "";
741 while (true) {
742 if (($lo & ~0x7f) === 0 &&
743 $hi === 0) {
744 $out .= chr($lo);
745 break;
746 } else {
747 $out .= chr(($lo & 0xff) | 0x80);
748 $lo = $lo >> 7;
749 $lo = $lo | ($hi << 25);
750 $hi = $hi >> 7;
751 // Right shift carries sign, but we don't want it to.
752 $hi = $hi & (127 << 25);
753 }
754 }
755
756 $ret = TStringFuncFactory::create()->strlen($out);
757 $this->trans_->write($out, $ret);
758
759 return $ret;
760 } else {

Callers

nothing calls this directly

Calls 5

writeVarintMethod · 0.95
toZigZagMethod · 0.95
writeMethod · 0.65
strlenMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected