# Path: afkak/_util.py
# _NULL_SHORT_STRING = struct.pack('>h', -1)
# def _buffer_underflow(what, buf, offset, size):
# def _coerce_topic(topic):
# def _coerce_consumer_group(consumer_group):
# def _coerce_client_id(client_id):
# def write_int_string(s):
# def write_short_ascii(s):
# def write_short_text(s):
# def write_short_bytes(b):
# def read_short_bytes(data, cur):
# def read_short_ascii(data, cur):
# def read_short_text(data, cur):
# def read_int_string(data, cur):
# def relative_unpack(fmt, data, cur):
# def group_by_topic_and_partition(tuples):
# 
# Path: afkak/common.py
# class BufferUnderflowError(KafkaError):
#     pass


import struct
import unittest
import afkak.common
from afkak import _util as util
from afkak.common import BufferUnderflowError
            b'\x00\x00\x00\x0bsome string',
        )

    def test_write_int_string__empty(self):
        self.assertEqual(
            util.write_int_string(b''),
            b'\x00\x00\x00\x00',
        )

    def test_write_int_string__null(self):
        self.assertEqual(
            util.write_int_string(None),
            b'\xff\xff\xff\xff',
        )

    def test_read_int_string(self):
        self.assertEqual(
            util.read_int_string(b'\xff\xff\xff\xff', 0), (None, 4))
        self.assertEqual(
            util.read_int_string(b'\x00\x00\x00\x00', 0), (b'', 4))
        self.assertEqual(
            util.read_int_string(b'\x00\x00\x00\x0bsome string', 0),
            (b'some string', 15),
        )

    def test_read_int_string_missing_length(self):
        """
        BufferUnderflowError results when there aren't enough bytes for
        a string length at the expected position.
        """

# Path: afkak/_util.py
# _NULL_SHORT_STRING = struct.pack('>h', -1)
# def _buffer_underflow(what, buf, offset, size):
# def _coerce_topic(topic):
# def _coerce_consumer_group(consumer_group):
# def _coerce_client_id(client_id):
# def write_int_string(s):
# def write_short_ascii(s):
# def write_short_text(s):
# def write_short_bytes(b):
# def read_short_bytes(data, cur):
# def read_short_ascii(data, cur):
# def read_short_text(data, cur):
# def read_int_string(data, cur):
# def relative_unpack(fmt, data, cur):
# def group_by_topic_and_partition(tuples):
# 
# Path: afkak/common.py
# class BufferUnderflowError(KafkaError):
#     pass


# Path: afkak/test/test_util.py
import struct
import unittest
import afkak.common
from afkak import _util as util
from afkak.common import BufferUnderflowError

            b'\x00\x00\x00\x0bsome string',
        )

    def test_write_int_string__empty(self):
        self.assertEqual(
            util.write_int_string(b''),
            b'\x00\x00\x00\x00',
        )

    def test_write_int_string__null(self):
        self.assertEqual(
            util.write_int_string(None),
            b'\xff\xff\xff\xff',
        )

    def test_read_int_string(self):
        self.assertEqual(
            util.read_int_string(b'\xff\xff\xff\xff', 0), (None, 4))
        self.assertEqual(
            util.read_int_string(b'\x00\x00\x00\x00', 0), (b'', 4))
        self.assertEqual(
            util.read_int_string(b'\x00\x00\x00\x0bsome string', 0),
            (b'some string', 15),
        )

    def test_read_int_string_missing_length(self):
        """
        BufferUnderflowError results when there aren't enough bytes for
        a string length at the expected position.
        """

        with self.assertRaises(BufferUnderflowError) as context: