@Override public ByteBuf setByte(int index, int value) { checkIndex(index); _setByte(index, value); return this; }
@Override public ByteBuf writeByte(int value) { ensureWritable0(1); _setByte(writerIndex++, value); return this; }
static int writeAscii(AbstractByteBuf buffer, int writerIndex, CharSequence seq, int len) { // We can use the _set methods as these not need to do any index checks and reference checks. // This is possible as we called ensureWritable(...) before. for (int i = 0; i < len; i++) { buffer._setByte(writerIndex++, AsciiString.c2b(seq.charAt(i))); } return len; }
char c = seq.charAt(i); if (c < 0x80) { buffer._setByte(writerIndex++, (byte) c); } else if (c < 0x800) { buffer._setByte(writerIndex++, (byte) (0xc0 | (c >> 6))); buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f))); } else if (isSurrogate(c)) { if (!Character.isHighSurrogate(c)) { buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN); continue; buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN); break; buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN); buffer._setByte(writerIndex++, Character.isHighSurrogate(c2) ? WRITE_UTF_UNKNOWN : c2); continue; buffer._setByte(writerIndex++, (byte) (0xf0 | (codePoint >> 18))); buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f))); buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f))); buffer._setByte(writerIndex++, (byte) (0x80 | (codePoint & 0x3f))); } else { buffer._setByte(writerIndex++, (byte) (0xe0 | (c >> 12))); buffer._setByte(writerIndex++, (byte) (0x80 | ((c >> 6) & 0x3f))); buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f)));
@Override protected void _setByte(int index, int value) { unwrap()._setByte(index, value); }
@Override protected void _setByte(int index, int value) { unwrap()._setByte(index, value); }
@Override protected void _setByte(int index, int value) { unwrap()._setByte(idx(index), value); }
@Override protected void _setByte(int index, int value) { unwrap()._setByte(idx(index), value); }
@Override public ByteBuf setZero(int index, int length) { if (length == 0) { return this; } checkIndex(index, length); int nLong = length >>> 3; int nBytes = length & 7; for (int i = nLong; i > 0; i --) { _setLong(index, 0); index += 8; } if (nBytes == 4) { _setInt(index, 0); // Not need to update the index as we not will use it after this. } else if (nBytes < 4) { for (int i = nBytes; i > 0; i --) { _setByte(index, (byte) 0); index ++; } } else { _setInt(index, 0); index += 4; for (int i = nBytes - 4; i > 0; i --) { _setByte(index, (byte) 0); index ++; } } return this; }