gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r2906 - freeway/src/org/gnu/freeway/cwrappers


From: mdonoughe
Subject: [GNUnet-SVN] r2906 - freeway/src/org/gnu/freeway/cwrappers
Date: Fri, 26 May 2006 11:49:25 -0700 (PDT)

Author: mdonoughe
Date: 2006-05-26 11:49:23 -0700 (Fri, 26 May 2006)
New Revision: 2906

Added:
   freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java
   freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java
Log:
Constant varients of CInt and CUnsignedInt.



Added: freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java        2006-05-26 
18:40:53 UTC (rev 2905)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java        2006-05-26 
18:49:23 UTC (rev 2906)
@@ -0,0 +1,56 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers;
+
+import org.gnu.freeway.cwrappers.util.CWrapper;
+
+/**
+ * @file freeway/src/org/gnu/freeway/cwrappers/ConstCInt.java
+ * @brief A wrapper for using constant integers with JNI
+ * @author mdonoughe
+ */
+public class ConstCInt implements CWrapper {
+
+       private int value;
+       
+       public ConstCInt(int value) {
+               this.value = value;
+       }
+       
+       /**
+        * Returns a byte array containing the integer in big endian format
+        */
+       public byte[] serializeToByteArray() {
+               byte[] retValue = {(byte) (value >> 24), (byte) (value >> 16), 
(byte) (value >> 8), (byte) value};
+               return retValue;
+       }
+
+       public void deserializeFromByteArray(byte[] serializedData) {
+               return; // this is a constant type
+       }
+
+       public int getValue() {
+               return value;
+       }
+
+       public int getSerializedSize() {
+               return 4;
+       }
+}

Added: freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java        
2006-05-26 18:40:53 UTC (rev 2905)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java        
2006-05-26 18:49:23 UTC (rev 2906)
@@ -0,0 +1,75 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers;
+
+import org.gnu.freeway.cwrappers.util.CWrapper;
+
+/**
+ * @file freeway/src/org/gnu/freeway/cwrappers/ConstCUnsignedInt.java
+ * @brief A wrapper for using constant unsigned integers with JNI
+ * @author mdonoughe
+ */
+public class ConstCUnsignedInt implements CWrapper {
+
+       private long value;
+       
+       public ConstCUnsignedInt(long value) {
+               validate(value);
+               this.value = value;
+       }
+       
+       private void validate(long value) {
+               if(value < 0 || value > 4294967295l)
+                       throw new IllegalArgumentException("Unsigned integers 
cannot be less than 0 or more than 4,294,967,295.");
+               return;
+       }
+       
+       /**
+        * Returns a byte array containing the integer in big endian format
+        */
+       public byte[] serializeToByteArray() {
+               byte[] retValue = {(byte) (value >> 24), (byte) (value >> 16), 
(byte) (value >> 8), (byte) value};
+               return retValue;
+       }
+
+       public void deserializeFromByteArray(byte[] serializedData) {
+               return; // this is a constant type
+       }
+
+       public long getValue() {
+               return value;
+       }
+
+       public int getSerializedSize() {
+               return 4;
+       }
+       
+       public static ConstCUnsignedInt boxSignedInt(int value) {
+               return new ConstCUnsignedInt(unsignedIntToLong(value));
+       }
+       
+       public static long unsignedIntToLong(int value) {
+               return value & 0xFFFFFFFFl;
+       }
+       
+       public static int longToUnsignedInt(long value) {
+               return (int) (value & 0xFFFFFFFFl);
+       }
+}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]