guile-netlink/netlink/standard.scm

standard.scm

1
;;;; This file is part of Guile Netlink
2
;;;;
3
;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu>
4
;;;; 
5
;;;; This library is free software: you can redistribute it and/or modify
6
;;;; it under the terms of the GNU General Public License as published by
7
;;;; the Free Software Foundation, either version 3 of the License, or
8
;;;; (at your option) any later version.
9
;;;;
10
;;;; This library is distributed in the hope that it will be useful,
11
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;;;; GNU General Public License for more details.
14
;;;;
15
;;;; You should have received a copy of the GNU General Public License
16
;;;; along with this library.  If not, see <https://www.gnu.org/licenses/>.
17
18
(define-module (netlink standard)
19
  #:use-module (ice-9 match)
20
  #:use-module (netlink data)
21
  #:use-module (netlink message)
22
  #:use-module (srfi srfi-9)
23
  #:use-module (rnrs bytevectors)
24
  #:export (make-error-message
25
            error-message?
26
            error-message-hdr
27
            error-message-err
28
            deserialize-error-message
29
            no-data
30
            deserialize-no-data))
31
32
(define-data-type error-message
33
  (lambda (msg)
34
    (+ 4 (data-size (error-message-type-hdr msg))))
35
  (lambda (msg pos bv)
36
    (match msg
37
     (($ error-message-type err hdr)
38
      (bytevector-s32-set! bv pos err (native-endianness))
39
      (serialize hdr (+ 4 pos) bv))))
40
  (err error-message-err error-message-type-err)
41
  (hdr error-message-hdr error-message-type-hdr))
42
43
(define (deserialize-error-message decoder bv pos)
44
  (make-error-message
45
    (bytevector-s32-ref bv pos (native-endianness))
46
    (deserialize 'message-hdr decoder bv (+ pos 4))))
47
48
(define no-data
49
  (make-nl-data
50
    #f
51
    (const 0)
52
    (const (make-bytevector 0))))
53
54
(define (deserialize-no-data decoder bv pos)
55
  no-data)
56