<commit_before>package falcon.fix;

import java.nio.ByteBuffer;

/**
 * On-wire protocol parsing and formatting.
 */
public class Protocol {

  /*
   * Maximum message header size in bytes.
   */
  public static final int MAX_HEADER_SIZE = 64;

  /*
   * Maximum message body size in bytes.
   */
  public static final int MAX_BODY_SIZE = 4096;

  /**
   * Format field to on-wire format.
   */
  public static void format(ByteBuffer buf, Tag tag, byte[] value) {
    buf.put(tag.value());
    buf.put((byte) '=');
    buf.put(value);
    buf.put((byte) 0x01);
  }

  /**
   * Format field to on-wire format.
   */
  public static void formatInt(ByteBuffer buf, Tag tag, int value) {
    buf.put(tag.value());
    buf.put((byte) '=');
    writeInt(buf, value);
    buf.put((byte) 0x01);
  }

  public static void formatString(ByteBuffer buf, Tag tag, String value) {
    buf.put(tag.value());
    buf.put((byte) '=');
    for (int i = 0; i < value.length(); i++) {
      buf.put((byte) value.charAt(i));
    }
    buf.put((byte) 0x01);
  }

  public static void formatCheckSum(ByteBuffer buf, Tag tag, int value) {
    buf.put(tag.value());
    buf.put((byte) '=');
    if (value < 10) {
      buf.put((byte) '0');
    }
    if (value < 100) {
      buf.put((byte) '0');
    }
    writeInt(buf, value);
    buf.put((byte) 0x01);
  }

  public static void writeInt(ByteBuffer buf, int n) {
    if (n < 0) {
      buf.put((byte) '-');
    }
    n = Math.abs(n);
    int start = buf.position();
    do {
      buf.put((byte)('0' + n % 10));
      n /= 10;
    } while (n > 0);
    int end = buf.position();
    int i = start;
    int j = end - 1;
    while (i < j) {
      byte tmp = buf.get(i);
      buf.put(i, buf.get(j));
      buf.put(j, tmp);
      i++; j--;
    }
  }

  public static void match(ByteBuffer buf, Tag tag) throws ParseException {
    byte[] tagBytes = tag.value();
    if (buf.remaining() < tagBytes.length) {
      throw new PartialParseException();
    }
    for (int i = 0; i < tagBytes.length; i++) {
      if (buf.get() != tagBytes[i]) {
        throw new ParseFailedException();
      }
    }
    byte ch = buf.get();
    if (ch != (byte)'=') {
      throw new ParseFailedException();
    }
    while (buf.get() != (byte)0x01)
      ;;
  }

  public static int matchInt(ByteBuffer buf, Tag tag) throws ParseException {
    byte[] tagBytes = tag.value();
    if (buf.remaining() < tagBytes.length) {
      throw new PartialParseException();
    }
    for (int i = 0; i < tagBytes.length; i++) {
      if (buf.get() != tagBytes[i]) {
        throw new ParseFailedException();
      }
    }
    byte ch = buf.get();
    if (ch != (byte)'=') {
      throw new ParseFailedException();
    }
    int result = 0;
    for (;;) {
      ch = buf.get();
      if (ch == (byte)0x01) {
        break;
      }
      result *= 10;
      result += (byte)ch - (byte)'0';
    }
    return result;
  }
}<commit_msg>Eliminate duplicate tag parsing code<commit_after>package falcon.fix;

import java.nio.ByteBuffer;

/**
 * On-wire protocol parsing and formatting.
 */
public class Protocol {

  /*
   * Maximum message header size in bytes.
   */
  public static final int MAX_HEADER_SIZE = 64;

  /*
   * Maximum message body size in bytes.
   */
  public static final int MAX_BODY_SIZE = 4096;

  /**
   * Format field to on-wire format.
   */
  public static void format(ByteBuffer buf, Tag tag, byte[] value) {
    buf.put(tag.value());
    buf.put((byte) '=');
    buf.put(value);
    buf.put((byte) 0x01);
  }

  /**
   * Format field to on-wire format.
   */
  public static void formatInt(ByteBuffer buf, Tag tag, int value) {
    buf.put(tag.value());
    buf.put((byte) '=');
    writeInt(buf, value);
    buf.put((byte) 0x01);
  }

  public static void formatString(ByteBuffer buf, Tag tag, String value) {
    buf.put(tag.value());
    buf.put((byte) '=');
    for (int i = 0; i < value.length(); i++) {
      buf.put((byte) value.charAt(i));
    }
    buf.put((byte) 0x01);
  }

  public static void formatCheckSum(ByteBuffer buf, Tag tag, int value) {
    buf.put(tag.value());
    buf.put((byte) '=');
    if (value < 10) {
      buf.put((byte) '0');
    }
    if (value < 100) {
      buf.put((byte) '0');
    }
    writeInt(buf, value);
    buf.put((byte) 0x01);
  }

  public static void writeInt(ByteBuffer buf, int n) {
    if (n < 0) {
      buf.put((byte) '-');
    }
    n = Math.abs(n);
    int start = buf.position();
    do {
      buf.put((byte)('0' + n % 10));
      n /= 10;
    } while (n > 0);
    int end = buf.position();
    int i = start;
    int j = end - 1;
    while (i < j) {
      byte tmp = buf.get(i);
      buf.put(i, buf.get(j));
      buf.put(j, tmp);
      i++; j--;
    }
  }

  public static void match(ByteBuffer buf, Tag tag) throws ParseException {
    matchTag(buf, tag);
    while (buf.get() != (byte)0x01)
      ;;
  }

  public static int matchInt(ByteBuffer buf, Tag tag) throws ParseException {
    matchTag(buf, tag);
    int result = 0;
    for (;;) {
      byte ch = buf.get();
      if (ch == (byte)0x01) {
        break;
      }
      result *= 10;
      result += (byte)ch - (byte)'0';
    }
    return result;
  }

  public static void matchTag(ByteBuffer buf, Tag tag) throws ParseException {
    byte[] tagBytes = tag.value();
    if (buf.remaining() < tagBytes.length) {
      throw new PartialParseException();
    }
    for (int i = 0; i < tagBytes.length; i++) {
      if (buf.get() != tagBytes[i]) {
        throw new ParseFailedException();
      }
    }
    byte ch = buf.get();
    if (ch != (byte)'=') {
      throw new ParseFailedException();
    }
  }
}
{'fraction_non_alphanumeric': 0.16716947648624667, 'fraction_numerical': 0.016149068322981366, 'mean_word_length': 2.2540415704387993, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4997030', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1956, 'n_words': 525}