MCPcopy Create free account
hub / github.com/apache/fory / try_write_shared_ref

Method try_write_shared_ref

cpp/fory/serialization/ref_resolver.h:62–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 /// serialized and a reference entry was emitted, false otherwise.
61 template <typename Writer, typename T>
62 bool try_write_shared_ref(Writer &writer, const std::shared_ptr<T> &ptr) {
63 if (!ptr) {
64 return false;
65 }
66
67 auto address = reinterpret_cast<uintptr_t>(ptr.get());
68 auto *entry = ptr_to_id_.find(address);
69 if (entry != nullptr) {
70 writer.write_int8(static_cast<int8_t>(RefFlag::Ref));
71 writer.write_var_uint32(entry->second);
72 return true;
73 }
74
75 uint32_t new_id = next_id_++;
76 ptr_to_id_.emplace(address, new_id);
77 writer.write_int8(static_cast<int8_t>(RefFlag::RefValue));
78 return false;
79 }
80
81 /// reserve a ref_id slot without storing a pointer.
82 /// Used for types (like structs) that Java tracks but C++ doesn't reference.

Callers 2

writeMethod · 0.80
writeMethod · 0.80

Calls 4

findMethod · 0.80
getMethod · 0.65
write_int8Method · 0.45
write_var_uint32Method · 0.45

Tested by

no test coverage detected