001/* 002 * This file is part of the Kompics component model runtime. 003 * 004 * Copyright (C) 2009 Swedish Institute of Computer Science (SICS) 005 * Copyright (C) 2009 Royal Institute of Technology (KTH) 006 * 007 * This program is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU General Public License 009 * as published by the Free Software Foundation; either version 2 010 * of the License, or (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with this program; if not, write to the Free Software 019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 020 */ 021package se.sics.kompics.network.netty.serialization; 022 023import java.util.Optional; 024import io.netty.buffer.ByteBuf; 025 026/** 027 * 028 * @author Lars Kroll {@literal <[email protected]>} 029 */ 030public interface Serializer { 031 /* 032 * Unique ID to differentiate the serializer from others over the network. 033 * 034 * Identifiers 1-16 are reserved for internal use. 035 * 036 * Make sure to configure serializers to use enough bytes for your ID to be uniqe! 037 */ 038 public int identifier(); 039 040 /** 041 * Serialize o into buf. 042 * 043 * @param o 044 * @param buf 045 */ 046 public void toBinary(Object o, ByteBuf buf); 047 048 /** 049 * Deserialize from buf. Optionally use hint to decide what to deserialize. 050 * 051 * @param buf 052 * @param hint 053 * @return 054 */ 055 public Object fromBinary(ByteBuf buf, Optional<Object> hint); // see comment at Serializers.fromBinary 056}