aboutsummaryrefslogtreecommitdiff
path: root/gnu/gnunet/util/struct.scm
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-02-17 21:03:47 +0100
committerMaxime Devos <maximedevos@telenet.be>2021-09-21 12:08:35 +0200
commit6d35e88e79d42de2f02ce77554bda1d14e513127 (patch)
tree43c066034e929b8516f95cb7d89f90b9418ea106 /gnu/gnunet/util/struct.scm
parent66286858b7f677bf6cdfcd97be5b02e322842013 (diff)
downloadgnunet-scheme-6d35e88e79d42de2f02ce77554bda1d14e513127.tar.gz
gnunet-scheme-6d35e88e79d42de2f02ce77554bda1d14e513127.zip
Implement self-documenting ‘network structures’
In contrast to scheme-bytestructures and (gnu gnunet utils netstruct), this allows associating a synopsis, a documention string (docstring) and arbitrary properties with structures and fields. Code compilation should be faster now as well and the compiled '.go' should be smaller due to less excessive use of syntax-rules. TODO: update old modules * Makefile.am (modules): compile new modules gnu/gnunet/netstruct/procedural.scm and gnu/gnunet/netstruct/syntactic.scm. * README.org (Network Structures): document new modules. * gnu/gnunet/crypto/struct.scm: use new module. * gnu/gnunet/hashcode/struct.scm: likewise. * gnu/gnunet/nse/struct.scm: likewise. * gnu/gnunet/util/struct.scm: likewise. * gnu/gnunet/netstruct/procedural.scm: new module for defining and using network structures procedurally. * gnu/gnunet/netstruct/syntactic.scm: likewise, but syntactically and with some inlining.
Diffstat (limited to 'gnu/gnunet/util/struct.scm')
-rw-r--r--gnu/gnunet/util/struct.scm69
1 files changed, 39 insertions, 30 deletions
diff --git a/gnu/gnunet/util/struct.scm b/gnu/gnunet/util/struct.scm
index 46323af..abec52b 100644
--- a/gnu/gnunet/util/struct.scm
+++ b/gnu/gnunet/util/struct.scm
@@ -20,41 +20,50 @@
20;; Brief: many network structures, that would otherwise result in very 20;; Brief: many network structures, that would otherwise result in very
21;; small source files if each was put in their own module. 21;; small source files if each was put in their own module.
22(define-library (gnu gnunet util struct) 22(define-library (gnu gnunet util struct)
23 (export /:message-header /:operation-result) 23 (export /uuid
24 (import (gnu gnunet utils netstruct) 24 /:message-header /:operation-result /async-scope-id)
25 (only (rnrs base) begin define-syntax)) 25 (import (only (gnu gnunet netstruct syntactic)
26 define-type structure/packed)
27 (only (gnu gnunet netstruct procedural)
28 u8vector u16/big u32/big u64/big)
29 (only (rnrs base) begin))
26 (begin 30 (begin
27 ; A UUID, a 128 bit random value 31 (define-type /uuid
28 (define-syntax /uuid
29 (structure/packed 32 (structure/packed
30 ;; 128 random bits 33 (synopsis "A UUID, a 128 bit random value")
31 ;; (This is represented as an array of uint32 in GNUnet) 34 (field (value/u8 (u8vector 16))
32 ("value/u8" (u8vector 16)))) 35 (synopsis "128 random bits")
36 (documentation
37 "This is represented as an array of uint32 in GNUnet"))))
33 38
34 ;; Header for all communications. 39 (define-type /:message-header
35 (define-syntax /:message-header
36 (structure/packed 40 (structure/packed
37 ;; The length of the struct (in bytes, including the length field itself), 41 (synopsis "Header for all communications")
38 ;; in big-endian format. 42 (field (size u16/big)
39 ("size" u16/big) 43 (documentation
40 ;; The type of the message (GNUNET_MESSAGE_TYPE_XXXX in the C 44 "The length of the struct (in bytes, including the length
41 ;; implementation and msg:XXX:YYY:... in the Scheme implementation), 45field itself), in big-endian format."))
42 ;; in big-endian format. 46 (field (type u16/big)
43 ("type" u16/big))) 47 (synopsis "The type of the message")
48 (documentation
49 "The type of the message (GNUNET_MESSAGE_TYPE_XXXX in the C
50implementation and msg:XXX:YYY:... in the Scheme implementation),
51in big-endian format."))))
44 52
45 ;; Answer from service to client about last operation. 53 (define-type /:operation-result
46 ;; Possibly followed by data.
47 (define-syntax /:operation-result
48 (structure/packed 54 (structure/packed
49 ("header" /:message-header) 55 (synopsis "Answer from service to client about last operation")
50 ("reserved" u32/big) 56 (documentation "Possibly followed by data")
51 ;; Operation ID. 57 (field (header /:message-header))
52 ("operation-id" u64/big) 58 (field (reserved u32/big))
53 ;; Status code for the operation. 59 (field (operation-id u64/big)
54 ("result-code" u64/big))) 60 (synopsis "Operation ID"))
61 (field (result-code u64/big)
62 (synopsis "Status code for the operation"))))
55 63
56 ;; Identifier for an asynchronous execution context. 64 (define-type /async-scope-id
57 (define-syntax /:async-scope-id
58 (structure/packed 65 (structure/packed
59 ;; This is represented as an array of uint32_t in GNUnet. 66 (synopsis "Identifier for an asynchronous execution context")
60 ("bits/u8" (u8vector 16)))))) 67 (documentation
68 "This is represented as an array of uint32_t in GNUnet.")
69 (field (bits/u8 (u8vector 16)))))))