InstanceTableSerializer.java |
/* Copyright (C) 2009 CSE,IIT Bombay http://www.cse.iitb.ac.in This file is part of the ConStore open source storage facility for concept-nets. ConStore is free software and distributed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License; you can copy, distribute and transmit the work with the work attribution in the manner specified by the author or licensor. You may not use this work for commercial purposes and may not alter, transform, or build upon this work. Please refer the legal code of the license, available at http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode ConStore is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ package iitb.con.ds; import java.nio.ByteBuffer; /** * InstanceSerializer serializes <tt>InstanceMetaItem</tt> to bytes and vice versa * * @author Prathab K * @see InstanceMetaItem */ public class InstanceTableSerializer implements ItemSerializer<InstanceMetaItem> { /** * Serializes <tt>InstanceMetaItem</tt> to bytes * @param instanceMetaIteam InstanceMetaItem * @return serialized <tt>InstanceMetaItem</tt> as {@link ByteBuffer} */ public ByteBuffer serialize(InstanceMetaItem instanceMetaIteam) { InstanceMetaItem item = (InstanceMetaItem) instanceMetaIteam; ByteBuffer buf = ByteBuffer.allocate(InstanceMetaItem.headerSize()); buf.putShort(item.typeId); buf.putShort(item.clusterId); buf.putInt(item.instanceId); buf.putLong(item.location); buf.putInt(item.size); return buf; } /** * Deserializes the given bytes as <tt>InstanceMetaItem</tt> * @param buf bytes as {@link ByteBuffer} * @return deserialized bytes as <tt>InstanceMetaItem</tt> */ public InstanceMetaItem deSerialize(ByteBuffer buf) { InstanceMetaItem item = new InstanceMetaItem(); buf.position(0); item.typeId = buf.getShort(); item.clusterId = buf.getShort(); item.instanceId = buf.getInt(); item.location = buf.getLong(); item.size = buf.getInt(); return item; } /** * Deserializes the given bytes to object * @param buf bytes as {@link ByteBuffer} * @param name attribute name * @return deserialized attribute value as <tt>Object</tt> */ public Object attributeDeSerialize(ByteBuffer buf, Object name) { return null; } }