SpdyProtocolUtils.putInt(inputBuffer, headers.size());
long fiCookie = headers.fastIterateNonEmpty();
while (fiCookie != -1) {
HeaderValues headerValues = headers.fiCurrent(fiCookie);
//TODO: for now it just fails if there are too many headers
SpdyProtocolUtils.putInt(inputBuffer, headerValues.getHeaderName().length());
for (int i = 0; i < headerValues.getHeaderName().length(); ++i) {
inputBuffer.put((byte) (Character.toLowerCase((char) headerValues.getHeaderName().byteAt(i))));
}
int pos = inputBuffer.position();
SpdyProtocolUtils.putInt(inputBuffer, 0); //size, back fill
int size = headerValues.size() - 1; //null between the characters
for (int i = 0; i < headerValues.size(); ++i) {
String val = headerValues.get(i);
size += val.length();
for (int j = 0; j < val.length(); ++j) {
inputBuffer.put((byte) val.charAt(j));
}
if (i != headerValues.size() - 1) {
inputBuffer.put((byte) 0);
}
}
SpdyProtocolUtils.putInt(inputBuffer, size, pos);
fiCookie = headers.fiNext(fiCookie);