@@ -45,6 +45,7 @@ BlobFormatWriter::BlobFormatWriter(const std::shared_ptr<OutputStream>& out, con
4545 write_consumer_(std::move(write_consumer)) {
4646 metrics_ = std::make_shared<MetricsImpl>();
4747 tmp_buffer_ = Bytes::AllocateBytes (kTmpBufferSize , pool_.get ());
48+ magic_number_bytes_ = IntegerToLittleEndian<int32_t >(BlobDefs::kMagicNumber , pool_);
4849}
4950
5051Result<std::unique_ptr<BlobFormatWriter>> BlobFormatWriter::Create (
@@ -159,9 +160,7 @@ Status BlobFormatWriter::WriteBlob(std::string_view blob_data) {
159160 PAIMON_ASSIGN_OR_RAISE (int64_t previous_pos, out_->GetPos ());
160161
161162 // write magic number
162- static PAIMON_UNIQUE_PTR <Bytes> kMagicNumberBytes =
163- IntegerToLittleEndian<int32_t >(BlobDefs::kMagicNumber , pool_);
164- PAIMON_RETURN_NOT_OK (WriteWithCrc32 (kMagicNumberBytes ->data (), kMagicNumberBytes ->size ()));
163+ PAIMON_RETURN_NOT_OK (WriteWithCrc32 (magic_number_bytes_->data (), magic_number_bytes_->size ()));
165164
166165 // write blob content
167166 // Dynamically check whether blob_data is a serialized BlobDescriptor (by magic header)
@@ -183,8 +182,9 @@ Status BlobFormatWriter::WriteBlob(std::string_view blob_data) {
183182 while (read_len > 0 ) {
184183 PAIMON_ASSIGN_OR_RAISE (int64_t actual_read_len, in->Read (tmp_buffer_->data (), read_len));
185184 if (actual_read_len != read_len) {
186- return Status::Invalid (" actual read length {}, not match with expect length {}" ,
187- actual_read_len, read_len);
185+ return Status::Invalid (
186+ fmt::format (" actual read length {}, not match with expect length {}" ,
187+ actual_read_len, read_len));
188188 }
189189 PAIMON_RETURN_NOT_OK (WriteWithCrc32 (tmp_buffer_->data (), actual_read_len));
190190 total_read_length += actual_read_len;
@@ -212,8 +212,8 @@ Status BlobFormatWriter::WriteBlob(std::string_view blob_data) {
212212Status BlobFormatWriter::WriteBytes (const char * data, int64_t length) {
213213 PAIMON_ASSIGN_OR_RAISE (int64_t actual, out_->Write (data, length));
214214 if (actual != length) {
215- return Status::Invalid (" not suppose actual length {} not match with expect {} " , actual,
216- length);
215+ return Status::Invalid (
216+ fmt::format ( " unexpected actual length {} not match with expect {} " , actual, length) );
217217 }
218218 return Status::OK ();
219219}
0 commit comments