1.1 --- a/vint.pyx Thu Sep 17 20:10:31 2009 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,46 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"""
1.7 -A variable-length integer encoding implementation in Pyrex.
1.8 -
1.9 -Copyright (C) 2009 Paul Boddie <paul@boddie.org.uk>
1.10 -
1.11 -This program is free software; you can redistribute it and/or modify it under
1.12 -the terms of the GNU General Public License as published by the Free Software
1.13 -Foundation; either version 3 of the License, or (at your option) any later
1.14 -version.
1.15 -
1.16 -This program is distributed in the hope that it will be useful, but WITHOUT ANY
1.17 -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
1.18 -PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.19 -
1.20 -You should have received a copy of the GNU General Public License along
1.21 -with this program. If not, see <http://www.gnu.org/licenses/>.
1.22 -"""
1.23 -
1.24 -cdef extern from "Python.h":
1.25 - object PyString_FromStringAndSize(char *, int)
1.26 -
1.27 -def vint(int number):
1.28 -
1.29 - cdef char bytes[40] # NOTE: Arbitrary limit.
1.30 - cdef int lsd, i
1.31 -
1.32 - if number < 128:
1.33 - bytes[0] = number
1.34 - s = PyString_FromStringAndSize(bytes, 1)
1.35 - return s
1.36 -
1.37 - i = 0
1.38 - while number != 0:
1.39 - lsd = number & 127
1.40 - number = number >> 7
1.41 - if number != 0:
1.42 - lsd = lsd | 128
1.43 - bytes[i] = lsd
1.44 - i = i + 1
1.45 -
1.46 - s = PyString_FromStringAndSize(bytes, i)
1.47 - return s
1.48 -
1.49 -# vim: tabstop=4 expandtab shiftwidth=4