[C#] Add initial hooks, the C# code compiles, the C not at all
[ldk-java] / c_sharp / src / org / ldk / util / UInt.cs
1 using System;
2 using System.Linq;
3
4 namespace org { namespace ldk { namespace util {
5
6 /**
7  * A 5-bit unsigned integer
8  */
9 public class UInt5 {
10         byte val;
11         public UInt5(byte val) {
12                 if (val > 32 || val < 0) {
13                         throw new ArgumentException();
14                 }
15                 this.val = val;
16         }
17
18         /**
19          * @return the value represented
20          */
21         public byte getVal() {
22                 return val;
23         }
24 }
25
26 /**
27  * A 5-bit unsigned integer
28  */
29 public class UInt128 {
30         private byte[] le_bytes;
31
32         /**
33          * Constructs a 128-bit integer from its little-endian representation
34          */
35         public UInt128(byte[] le_bytes) {
36                 if (le_bytes.Length != 16) {
37                         throw new ArgumentException();
38                 }
39                 this.le_bytes = le_bytes;
40         }
41
42         /**
43          * Constructs a 128-bit integer from a long, ignoring the sign bit
44          */
45         public UInt128(long val) {
46                 byte[] le_bytes = new byte[16];
47                 for (int i = 0; i < 8; i++)
48                         le_bytes[i] = (byte) ((val >> i*8) & 0xff);
49                 this.le_bytes = le_bytes;
50         }
51
52         /**
53          * @return The value as 16 little endian bytes
54          */
55         public byte[] getLEBytes() { return le_bytes; }
56
57         public override bool Equals(object o) {
58                 if (o == null || !(o is UInt128)) return false;
59                 byte[] o_le_bytes = ((UInt128) o).le_bytes;
60                 return le_bytes.SequenceEqual(o_le_bytes);
61         }
62
63         public override int GetHashCode() { return le_bytes.GetHashCode(); }
64 }
65
66 } } }