public static ExternalRefs fromBytes(InputStream rawBytes) throws IOException {
        DataInputStream inputStream = new DataInputStream(rawBytes);
        int count = inputStream.readByte();
        if (count > 127) {
            throw new IOException("Parse Error: count out of range [0, 127]");
        }

        List<Reference> refs = new ArrayList<Reference>();
        while (count > 0) {
            int kind = inputStream.readByte();
            if (count < 0 || count > 127) {
                throw new IOException("Parse Error: kind out of range [0, 127]");
            }

            int rawLength = inputStream.readShort();
            if (rawLength < 0 || rawLength > 32767) {
                throw new IOException("Parse Error: keyLength out of range [0, 32767]");
            }
            byte[] raw = new byte[rawLength];
            inputStream.readFully(raw);
            String key = new String(raw, IOUtil.UTF8);

            refs.add(new Reference(kind, key));
            count--;
        }
        return new ExternalRefs(refs);
    }