MCPcopy Index your code
hub / github.com/apache/fory / write_primitive_item

Function write_primitive_item

python/pyfory/cpp/pyfory.cc:783–931  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

781}
782
783static int write_primitive_item(Buffer *buffer, PyObject *value,
784 uint8_t type_id) {
785 switch (static_cast<TypeId>(type_id)) {
786 case TypeId::STRING:
787 return write_python_string(buffer, value);
788 case TypeId::VARINT64:
789 case TypeId::INT64: {
790 int64_t v = 0;
791 if (FORY_PREDICT_FALSE(!py_long_to_int64(value, &v))) {
792 return -1;
793 }
794 if (static_cast<TypeId>(type_id) == TypeId::INT64) {
795 buffer->write_int64(v);
796 } else {
797 buffer->write_var_int64(v);
798 }
799 return 0;
800 }
801 case TypeId::VARINT32:
802 case TypeId::INT32: {
803 int32_t v = 0;
804 if (FORY_PREDICT_FALSE(
805 !py_long_to_integral_range<int32_t>(value, "int32", &v))) {
806 return -1;
807 }
808 if (static_cast<TypeId>(type_id) == TypeId::INT32) {
809 buffer->write_int32(v);
810 } else {
811 buffer->write_var_int32(v);
812 }
813 return 0;
814 }
815 case TypeId::VAR_UINT64:
816 case TypeId::UINT64:
817 case TypeId::TAGGED_UINT64: {
818 uint64_t v = 0;
819 if (FORY_PREDICT_FALSE(
820 !py_long_to_unsigned_range<uint64_t>(value, "uint64", &v))) {
821 return -1;
822 }
823 if (static_cast<TypeId>(type_id) == TypeId::VAR_UINT64) {
824 buffer->write_var_uint64(v);
825 } else if (static_cast<TypeId>(type_id) == TypeId::TAGGED_UINT64) {
826 buffer->write_tagged_uint64(v);
827 } else {
828 buffer->write_int64(static_cast<int64_t>(v));
829 }
830 return 0;
831 }
832 case TypeId::VAR_UINT32:
833 case TypeId::UINT32: {
834 uint32_t v = 0;
835 if (FORY_PREDICT_FALSE(
836 !py_long_to_unsigned_range<uint32_t>(value, "uint32", &v))) {
837 return -1;
838 }
839 if (static_cast<TypeId>(type_id) == TypeId::VAR_UINT32) {
840 buffer->write_var_uint32(v);

Calls 15

write_python_stringFunction · 0.85
py_long_to_int64Function · 0.85
write_int64Method · 0.45
write_var_int64Method · 0.45
write_int32Method · 0.45
write_var_int32Method · 0.45
write_var_uint64Method · 0.45
write_tagged_uint64Method · 0.45
write_var_uint32Method · 0.45
write_uint32Method · 0.45
write_int8Method · 0.45
write_floatMethod · 0.45

Tested by

no test coverage detected