70 lines
2.6 KiB
C#
70 lines
2.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
|
|
using BCG.Utilities;
|
|
//using BCG.Utilities.BlueConfiguration;
|
|
|
|
namespace BCG {
|
|
/// <summary>
|
|
/// Helps the ClientUniversalDeserializer in deserilizing by dealing with the deserialization process
|
|
/// of one row. This leaves the ClientUniversalDeserializer to deserializer headers (indicating operations)
|
|
/// </summary>
|
|
internal class ClientUniversalRowDeserializer : IClientRowDeserializer {
|
|
private IBlueTableSchema mySchema;
|
|
private int myNullMapLength = 0;
|
|
private PrimitiveDeserializationHelper myDeserializationHelper;
|
|
private BitArray myNullMap;
|
|
private int[] mySerIndexToSchemaIndexMap;
|
|
|
|
public ClientUniversalRowDeserializer(IBlueTableSchema schema) {
|
|
myDeserializationHelper = new PrimitiveDeserializationHelper(mySchema = schema);
|
|
myNullMapLength = Convert.ToInt32((Math.Ceiling(Convert.ToDouble(mySchema.columnNames.Length) / 8)));
|
|
myInitReorderSchema();
|
|
|
|
|
|
}
|
|
|
|
#region Schema Reordering initialization
|
|
private void myInitReorderSchema() {
|
|
try {
|
|
int idColIndex = mySchema["id"].colNo;
|
|
int[] temp = new int[mySchema.columnInfo.Length];
|
|
foreach (ColumnInfo ci in mySchema.columnInfo) {
|
|
temp[ci.colNo] =
|
|
ci.colNo == idColIndex ? 0 :
|
|
ci.colNo < idColIndex ? ci.colNo + 1 : ci.colNo;
|
|
}
|
|
mySerIndexToSchemaIndexMap = new int[temp.Length];
|
|
for (int i = 0; i < temp.Length; i++)
|
|
mySerIndexToSchemaIndexMap[temp[i]] = i;
|
|
} catch (Exception ex) {
|
|
string schema_name = mySchema == null ? "NULL" : mySchema.tableName;
|
|
string err_msg = $"ClientUniversalRowDeserializer.myInitReorderSchema table: {schema_name} ex: {ex}";
|
|
bts.Log.Gen.error(err_msg);
|
|
throw new ApplicationException(err_msg);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region IClientRowDeserializer Members
|
|
|
|
public void deserializeRow(IBlueRowCollection currentState, BinaryReader br, byte op, out IBlueRow r) {
|
|
br.ReadInt32(); //length information for the row not needed
|
|
myNullMap = new BitArray(br.ReadBytes(myNullMapLength));
|
|
object[] values = new object[mySchema.columnNames.Length];
|
|
for (int i = 0; i < values.Length; i++) {
|
|
int colNo = mySerIndexToSchemaIndexMap[i];
|
|
values[mySerIndexToSchemaIndexMap[i]] = myNullMap[colNo] ? DBNull.Value : myDeserializationHelper.deserializeColumn(colNo, br);
|
|
}
|
|
|
|
|
|
r = new BlueRow(mySchema, values);
|
|
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
}
|