private int serializeGroup(byte[] buffer, int currentPos, String groupName, Map<String, Long> counterMap) throws JobCounterException {
int pos = currentPos;
final CounterGroupKey groupKey = getCounterGroup(groupName);
if (groupKey == null) {
throw new JobCounterException("Group name " + groupName + " is not defined");
}
Bytes.putInt(buffer, pos, groupKey.getIndex());
pos += 4;
int totalCounterNumberPos = pos;
pos += 4;
int totalCounters = 0;
for (Map.Entry<String, Long> entry : counterMap.entrySet()) {
final String counterName = entry.getKey();
final CounterKey counterKey = groupKey.getCounterKeyByName(counterName);
if (counterKey == null) {
continue;
}
final Long counterValue = entry.getValue();
Bytes.putInt(buffer, pos, counterKey.getIndex());
pos += 4;
Bytes.putLong(buffer, pos, counterValue);
pos += 8;
++totalCounters;
}
Bytes.putInt(buffer, totalCounterNumberPos, totalCounters);
return pos;
}