@@ -47,6 +47,7 @@ BlobFormatWriter::BlobFormatWriter(const std::shared_ptr<OutputStream>& out, con
4747 write_consumer_(std::move(write_consumer)) {
4848 metrics_ = std::make_shared<MetricsImpl>();
4949 tmp_buffer_ = Bytes::AllocateBytes (kTmpBufferSize , pool_.get ());
50+ magic_number_bytes_ = IntegerToLittleEndian<int32_t >(BlobDefs::kMagicNumber , pool_);
5051}
5152
5253Result<std::unique_ptr<BlobFormatWriter>> BlobFormatWriter::Create (
@@ -161,9 +162,7 @@ Status BlobFormatWriter::WriteBlob(std::string_view blob_data) {
161162 PAIMON_ASSIGN_OR_RAISE (int64_t previous_pos, out_->GetPos ());
162163
163164 // write magic number
164- static PAIMON_UNIQUE_PTR <Bytes> kMagicNumberBytes =
165- IntegerToLittleEndian<int32_t >(BlobDefs::kMagicNumber , pool_);
166- PAIMON_RETURN_NOT_OK (WriteWithCrc32 (kMagicNumberBytes ->data (), kMagicNumberBytes ->size ()));
165+ PAIMON_RETURN_NOT_OK (WriteWithCrc32 (magic_number_bytes_->data (), magic_number_bytes_->size ()));
167166
168167 // write blob content
169168 // Dynamically check whether blob_data is a serialized BlobDescriptor (by magic header)
@@ -185,8 +184,9 @@ Status BlobFormatWriter::WriteBlob(std::string_view blob_data) {
185184 while (read_len > 0 ) {
186185 PAIMON_ASSIGN_OR_RAISE (int64_t actual_read_len, in->Read (tmp_buffer_->data (), read_len));
187186 if (actual_read_len != read_len) {
188- return Status::Invalid (" actual read length {}, not match with expect length {}" ,
189- actual_read_len, read_len);
187+ return Status::Invalid (
188+ fmt::format (" actual read length {}, not match with expect length {}" ,
189+ actual_read_len, read_len));
190190 }
191191 PAIMON_RETURN_NOT_OK (WriteWithCrc32 (tmp_buffer_->data (), actual_read_len));
192192 total_read_length += actual_read_len;
@@ -214,8 +214,8 @@ Status BlobFormatWriter::WriteBlob(std::string_view blob_data) {
214214Status BlobFormatWriter::WriteBytes (const char * data, int64_t length) {
215215 PAIMON_ASSIGN_OR_RAISE (int64_t actual, out_->Write (data, length));
216216 if (actual != length) {
217- return Status::Invalid (" not suppose actual length {} not match with expect {} " , actual,
218- length);
217+ return Status::Invalid (
218+ fmt::format ( " unexpected actual length {} not match with expect {} " , actual, length) );
219219 }
220220 return Status::OK ();
221221}
0 commit comments