public static void DeSerializeHeader(byte[] data, long offset, out int length, out bool deleted) { /*Header: * byte[4] longitud <- delante para mantener el alineamiento de la memoria. * byte flags: * 0x01 = Borrado */ length = PointerCastHelper.BytesToInt(data, offset); deleted = (data[offset + 4] & 0x01) == 0x01; }
public void Int() { var real_bytes = BitConverter.GetBytes(12345678); Assert.AreEqual(12345678, PointerCastHelper.BytesToInt(real_bytes, 0), "No se convirtió el puntero correctamente"); Assert.AreEqual(real_bytes[0], PointerCastHelper.IntToBytes(12345678)[0], "No se convirtió a un array de bytes correctamente"); Assert.AreEqual(real_bytes[1], PointerCastHelper.IntToBytes(12345678)[1], "No se convirtió a un array de bytes correctamente"); Assert.AreEqual(real_bytes[2], PointerCastHelper.IntToBytes(12345678)[2], "No se convirtió a un array de bytes correctamente"); Assert.AreEqual(real_bytes[3], PointerCastHelper.IntToBytes(12345678)[3], "No se convirtió a un array de bytes correctamente"); }
public bool MoveNext() { if (data.Length == 0) { return(false); } if (current_offset == -1) { current_offset = 0; //todo: optimize! importante que esto sea óptimo dado que es el iterador principal //movemos el cursor hacia adelante el largo del registro. bool deleted; int length; SerializationHelper .DeSerializeHeader(data, current_offset, out length, out deleted); if (deleted) { return(MoveNext()); } if (data.Length > 0) { return(true); } } else { //todo: optimize! importante que esto sea óptimo dado que es el iterador principal int length = PointerCastHelper.BytesToInt(data, current_offset); //movemos el cursor hacia adelante el largo del registro. current_offset += length + Constants.RECORD_HEADER_SIZE; if (current_offset >= data.Length) { return(false); } bool deleted = (data[current_offset + 5] & 0x01) == 0x01; if (deleted) { return(MoveNext()); } if (data.Length > current_offset)//??? { return(true); } } return(false); }
public void Serialize() { var model = new testmodel() { value = 1, value3 = 2D, text1 = "texto 1", text2 = "otro texto de prueba" }; byte[] serialization = SerializationHelper.Serialize <ITestModel>(model); //según la ordenación, lo primero debería ser el campo más grande, el double, después el entero y los strings. Assert.AreEqual(1, PointerCastHelper.BytesToInt(serialization, 8)); Assert.AreEqual(2D, PointerCastHelper.BytesToDouble(serialization, 0)); Assert.AreEqual("texto 1", PointerCastHelper.GetStringAtOffset(serialization, 12, 0)); Assert.AreEqual("otro texto de prueba", PointerCastHelper.GetStringAtOffset(serialization, 12, 1)); }