protected void writeInteger(int typeByte, long val) throws IOException {
		byte lenCode;
		int sa;
		if (val <= 0) {
			if (val == 0) {
				lenCode = 0;
				sa = -1;
			}
			else {
				lenCode = 10;
				sa = 9 * RAWDATA_BITSPERBYTE;
			}
		}
		else if (val < 0x800000000L) {
			if (val < 0x200000L) {
				if (val < 0x80L) {
					lenCode = 1;		// 7-bits
					sa = 0;
				}
				else if (val < 0x4000L) {
					lenCode = 2;		// 14-bits
					sa = RAWDATA_BITSPERBYTE;
				}
				else {
					lenCode = 3;		// 21-bits
					sa = 2 * RAWDATA_BITSPERBYTE;
				}
			}
			else if (val < 0x10000000L) {
				lenCode = 4;		// 28-bits
				sa = 3 * RAWDATA_BITSPERBYTE;
			}
			else {
				lenCode = 5;		// 35-bits
				sa = 4 * RAWDATA_BITSPERBYTE;
			}
		}
		else if (val < 0x2000000000000L) {
			if (val < 0x40000000000L) {
				lenCode = 6;
				sa = 5 * RAWDATA_BITSPERBYTE;
			}
			else {
				lenCode = 7;
				sa = 6 * RAWDATA_BITSPERBYTE;
			}
		}
		else {
			if (val < 0x100000000000000L) {
				lenCode = 8;
				sa = 7 * RAWDATA_BITSPERBYTE;
			}
			else {
				lenCode = 9;
				sa = 8 * RAWDATA_BITSPERBYTE;
			}
		}
		typeByte |= lenCode;
		outStream.write(typeByte);
		for (; sa >= 0; sa -= RAWDATA_BITSPERBYTE) {
			long piece = (val >>> sa) & RAWDATA_MASK;
			piece |= RAWDATA_MARKER;
			outStream.write((int) piece);
		}
	}
A byte-based encoder designed to marshal to the decompiler efficiently
See {@code PackedDecode} for details of the encoding format
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PackedEncode.java