19 namespace Deveel.Data.Util {
31 private readonly byte[]
buf;
56 : this(buf, 0, buf.Length) {
71 get {
return length; }
82 Array.Copy(b, offset, buf, pos, count);
88 return Write(b, 0, b.Length);
108 Array.Copy(buf, pos, b, offset, count);
119 WriteInteger(v, buf, pos);
129 int v = ReadInt4(buf, pos);
161 WriteInt2(v, buf, pos);
171 short v = ReadInt2(buf, pos);
184 byte[] buff = BitConverter.GetBytes(value);
185 Array.Copy(buff, 0, arr, offset, buff.Length);
188 public static char ReadChar(byte[] arr,
int offset) {
189 int c1 = (((int) arr[offset + 0]) & 0x0FF);
190 int c2 = (((int) arr[offset + 1]) & 0x0FF);
191 return (
char) ((c1 << 8) + (c2));
195 public static void WriteChar(
char value, byte[] arr,
int offset) {
196 arr[offset + 0] = (byte) (URShift(value, 8) & 0x0FF);
197 arr[offset + 1] = (byte) (URShift(value, 0) & 0x0FF);
199 Array.Copy(arr, 0, arr, offset, 2);
202 public static short ReadInt2(byte[] arr,
int offset) {
209 return BitConverter.ToInt16(arr, offset);
212 public static void WriteInt2(
short value, byte[] arr,
int offset) {
218 byte[] buff = BitConverter.GetBytes(value);
219 Array.Copy(buff, 0, arr, offset, buff.Length);
222 public static int ReadInt4(byte[] arr,
int offset) {
231 return BitConverter.ToInt32(arr, offset);
234 public static long ReadInt8(byte[] arr,
int offset) {
249 return BitConverter.ToInt64(arr, offset);
252 public static void WriteInt8(
long value, byte[] arr,
int offset) {
264 byte[] buff = BitConverter.GetBytes(value);
265 Array.Copy(buff, 0, arr, offset, buff.Length);
277 public static int URShift(
int number,
int bits) {
279 return number >> bits;
280 return (number >> bits) + (2 << ~bits);
283 public static int URShift(
int number,
long bits) {
284 return URShift(number, (
int)bits);
287 public static long URShift(
long number,
int bits) {
289 return number >> bits;
290 return (number >> bits) + (2L << ~bits);
293 public static long URShift(
long number,
long bits) {
294 return URShift(number, (
int)bits);
ByteBuffer WriteInt2(short v)
Writes a short into the buffer at the current position.
short ReadInt2()
Reads a short from the buffer at the current position.
byte ReadByte()
Reads a byte from the buffer at the current position.
ByteBuffer WriteInteger(int v)
Writes an integer into the buffer at the current position.
readonly int length
The length of the buf array.
static short ReadInt2(byte[] arr, int offset)
int ReadInt4()
Reads an integer from the buffer at the current position.
static long URShift(long number, long bits)
static void WriteInt2(short value, byte[] arr, int offset)
static long URShift(long number, int bits)
ByteBuffer(byte[] buf, int offset, int length)
Constructs the buffer.
ByteBuffer Write(ByteBuffer buffer)
Writes a ByteBuffer in to this buffer.
static int URShift(int number, long bits)
static void WriteChar(char value, byte[] arr, int offset)
ByteBuffer Write(byte[] b)
ByteBuffer Write(byte[] b, int offset, int count)
Writes a byte array into the buffer.
static char ReadChar(byte[] arr, int offset)
static int URShift(int number, int bits)
Operates a shift on the given integer by the number of bits specified.
static int ReadInt4(byte[] arr, int offset)
A wrapper for an array of byte.
static void WriteInteger(int value, byte[] arr, int offset)
readonly byte[] buf
The wrapped byte array itself.
ByteBuffer Read(byte[] b, int offset, int count)
Reads a byte array from the buffer.
ByteBuffer WriteByte(byte v)
Writes a byte into the buffer at the current position.
static long ReadInt8(byte[] arr, int offset)
int pos
The current position in the array.
static void WriteInt8(long value, byte[] arr, int offset)