public class UpdateMask { public void Clear() { m_updateValues = new SortedDictionary(); m_mask = new byte[m_count/8]; } public void SetCount(int valuesCount) { m_updateValues = new SortedDictionary(); m_count = valuesCount; m_blocks = (valuesCount + 31) / 32; Console.WriteLine("blocks: {0}",m_blocks); m_mask = new byte[m_count/8]; Console.WriteLine("num bits: {0}", valuesCount); } public void Write(RealmPacketOut packet) { packet.WriteByte((byte)m_blocks); Console.WriteLine("BitMask len: {0}",m_count); for (int i = 0; i < m_mask.Length; i++) { packet.WriteByte(m_mask[i]); } foreach (uint value in m_updateValues.Values) { packet.WriteBE(value); } } public void SetBit(int index) { m_mask[index/8] |= (byte) (1 << index); } public void SetBit(int index, uint value) { SetBit(index); m_updateValues.Add(index,value); } public void SetBit(int index, ulong value) { SetBit(index); SetBit(index+1); m_updateValues.Add(index, BitConverter.ToUInt32(BitConverter.GetBytes(value), 0)); m_updateValues.Add(index + 1, BitConverter.ToUInt32(BitConverter.GetBytes(value), 4)); } public bool GetBit(int index) { return (m_mask[index/8] & (1 << index)) == 0; } int m_count; int m_blocks; private byte[] m_mask; private SortedDictionary m_updateValues; }