]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/vector/src/main/java/org/apache/arrow/vector/ipc/message/MessageMetadataResult.java
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.arrow
.vector
.ipc
.message
;
20 import java
.nio
.ByteBuffer
;
22 import org
.apache
.arrow
.flatbuf
.Message
;
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.
29 public class MessageMetadataResult
{
32 * Construct a container to hold a deserialized Message metadata, and buffer
33 * with the serialized Message as read from a ReadChannel.
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
39 MessageMetadataResult(int messageLength
, ByteBuffer messageBuffer
, Message message
) {
40 this.messageLength
= messageLength
;
41 this.messageBuffer
= messageBuffer
;
42 this.message
= message
;
46 * Creates a new {@link MessageMetadataResult} by parsing it from the beginning of the buffer.
48 * @param messageLength The length of the serialized flatbuffer message in bytes (might not be equal to the buffer
51 public static MessageMetadataResult
create(ByteBuffer buffer
, int messageLength
) {
52 return new MessageMetadataResult(messageLength
, buffer
, Message
.getRootAsMessage(buffer
));
56 * Get the length of the message metadata in bytes, not including the body length.
58 * @return number of bytes in the message metadata buffer.
60 public int getMessageLength() {
65 * Get the buffer containing the raw message metadata bytes, not including the message body data.
67 * @return buffer containing the message metadata.
69 public ByteBuffer
getMessageBuffer() {
74 * Returns the bytes remaining in the buffer after parsing the message from it.
76 public int bytesAfterMessage() {
77 return message
.getByteBuffer().remaining();
80 public byte headerType() {
81 return message
.headerType();
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.
88 * @return true if message has a defined body
90 public boolean messageHasBody() {
91 return message
.bodyLength() > 0;
95 * Get the length of the message body.
97 * @return number of bytes of the message body
99 public long getMessageBodyLength() {
100 return message
.bodyLength();
104 * Get the realized flatbuf Message metadata description.
106 * @return Message metadata
108 public Message
getMessage() {
112 private final int messageLength
;
113 private final ByteBuffer messageBuffer
;
114 private final Message message
;