diff options
Diffstat (limited to 'src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java')
-rw-r--r-- | src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java b/src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java deleted file mode 100644 index 5349f05..0000000 --- a/src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | package org.gnunet.construct.parsers; | ||
22 | |||
23 | import org.gnunet.construct.Message; | ||
24 | import org.gnunet.construct.ReflectUtil; | ||
25 | |||
26 | import java.lang.reflect.Field; | ||
27 | import java.nio.ByteBuffer; | ||
28 | import java.util.List; | ||
29 | |||
30 | public class FixedSizeByteArrayParser implements Parser { | ||
31 | private final int elemNumber; | ||
32 | private final Field targetField; | ||
33 | |||
34 | public FixedSizeByteArrayParser(int elemNumber, Field f) { | ||
35 | this.elemNumber = elemNumber; | ||
36 | this.targetField = f; | ||
37 | } | ||
38 | |||
39 | @Override | ||
40 | public int getSize(Message srcObj) { | ||
41 | return elemNumber; | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public int parse(ByteBuffer srcBuf, int frameStart, Message frameObj, Message dstObj, List<Field> frameSizePath) { | ||
46 | byte[] data = new byte[elemNumber]; | ||
47 | srcBuf.get(data); | ||
48 | ReflectUtil.justSet(dstObj, targetField, data); | ||
49 | return elemNumber; | ||
50 | } | ||
51 | |||
52 | @Override | ||
53 | public int write(ByteBuffer dstBuf, Message srcObj) { | ||
54 | byte[] data = (byte[]) ReflectUtil.justGet(srcObj, targetField); | ||
55 | if (data.length != elemNumber) { | ||
56 | throw new AssertionError("fixed size array has wrong size"); | ||
57 | } | ||
58 | dstBuf.put(data); | ||
59 | return elemNumber; | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public void patch(Message m, int frameSize, List<Field> frameSizePath, Message frameObj) { | ||
64 | // nothing to do | ||
65 | } | ||
66 | |||
67 | @Override | ||
68 | public int getStaticSize() { | ||
69 | return elemNumber; | ||
70 | } | ||
71 | } | ||