# Path: btchip/btchipException.py
# class BTChipException(Exception):
# 
# 	def __init__(self, message, sw=0x6f00):
# 		self.message = message
# 		self.sw = sw
# 
# 	def __str__(self):
# 		buf = "Exception : " + self.message
# 		return buf


from .btchipException import BTChipException
		varintSize = 5
	else:
		raise BTChipException("unsupported varint")
	return { "value": value, "size": varintSize }

def writeVarint(value, buffer):
	if (value < 0xfd):
		buffer.append(value)
	elif (value <= 0xffff):
		buffer.append(0xfd)
		buffer.append(value & 0xff)
		buffer.append((value >> 8) & 0xff)
	elif (value <= 0xffffffff):
		buffer.append(0xfe)
		buffer.append(value & 0xff)
		buffer.append((value >> 8) & 0xff)
		buffer.append((value >> 16) & 0xff)
		buffer.append((value >> 24) & 0xff)
	else:
		raise BTChipException("unsupported encoding")
	return buffer

def getVarintSize(value):
	if (value < 0xfd):
		return 1
	elif (value <= 0xffff):
		return 3
	elif (value <= 0xffffffff):
		return 5
	else:

# Path: btchip/btchipException.py
# class BTChipException(Exception):
# 
# 	def __init__(self, message, sw=0x6f00):
# 		self.message = message
# 		self.sw = sw
# 
# 	def __str__(self):
# 		buf = "Exception : " + self.message
# 		return buf


# Path: btchip/bitcoinVarint.py
from .btchipException import BTChipException

		varintSize = 5
	else:
		raise BTChipException("unsupported varint")
	return { "value": value, "size": varintSize }

def writeVarint(value, buffer):
	if (value < 0xfd):
		buffer.append(value)
	elif (value <= 0xffff):
		buffer.append(0xfd)
		buffer.append(value & 0xff)
		buffer.append((value >> 8) & 0xff)
	elif (value <= 0xffffffff):
		buffer.append(0xfe)
		buffer.append(value & 0xff)
		buffer.append((value >> 8) & 0xff)
		buffer.append((value >> 16) & 0xff)
		buffer.append((value >> 24) & 0xff)
	else:
		raise BTChipException("unsupported encoding")
	return buffer

def getVarintSize(value):
	if (value < 0xfd):
		return 1
	elif (value <= 0xffff):
		return 3
	elif (value <= 0xffffffff):
		return 5
	else:

		raise BTChipException("unsupported encoding")