commonlib/src/main/java/com/streamsets/pipeline/lib/parser/udp/collectd/CollectdParser.java
private int parsePart(int startOffset, ByteBuf buf, Map<String, Field> fields) throws OnRecordErrorException {
    int offset = startOffset;
    int type = buf.getUnsignedShort(offset); // 0-1
    offset += 2;
    final int length = buf.getUnsignedShort(offset); // 2-3
    offset += 2;

    switch (type) {
      case HOST:
      case PLUGIN:
      case PLUGIN_INSTANCE:
      case TYPE:
      case TYPE_INSTANCE:
      case MESSAGE:
        pruneFields(type);
        fields.put(PART_TYPES.get(type), Field.create(parseString(offset, length, buf)));
        offset += length - 4;
        break;
      case TIME_HIRES:
      case INTERVAL_HIRES:
        if (type != INTERVAL_HIRES || !excludeInterval) {
          long value = parseNumeric(offset, buf);
          if (convertTime) {
            value *= (Math.pow(2, -30) * 1000);
            type = type == TIME_HIRES ? TIME : INTERVAL;
          }
          fields.put(PART_TYPES.get(type), Field.create(value));
        }
        offset += 8;
        break;
      case TIME:
      case INTERVAL:
      case SEVERITY:
        if (type != INTERVAL || !excludeInterval) {
          fields.put(PART_TYPES.get(type), Field.create(parseNumeric(offset, buf)));
        }
        offset += 8;
        break;
      case VALUES:
        offset = parseValues(offset, buf);
        startNewRecord();
        break;
      case SIGNATURE:
        if (!verifySignature(offset, length, buf)) {
          throw new OnRecordErrorException(Errors.COLLECTD_02);
        }
        offset += length - 4;
        break;
      case ENCRYPTION:
        String user = parseUser(offset, buf);
        offset += (2 + user.length());
        byte[] iv = parseIv(offset, buf);
        offset += 16;
        decrypt(offset, length, buf, user, iv);
        // Skip the checksum and continue processing.
        offset += 20;
        break;
      default:
        // Don't recognize this part type, so skip it
        LOG.warn("Unrecognized part type: {}", type);
        offset += length - 4;
        break;
    }

    return offset;
  }
private int parsePart(int startOffset, ByteBuf buf, Map<String, Field> fields) throws OnRecordErrorException {
    int offset = startOffset;
    int type = buf.getUnsignedShort(offset); // 0-1
    offset += 2;
    final int length = buf.getUnsignedShort(offset); // 2-3
    offset += 2;

    switch (type) {
      case HOST:
      case PLUGIN:
      case PLUGIN_INSTANCE:
      case TYPE:
      case TYPE_INSTANCE:
      case MESSAGE:
        pruneFields(type);
        fields.put(PART_TYPES.get(type), Field.create(parseString(offset, length, buf)));
        offset += length - 4;
        break;
      case TIME_HIRES:
      case INTERVAL_HIRES:
        if (type != INTERVAL_HIRES || !excludeInterval) {
          long value = parseNumeric(offset, buf);
          if (convertTime) {
            value *= (Math.pow(2, -30) * 1000);
            type = type == TIME_HIRES ? TIME : INTERVAL;
          }
          fields.put(PART_TYPES.get(type), Field.create(value));
        }
        offset += 8;
        break;
      case TIME:
      case INTERVAL:
      case SEVERITY:
        if (type != INTERVAL || !excludeInterval) {
          fields.put(PART_TYPES.get(type), Field.create(parseNumeric(offset, buf)));
        }
        offset += 8;
        break;
      case VALUES:
        offset = parseValues(offset, buf);
        startNewRecord();
        break;
      case SIGNATURE:
        if (!verifySignature(offset, length, buf)) {
          throw new OnRecordErrorException(Errors.COLLECTD_02);
        }
        offset += length - 4;
        break;
      case ENCRYPTION:
        String user = parseUser(offset, buf);
        offset += (2 + user.length());
        byte[] iv = parseIv(offset, buf);
        offset += 16;
        decrypt(offset, length, buf, user, iv);
        // Skip the checksum and continue processing.
        offset += 20;
        break;
      default:
        // Don't recognize this part type, so skip it
        LOG.warn("Unrecognized part type: {}", type);
        offset += length - 4;
        break;
    }

    return offset;
  }
Parses a collectd packet "part".

@param startOffset beginning offset for this part
@param buf         buffered packet
@param fields      field map for the output record
@return offset after consuming part