DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Static Public Member Functions | Properties | Private Attributes | List of all members
Deveel.Data.Util.ByteBuffer Class Reference

A wrapper for an array of byte. More...

Public Member Functions

 ByteBuffer (byte[] buf, int offset, int length)
 Constructs the buffer. More...
 
 ByteBuffer (byte[] buf)
 
ByteBuffer Write (byte[] b, int offset, int count)
 Writes a byte array into the buffer. More...
 
ByteBuffer Write (byte[] b)
 
ByteBuffer Write (ByteBuffer buffer)
 Writes a ByteBuffer in to this buffer. More...
 
ByteBuffer Read (byte[] b, int offset, int count)
 Reads a byte array from the buffer. More...
 
ByteBuffer WriteInteger (int v)
 Writes an integer into the buffer at the current position. More...
 
int ReadInt4 ()
 Reads an integer from the buffer at the current position. More...
 
ByteBuffer WriteByte (byte v)
 Writes a byte into the buffer at the current position. More...
 
byte ReadByte ()
 Reads a byte from the buffer at the current position. More...
 
ByteBuffer WriteInt2 (short v)
 Writes a short into the buffer at the current position. More...
 
short ReadInt2 ()
 Reads a short from the buffer at the current position. More...
 

Static Public Member Functions

static void WriteInteger (int value, byte[] arr, int offset)
 
static char ReadChar (byte[] arr, int offset)
 
static void WriteChar (char value, byte[] arr, int offset)
 
static short ReadInt2 (byte[] arr, int offset)
 
static void WriteInt2 (short value, byte[] arr, int offset)
 
static int ReadInt4 (byte[] arr, int offset)
 
static long ReadInt8 (byte[] arr, int offset)
 
static void WriteInt8 (long value, byte[] arr, int offset)
 
static int URShift (int number, int bits)
 Operates a shift on the given integer by the number of bits specified. More...
 
static int URShift (int number, long bits)
 
static long URShift (long number, int bits)
 
static long URShift (long number, long bits)
 

Properties

int Position [get, set]
 Gets or sets the position in to the buffer. More...
 
int Length [get]
 Returns the length of this buffer. More...
 

Private Attributes

readonly byte[] buf
 The wrapped byte array itself. More...
 
int pos
 The current position in the array. More...
 
readonly int length
 The length of the buf array. More...
 

Detailed Description

A wrapper for an array of byte.

This provides various functions for altering the state of the buffer.

Definition at line 27 of file ByteBuffer.cs.

Constructor & Destructor Documentation

Deveel.Data.Util.ByteBuffer.ByteBuffer ( byte[]  buf,
int  offset,
int  length 
)
inline

Constructs the buffer.

Parameters
buf
offset
length

Definition at line 49 of file ByteBuffer.cs.

49  {
50  this.buf = buf;
51  this.length = length;
52  pos = offset;
53  }
readonly int length
The length of the buf array.
Definition: ByteBuffer.cs:41
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
Deveel.Data.Util.ByteBuffer.ByteBuffer ( byte[]  buf)
inline

Definition at line 55 of file ByteBuffer.cs.

56  : this(buf, 0, buf.Length) {
57  }
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31

Member Function Documentation

ByteBuffer Deveel.Data.Util.ByteBuffer.Read ( byte[]  b,
int  offset,
int  count 
)
inline

Reads a byte array from the buffer.

Parameters
b
offset
count
Returns

Definition at line 107 of file ByteBuffer.cs.

107  {
108  Array.Copy(buf, pos, b, offset, count);
109  pos += count;
110  return this;
111  }
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
byte Deveel.Data.Util.ByteBuffer.ReadByte ( )
inline

Reads a byte from the buffer at the current position.

Returns

Definition at line 149 of file ByteBuffer.cs.

149  {
150  byte b = buf[pos];
151  ++pos;
152  return b;
153  }
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
static char Deveel.Data.Util.ByteBuffer.ReadChar ( byte[]  arr,
int  offset 
)
inlinestatic

Definition at line 188 of file ByteBuffer.cs.

188  {
189  int c1 = (((int) arr[offset + 0]) & 0x0FF);
190  int c2 = (((int) arr[offset + 1]) & 0x0FF);
191  return (char) ((c1 << 8) + (c2));
192  //TODO: check... return BitConverter.ToChar(arr, offset);
193  }
short Deveel.Data.Util.ByteBuffer.ReadInt2 ( )
inline

Reads a short from the buffer at the current position.

Returns

Definition at line 170 of file ByteBuffer.cs.

170  {
171  short v = ReadInt2(buf, pos);
172  pos += 2;
173  return v;
174  }
short ReadInt2()
Reads a short from the buffer at the current position.
Definition: ByteBuffer.cs:170
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
static short Deveel.Data.Util.ByteBuffer.ReadInt2 ( byte[]  arr,
int  offset 
)
inlinestatic

Definition at line 202 of file ByteBuffer.cs.

202  {
203  /*
204  TODO: check ...
205  int c1 = (((int) arr[offset + 0]) & 0x0FF);
206  int c2 = (((int) arr[offset + 1]) & 0x0FF);
207  return (short) ((c1 << 8) + (c2));
208  */
209  return BitConverter.ToInt16(arr, offset);
210  }
int Deveel.Data.Util.ByteBuffer.ReadInt4 ( )
inline

Reads an integer from the buffer at the current position.

Returns

Definition at line 128 of file ByteBuffer.cs.

128  {
129  int v = ReadInt4(buf, pos);
130  pos += 4;
131  return v;
132  }
int ReadInt4()
Reads an integer from the buffer at the current position.
Definition: ByteBuffer.cs:128
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
static int Deveel.Data.Util.ByteBuffer.ReadInt4 ( byte[]  arr,
int  offset 
)
inlinestatic

Definition at line 222 of file ByteBuffer.cs.

222  {
223  /*
224  TODO: check ...
225  int c1 = (((int) arr[offset + 0]) & 0x0FF);
226  int c2 = (((int) arr[offset + 1]) & 0x0FF);
227  int c3 = (((int) arr[offset + 2]) & 0x0FF);
228  int c4 = (((int) arr[offset + 3]) & 0x0FF);
229  return (c1 << 24) + (c2 << 16) + (c3 << 8) + (c4);
230  */
231  return BitConverter.ToInt32(arr, offset);
232  }
static long Deveel.Data.Util.ByteBuffer.ReadInt8 ( byte[]  arr,
int  offset 
)
inlinestatic

Definition at line 234 of file ByteBuffer.cs.

234  {
235  /*
236  TODO: check ...
237  long c1 = (((int) arr[offset + 0]) & 0x0FF);
238  long c2 = (((int) arr[offset + 1]) & 0x0FF);
239  long c3 = (((int) arr[offset + 2]) & 0x0FF);
240  long c4 = (((int) arr[offset + 3]) & 0x0FF);
241  long c5 = (((int) arr[offset + 4]) & 0x0FF);
242  long c6 = (((int) arr[offset + 5]) & 0x0FF);
243  long c7 = (((int) arr[offset + 6]) & 0x0FF);
244  long c8 = (((int) arr[offset + 7]) & 0x0FF);
245 
246  return (c1 << 56) + (c2 << 48) + (c3 << 40) +
247  (c4 << 32) + (c5 << 24) + (c6 << 16) + (c7 << 8) + (c8);
248  */
249  return BitConverter.ToInt64(arr, offset);
250  }
static int Deveel.Data.Util.ByteBuffer.URShift ( int  number,
int  bits 
)
inlinestatic

Operates a shift on the given integer by the number of bits specified.

Parameters
numberThe number to shift.
bitsThe number of bits to shift the given number.
Returns
Returns an int representing the shifted number.

Definition at line 277 of file ByteBuffer.cs.

277  {
278  if (number >= 0)
279  return number >> bits;
280  return (number >> bits) + (2 << ~bits);
281  }
static int Deveel.Data.Util.ByteBuffer.URShift ( int  number,
long  bits 
)
inlinestatic

Definition at line 283 of file ByteBuffer.cs.

283  {
284  return URShift(number, (int)bits);
285  }
static int URShift(int number, int bits)
Operates a shift on the given integer by the number of bits specified.
Definition: ByteBuffer.cs:277
static long Deveel.Data.Util.ByteBuffer.URShift ( long  number,
int  bits 
)
inlinestatic

Definition at line 287 of file ByteBuffer.cs.

287  {
288  if (number >= 0)
289  return number >> bits;
290  return (number >> bits) + (2L << ~bits);
291  }
static long Deveel.Data.Util.ByteBuffer.URShift ( long  number,
long  bits 
)
inlinestatic

Definition at line 293 of file ByteBuffer.cs.

293  {
294  return URShift(number, (int)bits);
295  }
static int URShift(int number, int bits)
Operates a shift on the given integer by the number of bits specified.
Definition: ByteBuffer.cs:277
ByteBuffer Deveel.Data.Util.ByteBuffer.Write ( byte[]  b,
int  offset,
int  count 
)
inline

Writes a byte array into the buffer.

Parameters
b
offset
count
Returns

Definition at line 81 of file ByteBuffer.cs.

81  {
82  Array.Copy(b, offset, buf, pos, count);
83  pos += count;
84  return this;
85  }
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
ByteBuffer Deveel.Data.Util.ByteBuffer.Write ( byte[]  b)
inline

Definition at line 87 of file ByteBuffer.cs.

87  {
88  return Write(b, 0, b.Length);
89  }
ByteBuffer Write(byte[] b, int offset, int count)
Writes a byte array into the buffer.
Definition: ByteBuffer.cs:81
ByteBuffer Deveel.Data.Util.ByteBuffer.Write ( ByteBuffer  buffer)
inline

Writes a ByteBuffer in to this buffer.

Parameters
buffer
Returns

Definition at line 96 of file ByteBuffer.cs.

96  {
97  return Write(buffer.buf, buffer.pos, buffer.length);
98  }
ByteBuffer Write(byte[] b, int offset, int count)
Writes a byte array into the buffer.
Definition: ByteBuffer.cs:81
ByteBuffer Deveel.Data.Util.ByteBuffer.WriteByte ( byte  v)
inline

Writes a byte into the buffer at the current position.

Parameters
v
Returns

Definition at line 139 of file ByteBuffer.cs.

139  {
140  buf[pos] = v;
141  ++pos;
142  return this;
143  }
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
static void Deveel.Data.Util.ByteBuffer.WriteChar ( char  value,
byte[]  arr,
int  offset 
)
inlinestatic

Definition at line 195 of file ByteBuffer.cs.

195  {
196  arr[offset + 0] = (byte) (URShift(value, 8) & 0x0FF);
197  arr[offset + 1] = (byte) (URShift(value, 0) & 0x0FF);
198  // byte[] buff = BitConverter.GetBytes(value);
199  Array.Copy(arr, 0, arr, offset, 2);
200  }
static int URShift(int number, int bits)
Operates a shift on the given integer by the number of bits specified.
Definition: ByteBuffer.cs:277
ByteBuffer Deveel.Data.Util.ByteBuffer.WriteInt2 ( short  v)
inline

Writes a short into the buffer at the current position.

Parameters
v
Returns

Definition at line 160 of file ByteBuffer.cs.

160  {
161  WriteInt2(v, buf, pos);
162  pos += 2;
163  return this;
164  }
ByteBuffer WriteInt2(short v)
Writes a short into the buffer at the current position.
Definition: ByteBuffer.cs:160
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
static void Deveel.Data.Util.ByteBuffer.WriteInt2 ( short  value,
byte[]  arr,
int  offset 
)
inlinestatic

Definition at line 212 of file ByteBuffer.cs.

212  {
213  /*
214  TODO: check ...
215  arr[offset + 0] = (byte) ((value >>> 8) & 0x0FF);
216  arr[offset + 1] = (byte) ((value >>> 0) & 0x0FF);
217  */
218  byte[] buff = BitConverter.GetBytes(value);
219  Array.Copy(buff, 0, arr, offset, buff.Length);
220  }
static void Deveel.Data.Util.ByteBuffer.WriteInt8 ( long  value,
byte[]  arr,
int  offset 
)
inlinestatic

Definition at line 252 of file ByteBuffer.cs.

252  {
253  /*
254  TODO:
255  arr[offset + 0] = (byte) ((value >>> 56) & 0xFF);
256  arr[offset + 1] = (byte) ((value >>> 48) & 0xFF);
257  arr[offset + 2] = (byte) ((value >>> 40) & 0xFF);
258  arr[offset + 3] = (byte) ((value >>> 32) & 0xFF);
259  arr[offset + 4] = (byte) ((value >>> 24) & 0xFF);
260  arr[offset + 5] = (byte) ((value >>> 16) & 0xFF);
261  arr[offset + 6] = (byte) ((value >>> 8) & 0xFF);
262  arr[offset + 7] = (byte) ((value >>> 0) & 0xFF);
263  */
264  byte[] buff = BitConverter.GetBytes(value);
265  Array.Copy(buff, 0, arr, offset, buff.Length);
266  }
ByteBuffer Deveel.Data.Util.ByteBuffer.WriteInteger ( int  v)
inline

Writes an integer into the buffer at the current position.

Parameters
v
Returns

Definition at line 118 of file ByteBuffer.cs.

118  {
119  WriteInteger(v, buf, pos);
120  pos += 4;
121  return this;
122  }
ByteBuffer WriteInteger(int v)
Writes an integer into the buffer at the current position.
Definition: ByteBuffer.cs:118
readonly byte[] buf
The wrapped byte array itself.
Definition: ByteBuffer.cs:31
int pos
The current position in the array.
Definition: ByteBuffer.cs:36
static void Deveel.Data.Util.ByteBuffer.WriteInteger ( int  value,
byte[]  arr,
int  offset 
)
inlinestatic

Definition at line 176 of file ByteBuffer.cs.

176  {
177  /*
178  TODO: check ...
179  arr[offset + 0] = (byte) ((value >>> 24) & 0xFF);
180  arr[offset + 1] = (byte) ((value >>> 16) & 0xFF);
181  arr[offset + 2] = (byte) ((value >>> 8) & 0xFF);
182  arr[offset + 3] = (byte) ((value >>> 0) & 0xFF);
183  */
184  byte[] buff = BitConverter.GetBytes(value);
185  Array.Copy(buff, 0, arr, offset, buff.Length);
186  }

Member Data Documentation

readonly byte [] Deveel.Data.Util.ByteBuffer.buf
private

The wrapped byte array itself.

Definition at line 31 of file ByteBuffer.cs.

readonly int Deveel.Data.Util.ByteBuffer.length
private

The length of the buf array.

Definition at line 41 of file ByteBuffer.cs.

int Deveel.Data.Util.ByteBuffer.pos
private

The current position in the array.

Definition at line 36 of file ByteBuffer.cs.

Property Documentation

int Deveel.Data.Util.ByteBuffer.Length
get

Returns the length of this buffer.

Definition at line 70 of file ByteBuffer.cs.

int Deveel.Data.Util.ByteBuffer.Position
getset

Gets or sets the position in to the buffer.

Definition at line 62 of file ByteBuffer.cs.


The documentation for this class was generated from the following file: