| 548 | /// @return Vector containing serialized bytes, or error. |
| 549 | template <typename T> |
| 550 | Result<std::vector<uint8_t>, Error> serialize(const T &obj) { |
| 551 | if (FORY_PREDICT_FALSE(!finalized_)) { |
| 552 | ensure_finalized(); |
| 553 | } |
| 554 | WriteContextGuard guard(*write_ctx_); |
| 555 | Buffer &buffer = write_ctx_->buffer(); |
| 556 | |
| 557 | FORY_RETURN_NOT_OK(serialize_impl(obj, buffer)); |
| 558 | |
| 559 | std::vector<uint8_t> result(buffer.writer_index()); |
| 560 | std::memcpy(result.data(), buffer.data(), buffer.writer_index()); |
| 561 | return result; |
| 562 | } |
| 563 | |
| 564 | /// Serialize an object to an output stream. |
| 565 | /// |
nothing calls this directly
no test coverage detected