Yuta HIGUCHI | ea15015 | 2014-10-28 22:55:14 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.store.serializers; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkNotNull; |
| 4 | |
| 5 | import com.google.common.base.Function; |
| 6 | |
| 7 | /** |
| 8 | * Function to convert byte[] into {@code T}. |
| 9 | * |
| 10 | * @param <T> Type after decoding |
| 11 | */ |
| 12 | public final class DecodeTo<T> implements Function<byte[], T> { |
| 13 | |
| 14 | private StoreSerializer serializer; |
| 15 | |
| 16 | public DecodeTo(StoreSerializer serializer) { |
| 17 | this.serializer = checkNotNull(serializer); |
| 18 | } |
| 19 | |
| 20 | @Override |
| 21 | public T apply(byte[] input) { |
| 22 | return serializer.decode(input); |
| 23 | } |
| 24 | } |