001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.io.network.naming.serialization; 020 021import org.apache.reef.wake.remote.Codec; 022 023/** 024 * naming registration response codec. 025 */ 026public class NamingRegisterResponseCodec implements Codec<NamingRegisterResponse> { 027 private final NamingRegisterRequestCodec codec; 028 029 /** 030 * Constructs a naming register response codec. 031 * 032 * @param codec the naming register request codec 033 */ 034 public NamingRegisterResponseCodec(final NamingRegisterRequestCodec codec) { 035 this.codec = codec; 036 } 037 038 /** 039 * Encodes a naming register response to bytes. 040 * 041 * @param obj the naming register response 042 * @return bytes a byte array 043 */ 044 @Override 045 public byte[] encode(final NamingRegisterResponse obj) { 046 return codec.encode(obj.getRequest()); 047 } 048 049 /** 050 * Decodes a naming register response from the bytes. 051 * 052 * @param buf the byte array 053 * @return a naming register response 054 */ 055 @Override 056 public NamingRegisterResponse decode(final byte[] buf) { 057 return new NamingRegisterResponse(codec.decode(buf)); 058 } 059 060}