public void Concat(IOptionalMap otherMap) { int size = otherMap.GetSize(); for (int i = 0; i < size; i++) { this.Add(((OptionalMap)otherMap).GetBit(i)); } }
public static void EncodeOptionalMap(IOptionalMap optionalMap, Stream dest) { int size = optionalMap.GetSize(); byte[] map = ((OptionalMap)optionalMap).GetMap(); if (size <= 5) { dest.WriteByte((byte)(map[0] >> 3)); } else if (size <= 13) { dest.WriteByte((byte)((map[0] >> 3) + 0x20)); dest.WriteByte((byte)((map[1] >> 3) + (map[0] << 5))); } else if (size <= 0x15) { dest.WriteByte((byte)((map[0] >> 3) + 0x40)); dest.WriteByte((byte)((map[1] >> 3) + (map[0] << 5))); dest.WriteByte((byte)((map[2] >> 3) + (map[1] << 5))); } else if (size <= 0x1d) { dest.WriteByte((byte)((map[0] >> 3) + 0x60)); dest.WriteByte((byte)((map[1] >> 3) + (map[0] << 5))); dest.WriteByte((byte)((map[2] >> 3) + (map[1] << 5))); dest.WriteByte((byte)((map[3] >> 3) + (map[2] << 5))); } else if (size <= 0x1f8) { int length = (size >> 3) + (((size & 7) != 0) ? 1 : 0); byte[] destinationArray = new byte[] { (byte)((length & 0xff) + 0x80) }; Array.Copy(map, 0, destinationArray, 1, length); dest.Write(destinationArray, 0, destinationArray.Length); } else { if (size > 0x2000000) { throw new IndexOutOfRangeException("NullMap overflow"); } int length = (size >> 3) + (((size & 7) != 0) ? 1 : 0); int num5 = length + 0xc00000; byte[] destinationArray = new byte[] { (byte)((num5 & 0xff0000) >> 0x10), (byte)((num5 & 0xff00) >> 8), (byte)(num5 & 0xff) }; Array.Copy(map, 0, destinationArray, 3, length); dest.Write(destinationArray, 0, destinationArray.Length); } }
public ProtocolBuffer(IOptionalMap optionalMap, MemoryStreamData stream) { this.OptionalMap = optionalMap; this.Data = stream; }