Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
message.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 // C++ object model and user API for interprocess schema messaging
19 
20 #ifndef ARROW_IPC_MESSAGE_H
21 #define ARROW_IPC_MESSAGE_H
22 
23 #include <cstdint>
24 #include <memory>
25 #include <string>
26 
27 #include "arrow/status.h"
28 #include "arrow/util/macros.h"
29 #include "arrow/util/visibility.h"
30 
31 namespace arrow {
32 
33 class Buffer;
34 
35 namespace io {
36 
37 class InputStream;
38 class OutputStream;
39 class RandomAccessFile;
40 
41 } // namespace io
42 
43 namespace ipc {
44 
45 enum class MetadataVersion : char {
47  V1,
48 
50  V2,
51 
53  V3,
54 
56  V4
57 };
58 
59 // ARROW-109: We set this number arbitrarily to help catch user mistakes. For
60 // deeply nested schemas, it is expected the user will indicate explicitly the
61 // maximum allowed recursion depth
62 constexpr int kMaxNestingDepth = 64;
63 
64 // Read interface classes. We do not fully deserialize the flatbuffers so that
65 // individual fields metadata can be retrieved from very large schema without
66 //
67 
70 class ARROW_EXPORT Message {
71  public:
72  enum Type { NONE, SCHEMA, DICTIONARY_BATCH, RECORD_BATCH, TENSOR };
73 
77  Message(const std::shared_ptr<Buffer>& metadata, const std::shared_ptr<Buffer>& body);
78 
79  ~Message();
80 
87  static Status Open(const std::shared_ptr<Buffer>& metadata,
88  const std::shared_ptr<Buffer>& body, std::unique_ptr<Message>* out);
89 
97  static Status ReadFrom(const std::shared_ptr<Buffer>& metadata, io::InputStream* stream,
98  std::unique_ptr<Message>* out);
99 
109  static Status ReadFrom(const int64_t offset, const std::shared_ptr<Buffer>& metadata,
110  io::RandomAccessFile* file, std::unique_ptr<Message>* out);
111 
116  bool Equals(const Message& other) const;
117 
121  std::shared_ptr<Buffer> metadata() const;
122 
126  std::shared_ptr<Buffer> body() const;
127 
129  Type type() const;
130 
132  MetadataVersion metadata_version() const;
133 
134  const void* header() const;
135 
141  Status SerializeTo(io::OutputStream* file, int64_t* output_length) const;
142 
143  private:
144  // Hide serialization details from user API
145  class MessageImpl;
146  std::unique_ptr<MessageImpl> impl_;
147 
149 };
150 
151 ARROW_EXPORT std::string FormatMessageType(Message::Type type);
152 
155 class ARROW_EXPORT MessageReader {
156  public:
157  virtual ~MessageReader() = default;
158 
160  static std::unique_ptr<MessageReader> Open(io::InputStream* stream);
161 
163  static std::unique_ptr<MessageReader> Open(
164  const std::shared_ptr<io::InputStream>& owned_stream);
165 
170  virtual Status ReadNextMessage(std::unique_ptr<Message>* message) = 0;
171 };
172 
187 ARROW_EXPORT
188 Status ReadMessage(const int64_t offset, const int32_t metadata_length,
189  io::RandomAccessFile* file, std::unique_ptr<Message>* message);
190 
196 ARROW_EXPORT
197 Status ReadMessage(io::InputStream* stream, bool aligned,
198  std::unique_ptr<Message>* message);
199 
204 ARROW_EXPORT
205 Status ReadMessage(io::InputStream* stream, std::unique_ptr<Message>* message);
206 
207 } // namespace ipc
208 } // namespace arrow
209 
210 #endif // ARROW_IPC_MESSAGE_H
Definition: interfaces.h:111
std::string FormatMessageType(Message::Type type)
Main data type enumeration.
Definition: type.h:45
An IPC message including metadata and body.
Definition: message.h:70
Definition: interfaces.h:116
Definition: interfaces.h:121
Status ReadMessage(const int64_t offset, const int32_t metadata_length, io::RandomAccessFile *file, std::unique_ptr< Message > *message)
Read encapsulated RPC message from position in file.
Definition: status.h:93
Type
Definition: message.h:72
Top-level namespace for Apache Arrow C++ API.
Definition: adapter.h:32
MetadataVersion
Definition: message.h:45
constexpr int kMaxNestingDepth
Definition: message.h:62
Abstract interface for a sequence of messages.
Definition: message.h:155
#define ARROW_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:23