def convert_to_pcaptext(raw_packet, timestamp=''):
    """Convert the raw pcap hex to a form that text2cap can read from stdin.

    hexdump and xxd can do this on unix-like platforms, but not on Windows.

    `tshark -r <file> -T json -x` produces the "in" and text2pcap
    requires the "out" formats as shown below:

    Per Text2pcap documentation:
    "Text2pcap understands a hexdump of the form generated by od -Ax -tx1 -v."

    In format::

      247703511344881544abbfdd0800452000542bbc00007901e8fd080808080a301290000
      082a563110001f930ab5b00000000a9e80d0000000000101112131415161718191a1b1c
      1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637

    Out format::

      0000  24 77 03 51 13 44 88 15 44 ab bf dd 08 00 45 20
      0010  00 54 2b bc 00 00 79 01 e8 fd 08 08 08 08 0a 30
      0020  12 90 00 00 82 a5 63 11 00 01 f9 30 ab 5b 00 00
      0030  00 00 a9 e8 0d 00 00 00 00 00 10 11 12 13 14 15
      0040  16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25
      0050  26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35
      0060  36 37

    NOTE: Output format doesn't need an extra \\n between packets. So in the
    above example, the next line could be 0000  00 ... for the next packet.

    Args:
        raw_packet (str): The ASCII hexdump seen above in 'In'
        timestamp (str): An optional packet timestamp that will precede
            the 0000 line of the packet hex.
    Returns:
        formatted_string (str): Packet in ASCII hexdump format like `Out` above
    """
    formatted_string = ''
    hex_chars_per_line = 32
    hex_chars_per_byte = 2
    num_chars = len(raw_packet)
    if timestamp:
        formatted_string += str(timestamp) + '\n'
    for line_sep in range(0, num_chars, hex_chars_per_line):
        raw_line = raw_packet[line_sep:line_sep + hex_chars_per_line]
        line = ''
        for byte_sep in range(0, hex_chars_per_line, hex_chars_per_byte):
            line += raw_line[byte_sep:byte_sep + hex_chars_per_byte] + ' '
        line = line[:-1]
        line_sep_hex = line_sep // 32 * 10
        formatted_string += '{:>04d}'.format(line_sep_hex) + '  ' + line + '\n'
    return formatted_string
