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 LongTranscoder extends SpyObject |
12 | implements Transcoder<Long> { |
13 | |
14 | private static final int flags = SerializingTranscoder.SPECIAL_LONG; |
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.Long l) { |
23 | return new CachedData(flags, tu.encodeLong(l), getMaxSize()); |
24 | } |
25 | |
26 | public Long decode(CachedData d) { |
27 | if (flags == d.getFlags()) { |
28 | return tu.decodeLong(d.getData()); |
29 | } else { |
30 | getLogger().error("Unexpected flags for long: " |
31 | + d.getFlags() + " wanted " + flags); |
32 | return null; |
33 | } |
34 | } |
35 | |
36 | public int getMaxSize() { |
37 | return CachedData.MAX_SIZE; |
38 | } |
39 | |
40 | } |