DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
AreaExtensions.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
19 namespace Deveel.Data.Store {
24  public static class AreaExtensions {
32  public static byte ReadByte(this IArea area) {
33  var bytes = new byte[1];
34  area.Read(bytes, 0, 1);
35  return bytes[0];
36  }
37 
45  public static short ReadInt2(this IArea area) {
46  var bytes = new byte[2];
47  area.Read(bytes, 0, 2);
48  return BitConverter.ToInt16(bytes, 0);
49  }
50 
58  public static int ReadInt4(this IArea area) {
59  var bytes = new byte[4];
60  area.Read(bytes, 0, 4);
61  return BitConverter.ToInt32(bytes, 0);
62  }
63 
71  public static long ReadInt8(this IArea area) {
72  var bytes = new byte[8];
73  area.Read(bytes, 0, 8);
74  return BitConverter.ToInt64(bytes, 0);
75  }
76 
82  public static void WriteByte(this IArea area, byte value) {
83  var bytes = new byte[1] {value};
84  area.Write(bytes, 0, 1);
85  }
86 
92  public static void WriteInt2(this IArea area, short value) {
93  var bytes = BitConverter.GetBytes(value);
94  area.Write(bytes, 0, 2);
95  }
96 
102  public static void WriteInt4(this IArea area, int value) {
103  var bytes = BitConverter.GetBytes(value);
104  area.Write(bytes, 0, 4);
105  }
106 
112  public static void WriteInt8(this IArea area, long value) {
113  var bytes = BitConverter.GetBytes(value);
114  area.Write(bytes, 0, 8);
115  }
116  }
117 }
static long ReadInt8(this IArea area)
Reads a 8-byte integer from the area.
static void WriteInt2(this IArea area, short value)
Writes a 2-byte integer into the given area.
static void WriteInt4(this IArea area, int value)
Writes a 4-byte integer into the given area.
int Read(byte[] buffer, int offset, int length)
Reads an array of bytes from the underlying IArea and advances the position by length ...
static int ReadInt4(this IArea area)
Reads a 4-byte integer from the area.
Extension methods to optimize the access to the contents of an IArea of a database store...
static byte ReadByte(this IArea area)
Reads a single byte from the area.
void Write(byte[] buffer, int offset, int length)
static void WriteInt8(this IArea area, long value)
Writes a 8-byte integer into the given area.
An interface for access the contents of an area of a store.
Definition: IArea.cs:23
static short ReadInt2(this IArea area)
Reads a 2-byte integer from the area.
static void WriteByte(this IArea area, byte value)
Writes a single byte into the given area.