fix: Fixes BitArray serialization (#1027)
Fixes bit array serialization. This may cause objects that were serialized by bit array to fail to deserialize. I am sorry, please accept my condolences. It is probably easiest to just delete those objects. If it becomes a major problem, contact me and I'll help with a hacky per-case solution.
This commit is contained in:
parent
6ea5508f5f
commit
6b3617b08f
4 changed files with 207 additions and 167 deletions
|
|
@ -159,13 +159,15 @@ namespace Server
|
|||
|
||||
public BitArray ReadBitArray()
|
||||
{
|
||||
var length = ((IGenericReader)this).ReadEncodedInt();
|
||||
var bitLength = ((IGenericReader)this).ReadEncodedInt();
|
||||
var length = BitArray.GetByteArrayLengthFromBitLength(bitLength);
|
||||
|
||||
if (length > _buffer.Length - _position)
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
||||
var bitArray = new BitArray(_buffer.AsSpan(_position, length));
|
||||
var bitArray = new BitArray(_buffer.AsSpan(_position, length), bitLength);
|
||||
_position += length;
|
||||
return bitArray;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,9 +138,9 @@ namespace Server
|
|||
public void Write(BitArray bitArray)
|
||||
{
|
||||
var byteLength = BitArray.GetByteArrayLengthFromBitLength(bitArray.Length);
|
||||
FlushIfNeeded(byteLength + 4);
|
||||
|
||||
((IGenericWriter)this).WriteEncodedInt(byteLength);
|
||||
((IGenericWriter)this).WriteEncodedInt(bitArray.Length);
|
||||
FlushIfNeeded(byteLength);
|
||||
bitArray.CopyTo(_buffer.AsSpan((int)Index, byteLength));
|
||||
Index += byteLength;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue