]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/java/vector/src/main/java/org/apache/arrow/vector/ipc/message/MessageMetadataResult.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / vector / src / main / java / org / apache / arrow / vector / ipc / message / MessageMetadataResult.java
CommitLineData
1d09f67e
TL
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * 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, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package org.apache.arrow.vector.ipc.message;
19
20import java.nio.ByteBuffer;
21
22import org.apache.arrow.flatbuf.Message;
23
24/**
25 * Class to hold resulting Message metadata and buffer containing the serialized Flatbuffer
26 * message when reading messages from a ReadChannel. This handles Message metadata only and
27 * does not include the message body data, which should be subsequently read into an ArrowBuf.
28 */
29public class MessageMetadataResult {
30
31 /**
32 * Construct a container to hold a deserialized Message metadata, and buffer
33 * with the serialized Message as read from a ReadChannel.
34 *
35 * @param messageLength the length of the serialized Flatbuffer message in bytes
36 * @param messageBuffer contains the serialized Flatbuffer Message metadata
37 * @param message the deserialized Flatbuffer Message metadata description
38 */
39 MessageMetadataResult(int messageLength, ByteBuffer messageBuffer, Message message) {
40 this.messageLength = messageLength;
41 this.messageBuffer = messageBuffer;
42 this.message = message;
43 }
44
45 /**
46 * Creates a new {@link MessageMetadataResult} by parsing it from the beginning of the buffer.
47 *
48 * @param messageLength The length of the serialized flatbuffer message in bytes (might not be equal to the buffer
49 * size).
50 */
51 public static MessageMetadataResult create(ByteBuffer buffer, int messageLength) {
52 return new MessageMetadataResult(messageLength, buffer, Message.getRootAsMessage(buffer));
53 }
54
55 /**
56 * Get the length of the message metadata in bytes, not including the body length.
57 *
58 * @return number of bytes in the message metadata buffer.
59 */
60 public int getMessageLength() {
61 return messageLength;
62 }
63
64 /**
65 * Get the buffer containing the raw message metadata bytes, not including the message body data.
66 *
67 * @return buffer containing the message metadata.
68 */
69 public ByteBuffer getMessageBuffer() {
70 return messageBuffer;
71 }
72
73 /**
74 * Returns the bytes remaining in the buffer after parsing the message from it.
75 */
76 public int bytesAfterMessage() {
77 return message.getByteBuffer().remaining();
78 }
79
80 public byte headerType() {
81 return message.headerType();
82 }
83
84 /**
85 * Check if the message is followed by a body. This will be true if the message has a body
86 * length > 0, which indicates that a message body needs to be read from the input source.
87 *
88 * @return true if message has a defined body
89 */
90 public boolean messageHasBody() {
91 return message.bodyLength() > 0;
92 }
93
94 /**
95 * Get the length of the message body.
96 *
97 * @return number of bytes of the message body
98 */
99 public long getMessageBodyLength() {
100 return message.bodyLength();
101 }
102
103 /**
104 * Get the realized flatbuf Message metadata description.
105 *
106 * @return Message metadata
107 */
108 public Message getMessage() {
109 return message;
110 }
111
112 private final int messageLength;
113 private final ByteBuffer messageBuffer;
114 private final Message message;
115}