guile-netlink/netlink/standard.scm

standard.scm

1
;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu>
2
;;;; 
3
;;;; This library is free software; you can redistribute it and/or
4
;;;; modify it under the terms of the GNU Lesser General Public
5
;;;; License as published by the Free Software Foundation; either
6
;;;; version 3 of the License, or (at your option) any later version.
7
;;;; 
8
;;;; This library is distributed in the hope that it will be useful,
9
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
;;;; Lesser General Public License for more details.
12
;;;; 
13
;;;; You should have received a copy of the GNU Lesser General Public
14
;;;; License along with this library; if not, write to the Free Software
15
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
;;;; 
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 (pk 'error-mrg 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