6 namespace Deveel.Data.Protocol {
20 private const int InitialBufferSize = 512;
50 buf =
new byte[InitialBufferSize];
64 int old_size = buf.Length;
65 if (newSize > old_size) {
66 int cap = (old_size * 3) / 2 + 1;
72 Array.Copy(oldBuf, 0, buf, 0, count);
88 Array.Copy(buf, markedIndex, buf, 0, count - markedLength);
89 count -= markedLength;
100 if (markedIndex == -1)
101 throw new IOException(
"No mark has been read yet.");
103 if (markedIndex >= markedLength) {
104 string debugMsg =
"Read over end of length marked buffer. ";
105 debugMsg +=
"(marked_index=" + markedIndex;
106 debugMsg +=
",marked_length=" + markedLength +
")";
108 throw new IOException(debugMsg);
110 int n = buf[markedIndex++] & 0x0FF;
111 if (markedIndex >= markedLength) {
118 public override void Write(byte[] buffer,
int offset,
int count) {
119 throw new NotSupportedException();
122 public override bool CanRead {
126 public override bool CanSeek {
127 get {
return false; }
130 public override bool CanWrite {
131 get {
return false; }
134 public override long Length {
135 get {
throw new NotImplementedException(); }
138 public override long Position {
139 get {
throw new NotImplementedException(); }
140 set {
throw new NotImplementedException(); }
146 public override long Seek(
long offset, SeekOrigin origin) {
147 throw new NotSupportedException();
151 throw new NotSupportedException();
154 public override int Read(byte[] b,
int off,
int len) {
156 if (markedIndex == -1)
157 throw new IOException(
"No mark has been read yet.");
159 int readUpto = markedIndex + len;
160 if (readUpto > markedLength) {
161 String debug_msg =
"Read over end of length marked buffer. ";
162 debug_msg +=
"(marked_index=" + markedIndex;
163 debug_msg +=
",len=" + len;
164 debug_msg +=
",marked_length=" + markedLength +
")";
165 throw new IOException(debug_msg);
167 Array.Copy(buf, markedIndex, b, off, len);
168 markedIndex = readUpto;
169 if (markedIndex >= markedLength) {
176 public int Available {
181 if (markedLength >= 0) {
182 return (markedLength - markedIndex);
206 if (markedLength == -1) {
207 int available = input.Available;
208 if (count > 0 || available > 0) {
209 if ((count + available) > maxSize) {
210 throw new IOException(
"Marked length is greater than max size ( " +
211 (count + available) +
" > " + maxSize +
" )");
214 EnsureCapacity(count + available);
215 int readIn = input.Read(buf, count, available);
224 count = count + readIn;
230 if (count >= lengthMarker + 4) {
233 markedLength = lengthMarker + 4;
253 if (count >= lengthMarker + 4) {
256 markedLength = lengthMarker + 4;
263 if (count >= buf.Length) {
264 EnsureCapacity(count + InitialBufferSize);
267 int read_in = input.Read(buf, count, buf.Length - count);
int ReadInt4()
Reads an integer from the buffer at the current position.
A wrapper for an array of byte.