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