1 | // Copyright (c) 2006 Dustin Sallings <dustin@spy.net> |
2 | |
3 | package net.spy.memcached.transcoders; |
4 | |
5 | import net.spy.memcached.CachedData; |
6 | import net.spy.memcached.compat.SpyObject; |
7 | |
8 | /** |
9 | * Transcoder that serializes and unserializes longs. |
10 | */ |
11 | public final class IntegerTranscoder extends SpyObject |
12 | implements Transcoder<Integer> { |
13 | |
14 | private static final int flags = SerializingTranscoder.SPECIAL_INT; |
15 | |
16 | private final TranscoderUtils tu=new TranscoderUtils(true); |
17 | |
18 | public boolean asyncDecode(CachedData d) { |
19 | return false; |
20 | } |
21 | |
22 | public CachedData encode(java.lang.Integer l) { |
23 | return new CachedData(flags, tu.encodeInt(l), getMaxSize()); |
24 | } |
25 | |
26 | public Integer decode(CachedData d) { |
27 | if (flags == d.getFlags()) { |
28 | return tu.decodeInt(d.getData()); |
29 | } else { |
30 | return null; |
31 | } |
32 | } |
33 | |
34 | public int getMaxSize() { |
35 | return CachedData.MAX_SIZE; |
36 | } |
37 | |
38 | } |