From 0d268c5d701423b770b05ed208461c47709dafb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 29 Jan 2017 12:55:24 +0100 Subject: store: Add 'add-data-to-store'. * guix/serialization.scm (write-bytevector): New procedure. (write-string): Rewrite in terms of 'write-bytevector'. * guix/store.scm (write-arg): Add 'bytevector' case. (add-data-to-store): New procedure, from former 'add-text-to-store'. (add-text-to-store): Rewrite in terms of 'add-data-to-store'. * tests/store.scm ("add-data-to-store"): New test. --- guix/serialization.scm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'guix/serialization.scm') diff --git a/guix/serialization.scm b/guix/serialization.scm index 5953b84616..4cab5910f7 100644 --- a/guix/serialization.scm +++ b/guix/serialization.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -30,7 +30,7 @@ #:export (write-int read-int write-long-long read-long-long write-padding - write-string + write-bytevector write-string read-string read-latin1-string read-maybe-utf8-string write-string-list read-string-list write-string-pairs @@ -102,15 +102,17 @@ (or (zero? m) (put-bytevector p zero 0 (- 8 m))))))) -(define (write-string s p) - (let* ((s (string->utf8 s)) - (l (bytevector-length s)) +(define (write-bytevector s p) + (let* ((l (bytevector-length s)) (m (modulo l 8)) (b (make-bytevector (+ 8 l (if (zero? m) 0 (- 8 m)))))) (bytevector-u32-set! b 0 l (endianness little)) (bytevector-copy! s 0 b 8 l) (put-bytevector p b))) +(define (write-string s p) + (write-bytevector (string->utf8 s) p)) + (define (read-byte-string p) (let* ((len (read-int p)) (m (modulo len 8)) -- cgit v1.2.3