summaryrefslogtreecommitdiff
path: root/src/big_endian.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-07-08 12:30:21 +0800
committerJSDurand <mmemmew@gmail.com>2023-07-08 12:31:13 +0800
commit9a317e56f8a6126583f7d0c431bf878d9b1fe7b1 (patch)
tree7bb6004196b38446a5ab0cb3a0ab642d35f113e9 /src/big_endian.c
parent691f969eb104fa3d4c2a1667693fd0382eb9d6b5 (diff)
Finished the Emacs binding.
Now the binding part is finished. What remains is a bug encountered when planting a fragment to the forest which intersects a packed node, which would lead to invalid forests. This will also cause problem when planting a packed fragment, but until now my testing grammars do not produce packed fragments, so this problem is not encountered yet. I am still figuring out efficient ways to solve this problem.
Diffstat (limited to 'src/big_endian.c')
-rw-r--r--src/big_endian.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/big_endian.c b/src/big_endian.c
new file mode 100644
index 0000000..2db8624
--- /dev/null
+++ b/src/big_endian.c
@@ -0,0 +1,28 @@
+#include "big_endian.h"
+
+void to_big_endian(uint64_t num, unsigned char *result)
+{
+ *(result+0) = (num >> 56) & 0xff;
+ *(result+1) = (num >> 48) & 0xff;
+ *(result+2) = (num >> 40) & 0xff;
+ *(result+3) = (num >> 32) & 0xff;
+ *(result+4) = (num >> 24) & 0xff;
+ *(result+5) = (num >> 16) & 0xff;
+ *(result+6) = (num >> 8) & 0xff;
+ *(result+7) = (num >> 0) & 0xff;
+}
+
+uint64_t from_big_endian(unsigned char *num)
+{
+ uint64_t result = ((uint64_t) (*num) << 56);
+
+ result += ((uint64_t) (*(num+1)) << 48);
+ result += ((uint64_t) (*(num+2)) << 40);
+ result += ((uint64_t) (*(num+3)) << 32);
+ result += ((uint64_t) (*(num+4)) << 24);
+ result += ((uint64_t) (*(num+5)) << 16);
+ result += ((uint64_t) (*(num+6)) << 8);
+ result += ((uint64_t) (*(num+7)) << 0);
+
+ return result;
+}