Skip to content

Commit

Permalink
fix PYFB-22
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Makowski committed Oct 10, 2012
1 parent c49de5d commit 0c3c629
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions fdb/fbcore.py
Expand Up @@ -391,53 +391,53 @@ def inc_pointer(pointer):
def bytes_to_bint(b): # Read as big endian
len_b = len(b)
if len_b == 1:
fmt = 'b'
fmt = 'B'
elif len_b == 2:
fmt = '>h'
fmt = '>H'
elif len_b == 4:
fmt = '>l'
fmt = '>L'
elif len_b == 8:
fmt = '>q'
fmt = '>Q'
else:
raise InternalError
return struct.unpack(fmt, b)[0]

def bytes_to_int(b): # Read as little endian.
len_b = len(b)
if len_b == 1:
fmt = 'b'
fmt = 'B'
elif len_b == 2:
fmt = '<h'
fmt = '<H'
elif len_b == 4:
fmt = '<l'
fmt = '<L'
elif len_b == 8:
fmt = '<q'
fmt = '<Q'
else:
raise InternalError
return struct.unpack(fmt, b)[0]

def bint_to_bytes(val, nbytes): # Convert int value to big endian bytes.
if nbytes == 1:
fmt = 'b'
fmt = 'B'
elif nbytes == 2:
fmt = '>h'
fmt = '>H'
elif nbytes == 4:
fmt = '>l'
fmt = '>L'
elif nbytes == 8:
fmt = '>q'
fmt = '>Q'
else:
raise InternalError
return struct.pack(fmt, val)

def int_to_bytes(val, nbytes): # Convert int value to little endian bytes.
if nbytes == 1:
fmt = 'b'
fmt = 'B'
elif nbytes == 2:
fmt = '<h'
fmt = '<H'
elif nbytes == 4:
fmt = '<l'
fmt = '<L'
elif nbytes == 8:
fmt = '<q'
fmt = '<Q'
else:
raise InternalError
return struct.pack(fmt, val)
Expand Down

0 comments on commit 0c3c629

Please sign in to comment.