public Validate ( bool write, int dataSize ) : void | ||
write | bool | Operation to verify. True for write and false for read. |
dataSize | int | The size to read or write. |
return | void |
public void Validate(bool write, int dataSize)
{
bool valid = false;
if (write)
{
if (this.Size < dataSize && this.autoGrow)
{
int newSize = Math.Max(this.Capacity * 2, this.Capacity + dataSize);
byte[] newBuffer;
int offset;
int count;
this.DuplicateBuffer(newSize, this.write - this.start, out newBuffer, out offset, out count);
int bufferOffset = this.start - offset;
this.buffer = newBuffer;
this.start = offset;
this.read -= bufferOffset;
this.write -= bufferOffset;
this.end = offset + count;
}
valid = this.Size >= dataSize;
}
else
{
valid = this.Length >= dataSize;
}
if (!valid)
{
throw new InvalidOperationException("buffer too small");
}
}
/// <summary> /// Writes a uuid (16-bytes) into the buffer and advance the buffer write cursor. /// </summary> /// <param name="buffer">The buffer to write.</param> /// <param name="data">The data to write.</param> public static void WriteUuid(ByteBuffer buffer, Guid data) { buffer.Validate(true, FixedWidth.Uuid); byte[] p = data.ToByteArray(); int pos = buffer.WritePos; if (AmqpBitConverter.IsLittleEndian) { buffer.Buffer[pos++] = p[3]; buffer.Buffer[pos++] = p[2]; buffer.Buffer[pos++] = p[1]; buffer.Buffer[pos++] = p[0]; buffer.Buffer[pos++] = p[5]; buffer.Buffer[pos++] = p[4]; buffer.Buffer[pos++] = p[7]; buffer.Buffer[pos++] = p[6]; Array.Copy(p, 8, buffer.Buffer, pos, 8); } else { Array.Copy(p, buffer.Buffer, FixedWidth.Uuid); } buffer.Append(FixedWidth.Uuid); }