diff --git a/cavis-datavec/dvec-api/src/main/java/net/brutex/cavis/dvec/api/FieldInterface.java b/cavis-datavec/dvec-api/src/main/java/net/brutex/cavis/dvec/api/FieldInterface.java new file mode 100644 index 000000000..92705bea8 --- /dev/null +++ b/cavis-datavec/dvec-api/src/main/java/net/brutex/cavis/dvec/api/FieldInterface.java @@ -0,0 +1,79 @@ +/* + * + * ****************************************************************************** + * * + * * This program and the accompanying materials are made available under the + * * terms of the Apache License, Version 2.0 which is available at + * * https://www.apache.org/licenses/LICENSE-2.0. + * * + * * See the NOTICE file distributed with this work for additional + * * information regarding copyright ownership. + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * * License for the specific language governing permissions and limitations + * * under the License. + * * + * * SPDX-License-Identifier: Apache-2.0 + * ***************************************************************************** + * + */ + +package net.brutex.cavis.dvec.api; + +import java.io.Serializable; +import java.nio.Buffer; +import java.nio.LongBuffer; +import java.util.List; +import net.brutex.cavis.dvec.api.exceptions.DVecException; + +/** + * A Field can be considered a "column" in a {@code Record}, as such a Field may refer to multiple + * entries of that "column". Fields are typed as Buffers. Some of them defined in the dvec core api, + * other (i.e. Image or Arrow) require dvec extensions accordingly. + * + * @author Brian Rosenberger + * @since 1.0 + */ +public interface FieldInterface extends Serializable { + + /** + * Get a reference to the metadata for this Field. + * + * @return the {@link FieldMetadata} + */ + FieldMetadata getFieldMetadata(); + + /** + * Get the 1st field as Buffer. This deserializes the data from the underlying storage. + * + * @return T underlying Buffer + */ + default T read() throws DVecException { + return read(0, 1); + } + + /** + * Get a range of fields as a {@code Buffer} + * + * @param start Index of starting position, zero based + * @param length how many fields to read + * @return the buffers + */ + T read(long start, long length) throws DVecException; + + /** + * Write the data into the underlying storage. + */ + default void write(T buffer) { + write(0, buffer); + } + + /** + * Write the data into the underyling storage starting at a position + * + * @param pos the position to start + */ + void write(long pos, T buffer); + +}