public override object Decode(byte[] encoded, Type type) { if (!IsSupportedType(type)) { throw new NotSupportedException(type + " is not supported"); } var decoded = _intTypeDecoder.DecodeInt(encoded); return(Convert.ToBoolean(decoded)); }
protected virtual object DecodeDynamicElementType(byte[] encoded, Type type, int size) { var decodedListOutput = (IList)Activator.CreateInstance(type); if (decodedListOutput == null) { throw new Exception("Only types that implement IList<T> are supported to decode Array Types"); } var elementType = GetIListElementType(type); if (elementType == null) { throw new Exception("Only types that implement IList<T> are supported to decode Array Types"); } var intDecoder = new IntTypeDecoder(); var dataIndexes = new List <int>(); var currentIndex = 0; while (currentIndex < size) { dataIndexes.Add(intDecoder.DecodeInt(encoded.Skip(currentIndex * 32).Take(32).ToArray())); currentIndex++; } currentIndex = 0; while (currentIndex < size) { var currentDataIndex = dataIndexes[currentIndex]; var nextDataIndex = encoded.Length; if (currentIndex + 1 < dataIndexes.Count) { nextDataIndex = dataIndexes[currentIndex + 1]; } var encodedElement = encoded.Skip(currentDataIndex).Take(nextDataIndex - currentDataIndex).ToArray(); DecodeAndAddElement(elementType, decodedListOutput, encodedElement); currentIndex++; } return(decodedListOutput); }