001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.kahadb.util; 018 019import java.io.DataInput; 020import java.io.DataOutput; 021import java.io.IOException; 022 023/** 024 * 025 */ 026public interface Marshaller<T> { 027 028 /** 029 * Write the payload of the object to the DataOutput stream. 030 * 031 * @param object 032 * @param dataOut 033 * @throws IOException 034 */ 035 void writePayload(T object, DataOutput dataOut) throws IOException; 036 037 038 /** 039 * Read the payload of the object from the DataInput stream. 040 * 041 * @param dataIn 042 * @return unmarshalled object 043 * @throws IOException 044 */ 045 T readPayload(DataInput dataIn) throws IOException; 046 047 /** 048 * @return -1 if the object do not always marshall to a fixed size, otherwise return that fixed size. 049 */ 050 int getFixedSize(); 051 052 /** 053 * 054 * @return true if the {@link #deepCopy(Object)} operations is supported. 055 */ 056 boolean isDeepCopySupported(); 057 058 /** 059 * @return a deep copy of the source object. 060 */ 061 T deepCopy(T source); 062 063}