import struct


def GetUnsignedByte(buf, offset):
  """Get an unsigned byte from a buffer at a supplied offset.

  This returns the same value whether the input is a string or a bytes
  object, coercing the return value of socket.recv to the same type whether
  on python 2 or 3.

  Args:
    buf: A string or bytes object.
    offset: An offset into buf.

  Returns:
    an unsigned byte
  """
  return struct.unpack_from('B', buf, offset)[0]