15
15
// specific language governing permissions and limitations
16
16
// under the License.
17
17
18
- #include " arrow/matlab/buffer/matlab_buffer.h"
19
18
#include " arrow/matlab/io/ipc/proxy/record_batch_stream_reader.h"
20
19
#include " arrow/io/file.h"
21
20
#include " arrow/io/memory.h"
21
+ #include " arrow/matlab/buffer/matlab_buffer.h"
22
22
#include " arrow/matlab/error/error.h"
23
23
#include " arrow/matlab/tabular/proxy/record_batch.h"
24
24
#include " arrow/matlab/tabular/proxy/schema.h"
@@ -38,58 +38,63 @@ RecordBatchStreamReader::RecordBatchStreamReader(
38
38
REGISTER_METHOD (RecordBatchStreamReader, readTable);
39
39
}
40
40
41
- libmexclass::proxy::MakeResult RecordBatchStreamReader::fromFile (const libmexclass::proxy::FunctionArguments& constructor_arguments) {
42
- namespace mda = ::matlab::data;
43
- using RecordBatchStreamReaderProxy =
41
+ libmexclass::proxy::MakeResult RecordBatchStreamReader::fromFile (
42
+ const libmexclass::proxy::FunctionArguments& constructor_arguments) {
43
+ namespace mda = ::matlab::data;
44
+ using RecordBatchStreamReaderProxy =
44
45
arrow::matlab::io::ipc::proxy::RecordBatchStreamReader;
45
46
46
- const mda::StructArray opts = constructor_arguments[0 ];
47
- const mda::StringArray filename_mda = opts[0 ][" Filename" ];
48
- const auto filename_utf16 = std::u16string (filename_mda[0 ]);
49
- MATLAB_ASSIGN_OR_ERROR (const auto filename_utf8,
50
- arrow::util::UTF16StringToUTF8 (filename_utf16),
51
- error::UNICODE_CONVERSION_ERROR_ID);
47
+ const mda::StructArray opts = constructor_arguments[0 ];
48
+ const mda::StringArray filename_mda = opts[0 ][" Filename" ];
49
+ const auto filename_utf16 = std::u16string (filename_mda[0 ]);
50
+ MATLAB_ASSIGN_OR_ERROR (const auto filename_utf8,
51
+ arrow::util::UTF16StringToUTF8 (filename_utf16),
52
+ error::UNICODE_CONVERSION_ERROR_ID);
52
53
53
- MATLAB_ASSIGN_OR_ERROR (auto input_stream, arrow::io::ReadableFile::Open (filename_utf8),
54
- error::FAILED_TO_OPEN_FILE_FOR_READ);
54
+ MATLAB_ASSIGN_OR_ERROR (auto input_stream, arrow::io::ReadableFile::Open (filename_utf8),
55
+ error::FAILED_TO_OPEN_FILE_FOR_READ);
55
56
56
- MATLAB_ASSIGN_OR_ERROR (auto reader,
57
- arrow::ipc::RecordBatchStreamReader::Open (input_stream),
58
- error::IPC_RECORD_BATCH_READER_OPEN_FAILED);
57
+ MATLAB_ASSIGN_OR_ERROR (auto reader,
58
+ arrow::ipc::RecordBatchStreamReader::Open (input_stream),
59
+ error::IPC_RECORD_BATCH_READER_OPEN_FAILED);
59
60
60
- return std::make_shared<RecordBatchStreamReaderProxy>(std::move (reader));
61
+ return std::make_shared<RecordBatchStreamReaderProxy>(std::move (reader));
61
62
}
62
63
63
- libmexclass::proxy::MakeResult RecordBatchStreamReader::fromBytes (const libmexclass::proxy::FunctionArguments& constructor_arguments) {
64
- namespace mda = ::matlab::data;
65
- using RecordBatchStreamReaderProxy =
66
- arrow::matlab::io::ipc::proxy::RecordBatchStreamReader;
67
-
68
- const mda::StructArray opts = constructor_arguments[0 ];
69
- const ::matlab::data::TypedArray<uint8_t > bytes_mda = opts[0 ][" Bytes" ];
70
- const auto matlab_buffer = std::make_shared<arrow::matlab::buffer::MatlabBuffer>(bytes_mda);
71
- auto buffer_reader = std::make_shared<arrow::io::BufferReader>(matlab_buffer);
72
- MATLAB_ASSIGN_OR_ERROR (auto reader,
73
- arrow::ipc::RecordBatchStreamReader::Open (buffer_reader),
74
- error::IPC_RECORD_BATCH_READER_OPEN_FAILED);
75
- return std::make_shared<RecordBatchStreamReaderProxy>(std::move (reader));
64
+ libmexclass::proxy::MakeResult RecordBatchStreamReader::fromBytes (
65
+ const libmexclass::proxy::FunctionArguments& constructor_arguments) {
66
+ namespace mda = ::matlab::data;
67
+ using RecordBatchStreamReaderProxy =
68
+ arrow::matlab::io::ipc::proxy::RecordBatchStreamReader;
69
+
70
+ const mda::StructArray opts = constructor_arguments[0 ];
71
+ const ::matlab::data::TypedArray<uint8_t > bytes_mda = opts[0 ][" Bytes" ];
72
+ const auto matlab_buffer =
73
+ std::make_shared<arrow::matlab::buffer::MatlabBuffer>(bytes_mda);
74
+ auto buffer_reader = std::make_shared<arrow::io::BufferReader>(matlab_buffer);
75
+ MATLAB_ASSIGN_OR_ERROR (auto reader,
76
+ arrow::ipc::RecordBatchStreamReader::Open (buffer_reader),
77
+ error::IPC_RECORD_BATCH_READER_OPEN_FAILED);
78
+ return std::make_shared<RecordBatchStreamReaderProxy>(std::move (reader));
76
79
}
77
80
78
81
libmexclass::proxy::MakeResult RecordBatchStreamReader::make (
79
82
const libmexclass::proxy::FunctionArguments& constructor_arguments) {
80
- namespace mda = ::matlab::data;
83
+ namespace mda = ::matlab::data;
81
84
const mda::StructArray opts = constructor_arguments[0 ];
82
85
83
86
// Dispatch to the appropriate static "make" method depending
84
87
// on the input type.
85
88
const mda::StringArray type_mda = opts[0 ][" Type" ];
86
89
const auto type_utf16 = std::u16string (type_mda[0 ]);
87
90
if (type_utf16 == u" Bytes" ) {
88
- return RecordBatchStreamReader::fromBytes (constructor_arguments);
91
+ return RecordBatchStreamReader::fromBytes (constructor_arguments);
89
92
} else if (type_utf16 == u" File" ) {
90
- return RecordBatchStreamReader::fromFile (constructor_arguments);
93
+ return RecordBatchStreamReader::fromFile (constructor_arguments);
91
94
} else {
92
- return libmexclass::error::Error{" arrow:io:ipc:InvalidConstructionType" , " Invalid construction type for RecordBatchStreamReader." };
95
+ return libmexclass::error::Error{
96
+ " arrow:io:ipc:InvalidConstructionType" ,
97
+ " Invalid construction type for RecordBatchStreamReader." };
93
98
}
94
99
}
95
100
0 commit comments