aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/gnunet/construct/parsers/Parser.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/gnunet/construct/parsers/Parser.java')
-rw-r--r--src/main/java/org/gnunet/construct/parsers/Parser.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/construct/parsers/Parser.java b/src/main/java/org/gnunet/construct/parsers/Parser.java
new file mode 100644
index 0000000..3eb02a6
--- /dev/null
+++ b/src/main/java/org/gnunet/construct/parsers/Parser.java
@@ -0,0 +1,78 @@
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
21package org.gnunet.construct.parsers;
22
23import org.gnunet.construct.Message;
24
25import java.lang.reflect.Field;
26import java.nio.ByteBuffer;
27import java.util.List;
28
29
30public interface Parser {
31 /**
32 * Compute the exact size of the object's binary representation in bytes.
33 *
34 * @param srcObj a message object with all fields filled out appropriately
35 * @return the exact size of the object's binary representation in bytes
36 */
37 public int getSize(Message srcObj);
38
39
40 /**
41 * Parse from a ByteBuffer into a destination object.
42 *
43 * @param srcBuf the buffer containing the binary data to construct this object
44 * @param frameStart start of the current frame, relative to the beginning of srcBuf
45 * @param frameObj the object containing the dstObj, dstObj if dstObj itself is the frame object
46 * @param dstObj the object whose members are written according according to the data in srcBuf
47 * @param frameSizePath
48 * @return number of byres read from srcBuf
49 */
50 public int parse(ByteBuffer srcBuf, int frameStart, Message frameObj, Message dstObj, List<Field> frameSizePath);
51
52 /**
53 *
54 * @param dstBuf destination buffer for the binary representation of the object
55 * @param srcObj object to serialize to binary form
56 * @return number of bytes written to buf (todo: we are using a ByteBuffer now, this is obsolete)
57 */
58 public int write(ByteBuffer dstBuf, Message srcObj);
59
60 /**
61 * Parser-dependent method; sets members of the Message m (or Messages nested in m) which are
62 * values inferable by the parser.
63 * Examples: Union tags, size fields.
64 *
65 * @param m the message object to patch
66 * @param frameSize the size of the containing message
67 * @param frameSizePath
68 * @param frameObj the object containing the message (and possibly size fields)
69 */
70 public void patch(Message m, int frameSize, List<Field> frameSizePath, Message frameObj);
71
72 /**
73 * Return a lower bound for the size of the message in bytes
74 *
75 * @return minimum static size of the message in bytes
76 */
77 int getStaticSize();
78}