2 * Firebird ADO.NET Data provider for .NET and Mono
\r
4 * The contents of this file are subject to the Initial
\r
5 * Developer's Public License Version 1.0 (the "License");
\r
6 * you may not use this file except in compliance with the
\r
7 * License. You may obtain a copy of the License at
\r
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
\r
10 * Software distributed under the License is distributed on
\r
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
\r
12 * express or implied. See the License for the specific
\r
13 * language governing rights and limitations under the License.
\r
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
\r
16 * All Rights Reserved.
\r
24 namespace FirebirdSql.Data.Common
\r
26 internal abstract class ParameterBuffer
\r
30 private MemoryStream stream;
\r
31 private bool isLittleEndian;
\r
39 get { return (short)this.ToArray().Length; }
\r
44 #region Protected properties
\r
46 protected bool IsLittleEndian
\r
48 get { return this.isLittleEndian; }
\r
53 #region Constructors
\r
55 protected ParameterBuffer() : this(false)
\r
59 protected ParameterBuffer(bool isLittleEndian)
\r
61 this.stream = new MemoryStream();
\r
62 this.isLittleEndian = isLittleEndian;
\r
67 #region Protected Methods
\r
69 protected void WriteByte(int value)
\r
71 this.WriteByte((byte)value);
\r
74 protected void WriteByte(byte value)
\r
76 this.stream.WriteByte(value);
\r
79 protected void Write(short value)
\r
81 if (!this.IsLittleEndian)
\r
83 value = (short)IPAddress.NetworkToHostOrder(value);
\r
86 byte[] buffer = BitConverter.GetBytes(value);
\r
88 this.stream.Write(buffer, 0, buffer.Length);
\r
91 protected void Write(int value)
\r
93 if (!this.IsLittleEndian)
\r
95 value = (int)IPAddress.NetworkToHostOrder(value);
\r
98 byte[] buffer = BitConverter.GetBytes(value);
\r
100 this.stream.Write(buffer, 0, buffer.Length);
\r
103 protected void Write(byte[] buffer)
\r
105 this.Write(buffer, 0, buffer.Length);
\r
108 protected void Write(byte[] buffer, int offset, int count)
\r
110 this.stream.Write(buffer, offset, count);
\r
117 public virtual void Append(int type)
\r
119 this.WriteByte(type);
\r
122 public byte[] ToArray()
\r
124 return stream.ToArray();
\r