Skip to content

Commit 309cf67

Browse files
committed
Revert "Add more improvements"
This reverts commit 2385034.
1 parent 7d7ff1c commit 309cf67

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/serialize.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ namespace sparrow_ipc
100100

101101
// arrow_arr.buffers[0] is the validity bitmap
102102
// arrow_arr.buffers[1] is the data buffer
103-
const auto validity_bitmap = static_cast<const uint8_t*>(arrow_arr.buffers[0]);
104-
const auto data_buffer = static_cast<const uint8_t*>(arrow_arr.buffers[1]);
103+
const uint8_t* validity_bitmap = static_cast<const uint8_t*>(arrow_arr.buffers[0]);
104+
const uint8_t* data_buffer = static_cast<const uint8_t*>(arrow_arr.buffers[1]);
105105

106106
// Calculate the size of the validity and data buffers
107107
int64_t validity_size = (arrow_arr.length + arrow_alignment - 1) / arrow_alignment;
@@ -133,10 +133,10 @@ namespace sparrow_ipc
133133
batch_builder.Finish(batch_message_offset);
134134

135135
// III - Append the RecordBatch message to the final buffer
136-
const uint32_t batch_meta_len = batch_builder.GetSize(); // Get the size of the batch metadata
137-
const int64_t aligned_batch_meta_len = align_to_8(batch_meta_len); // Calculate the padded length
136+
uint32_t batch_meta_len = batch_builder.GetSize(); // Get the size of the batch metadata
137+
int64_t aligned_batch_meta_len = align_to_8(batch_meta_len); // Calculate the padded length
138138

139-
const size_t current_size = final_buffer.size(); // Get the current size (which is the end of the Schema message)
139+
size_t current_size = final_buffer.size(); // Get the current size (which is the end of the Schema message)
140140
// Resize the buffer to append the new message
141141
final_buffer.resize(current_size + sizeof(uint32_t) + aligned_batch_meta_len + body_len);
142142
uint8_t* dst = final_buffer.data() + current_size; // Get a pointer to where the new message will start
@@ -147,15 +147,7 @@ namespace sparrow_ipc
147147
// Copy the RecordBatch metadata into the buffer
148148
memcpy(dst, batch_builder.GetBufferPointer(), batch_meta_len);
149149
// Add padding to align the body to an 8-byte boundary
150-
if (aligned_batch_meta_len >= batch_meta_len)
151-
{
152-
memset(dst + batch_meta_len, 0, aligned_batch_meta_len - batch_meta_len);
153-
}
154-
else
155-
{
156-
throw std::runtime_error("aligned_batch_meta_len should be greater than batch_meta_len");
157-
}
158-
150+
memset(dst + batch_meta_len, 0, aligned_batch_meta_len - batch_meta_len);
159151
dst += aligned_batch_meta_len;
160152
// Copy the actual data buffers (the message body) into the buffer
161153
if (validity_bitmap)
@@ -165,8 +157,7 @@ namespace sparrow_ipc
165157
else
166158
{
167159
// If validity_bitmap is null, it means there are no nulls
168-
constexpr uint8_t no_nulls_bitmap = 0xFF;
169-
memset(dst, no_nulls_bitmap, validity_size);
160+
memset(dst, 0xFF, validity_size);
170161
}
171162
dst += validity_size;
172163
if (data_buffer)
@@ -189,7 +180,7 @@ sparrow::primitive_array<T> deserialize_primitive_array(const std::vector<uint8_
189180
size_t current_offset = 0;
190181

191182
// I - Deserialize the Schema message
192-
uint32_t schema_meta_len = 0;
183+
uint32_t schema_meta_len;
193184
memcpy(&schema_meta_len, buf_ptr + current_offset, sizeof(schema_meta_len));
194185
current_offset += sizeof(uint32_t);
195186
auto schema_message = org::apache::arrow::flatbuf::GetMessage(buf_ptr + current_offset);
@@ -207,7 +198,7 @@ sparrow::primitive_array<T> deserialize_primitive_array(const std::vector<uint8_
207198
current_offset += schema_meta_len;
208199

209200
// II - Deserialize the RecordBatch message
210-
uint32_t batch_meta_len = 0;
201+
uint32_t batch_meta_len;
211202
memcpy(&batch_meta_len, buf_ptr + current_offset, sizeof(batch_meta_len));
212203
current_offset += sizeof(uint32_t);
213204
auto batch_message = org::apache::arrow::flatbuf::GetMessage(buf_ptr + current_offset);
@@ -229,10 +220,10 @@ sparrow::primitive_array<T> deserialize_primitive_array(const std::vector<uint8_
229220
int64_t validity_len = buffers_meta->Get(0)->length();
230221
int64_t data_len = buffers_meta->Get(1)->length();
231222

232-
auto validity_buffer_copy = new uint8_t[validity_len];
223+
uint8_t* validity_buffer_copy = new uint8_t[validity_len];
233224
memcpy(validity_buffer_copy, body_ptr + buffers_meta->Get(0)->offset(), validity_len);
234225

235-
auto data_buffer_copy = new uint8_t[data_len];
226+
uint8_t* data_buffer_copy = new uint8_t[data_len];
236227
memcpy(data_buffer_copy, body_ptr + buffers_meta->Get(1)->offset(), data_len);
237228

238229
// Get name

0 commit comments

Comments
 (0)