System.Collections.Generic.List.Add(sbyte)

Here are the examples of the csharp api System.Collections.Generic.List.Add(sbyte) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

20 Examples 7

19 View Source File : Formatter.Array1.List.cs
License : MIT License
Project Creator : 1996v

public List<SByte> Deserialize(ref BssomReader reader, ref BssomDeserializeContext context)
        {
            if (reader.TryReadNullWithEnsureArray1BuildInType(BssomType.Int8Code))
            {
                return default;
            }

            context.Option.Security.DepthStep(ref context);
            reader.SkipVariableNumber();
            int len = reader.ReadVariableNumber();
            List<sbyte> val = new List<SByte>(len);
            for (int i = 0; i < len; i++)
            {
                val.Add(reader.ReadInt8WithOutTypeHead());
            }
            context.Depth--;
            return val;
        }

19 View Source File : ClipboardUtils.cs
License : MIT License
Project Creator : BleuBleu

public static sbyte[] GetStringEnvelopeData()
        {
            var str = PlatformUtils.GetClipboardString();

            if (!string.IsNullOrEmpty(str))
            {
                var values = new List<sbyte>();
                var splits = str.Split(Seperators, StringSplitOptions.RemoveEmptyEntries);
                foreach (var split in splits)
                {
                    if (int.TryParse(split, out var i))
                        values.Add((sbyte)Utils.Clamp(i, sbyte.MinValue, sbyte.MaxValue));
                    else
                        return null;
                }

                return values.Count > 0 ? values.ToArray() : null;
            }

            return null;
        }

19 View Source File : SmallIntSeries.cs
License : GNU General Public License v3.0
Project Creator : daviburg

public long GreatestProduct(int countOfAdjacentNumbers)
        {
            long greatestProduct = 0;
            var greatestProductFactors = new List<sbyte>();
            long runningProduct = 1;
            var sequentialDigits = new List<sbyte>();
            foreach (var digit in this.seriesOfSmallIntegers)
            {
                // Any zero will zero the product hence we can restart from an empty sequence after it
                if (digit == 0)
                {
                    sequentialDigits = new List<sbyte>();
                    runningProduct = 1;
                    continue;
                }

                sequentialDigits.Add(digit);
                runningProduct *= digit;

                // Test if we are at the desired count of adjacent digits
                if (sequentialDigits.Count == countOfAdjacentNumbers)
                {
                    // Capture new max product if any
                    if (runningProduct > greatestProduct)
                    {
                        greatestProduct = runningProduct;
                        greatestProductFactors = new List<sbyte>(sequentialDigits);
                    }

                    // To avoid recomputing the whole sequence, remove just the first/oldest digit
                    runningProduct /= sequentialDigits[0];
                    sequentialDigits.RemoveAt(0);
                }
            }

            // Enable the following line if you'd like to see what numbers were used to get the greatest product.
            ////Console.WriteLine($"The greatest product is {greatestProduct} from multiplying the {countOfAdjacentNumbers} numbers {String.Join(", ", greatestProductFactors.Select<sbyte, string>(digit => digit.ToString()))}.");
            return greatestProduct;
        }

19 View Source File : NDArray.cs
License : Apache License 2.0
Project Creator : deepakkumar1984

public static NDArrayList LoadNpz(string file)
        {
            NDArrayList result = new NDArrayList();
            using (ZipArchive zip = ZipFile.OpenRead(file))
            {
                foreach (ZipArchiveEntry entry in zip.Entries)
                {
                    Stream fs = entry.Open();
                    BinaryReader reader = new BinaryReader(fs);
                    var magic = reader.ReadChars(6);
                    var maj = reader.ReadByte();
                    var min = reader.ReadByte();
                    int headerLength = reader.ReadUInt16();
                    string header = new string(reader.ReadChars(headerLength)).Trim();
                    string mark = "'descr': '";
                    int s = header.IndexOf(mark) + mark.Length;
                    int e = header.IndexOf("'", s + 1);
                    string type = header.Substring(s, e - s);

                    DType dtype = GetNpyType(type);
                    mark = "'fortran_order': ";
                    s = header.IndexOf(mark) + mark.Length;
                    e = header.IndexOf(",", s + 1);
                    bool fortran = bool.Parse(header.Substring(s, e - s));

                    if (fortran)
                        throw new Exception();

                    mark = "'shape': (";
                    s = header.IndexOf(mark) + mark.Length;
                    e = header.IndexOf(")", s + 1);
                    var shapeSplit = header.Substring(s, e - s).Split(',');
                    List<int> shapeInt = new List<int>();
                    foreach (var element in shapeSplit)
                    {
                        if (!string.IsNullOrWhiteSpace(element))
                        {
                            shapeInt.Add(Convert.ToInt32(element));
                        }
                    }

                    Shape shape = new Shape(shapeInt);
                    if (dtype == DType.Int32)
                    {
                        List<int> data = new List<int>();
                        for (int i = 0; i < shape.Size; i++)
                        {
                            data.Add(reader.ReadInt32());
                        }

                        var x = nd.Array(data.ToArray()).AsType(dtype).Reshape(shape);
                        result.Add(x);
                    }
                    else if (dtype == DType.Int8)
                    {
                        List<sbyte> data = new List<sbyte>();
                        for (int i = 0; i < shape.Size; i++)
                        {
                            data.Add(reader.ReadSByte());
                        }

                        var x = nd.Array(data.ToArray()).AsType(dtype).Reshape(shape);
                        result.Add(x);
                    }
                    else if (dtype == DType.Int64)
                    {
                        List<long> data = new List<long>();
                        for (int i = 0; i < shape.Size; i++)
                        {
                            data.Add(reader.ReadSByte());
                        }

                        var x = nd.Array(data.ToArray()).AsType(dtype).Reshape(shape);
                        result.Add(x);
                    }
                    else if (dtype == DType.Float32)
                    {
                        List<float> data = new List<float>();
                        for (int i = 0; i < shape.Size; i++)
                        {
                            data.Add(reader.ReadSByte());
                        }

                        var x = nd.Array(data.ToArray()).AsType(dtype).Reshape(shape);
                        result.Add(x);
                    }
                    else if (dtype == DType.Float64)
                    {
                        List<double> data = new List<double>();
                        for (int i = 0; i < shape.Size; i++)
                        {
                            data.Add(reader.ReadSByte());
                        }

                        var x = nd.Array(data.Select(i => (float)i).ToArray()).AsType(dtype).Reshape(shape).AsType(dtype);
                        result.Add(x);
                    }
                    else if (dtype == DType.UInt8)
                    {
                        var data = reader.ReadBytes(Convert.ToInt32(shape.Size));

                        var x = nd.Array(data.Select(i => (float)i).ToArray()).Reshape(shape).AsType(dtype);
                        result.Add(x);
                    }
                }
            }

            return result;
        }

19 View Source File : SubstitutionArrayEntry.cs
License : MIT License
Project Creator : EricZimmerman

public string GetDatareplacedtring()
        {
            int index;
            switch (ValType)
            {
                case TagBuilder.ValueType.NullType:
                    return string.Empty;

                case TagBuilder.ValueType.StringType:
                    var s = Encoding.Unicode.GetString(DataBytes).Trim('\0');
                    s = Regex.Replace(s, @"\p{C}+", ", ");
                    return s;
                case TagBuilder.ValueType.AnsiStringType:
                    var sa = Encoding.GetEncoding(1252).GetString(DataBytes).Trim('\0');
                    sa = Regex.Replace(sa, @"\p{C}+", ", ");
                    return sa;
                case TagBuilder.ValueType.Int8Type:
                    return ((sbyte) DataBytes[0]).ToString();
                case TagBuilder.ValueType.UInt8Type:
                    return DataBytes[0].ToString();
                case TagBuilder.ValueType.Int16Type:
                    return BitConverter.ToInt16(DataBytes, 0).ToString();
                case TagBuilder.ValueType.UInt16Type:
                    return BitConverter.ToUInt16(DataBytes, 0).ToString();
                case TagBuilder.ValueType.Int32Type:
                    return BitConverter.ToInt32(DataBytes, 0).ToString();
                case TagBuilder.ValueType.UInt32Type:
                    return BitConverter.ToUInt32(DataBytes, 0).ToString();
                case TagBuilder.ValueType.Int64Type:
                    return BitConverter.ToInt64(DataBytes, 0).ToString();
                case TagBuilder.ValueType.UInt64Type:
                    return BitConverter.ToUInt64(DataBytes, 0).ToString();
                case TagBuilder.ValueType.Real32Type:
                    return BitConverter.ToSingle(DataBytes, 0).ToString(CultureInfo.InvariantCulture);
                case TagBuilder.ValueType.Real64Type:
                    return BitConverter.ToDouble(DataBytes, 0).ToString(CultureInfo.InvariantCulture);
                case TagBuilder.ValueType.BoolType:
                    return BitConverter.ToBoolean(DataBytes, 0).ToString();
                case TagBuilder.ValueType.BinaryType:
                    return BitConverter.ToString(DataBytes);
                case TagBuilder.ValueType.GuidType:
                    var g = new Guid(DataBytes);
                    return g.ToString();

                case TagBuilder.ValueType.SizeTType:
                    return BitConverter.ToString(DataBytes);

                case TagBuilder.ValueType.FileTimeType:
                    var fts = DateTimeOffset.FromFileTime(BitConverter.ToInt64(DataBytes, 0)).ToUniversalTime();
                    return fts.ToString("yyyy-MM-dd HH:mm:ss.fffffff");

                case TagBuilder.ValueType.SysTimeType:

                    var sts = GetSystemTime(DataBytes);

                    return sts.ToString("yyyy-MM-dd HH:mm:ss.fffffff");

                case TagBuilder.ValueType.SidType:
                    return ConvertHexStringToSidString(DataBytes);

                case TagBuilder.ValueType.HexInt32Type:
                    return $"0x{BitConverter.ToInt32(DataBytes, 0):X}";
                case TagBuilder.ValueType.HexInt64Type:
                    return $"0x{BitConverter.ToInt64(DataBytes, 0):X}";

                case TagBuilder.ValueType.EvtXml:
                case TagBuilder.ValueType.EvtHandle:
                    return "UNKNOWN: Please submit to [email protected]!";

                case TagBuilder.ValueType.BinXmlType:
                    return "BinaryXML";

                case TagBuilder.ValueType.ArrayUnicodeString:
                    var tsu = Encoding.Unicode.GetString(DataBytes)
                        .Split(new[] {'\0'}, StringSplitOptions.RemoveEmptyEntries);
                    return string.Join(", ", tsu).Trim('\0');

                case TagBuilder.ValueType.ArrayAsciiString:
                    var tsa = Encoding.GetEncoding(1252).GetString(DataBytes)
                        .Split(new[] {'\0'}, StringSplitOptions.RemoveEmptyEntries);
                    return string.Join(", ", tsa).Trim('\0');

                case TagBuilder.ValueType.Array64BitIntSigned:
                    var a64i = new List<long>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var ul = BitConverter.ToInt64(DataBytes, index);
                        index += 8;
                        a64i.Add(ul);
                    }

                    return string.Join(",", a64i);

                case TagBuilder.ValueType.Array64BitIntUnsigned:
                    var a64ui = new List<ulong>();

                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var ul = BitConverter.ToUInt64(DataBytes, index);
                        index += 8;
                        a64ui.Add(ul);
                    }

                    return string.Join(",", a64ui);

                case TagBuilder.ValueType.Array16BitIntUnsigned:
                    var a16ui = new List<ushort>();

                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var ul = BitConverter.ToUInt16(DataBytes, index);
                        index += 2;
                        a16ui.Add(ul);
                    }

                    return string.Join(",", a16ui);

                case TagBuilder.ValueType.Array16BitIntSigned:
                    var a16i = new List<short>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var ul = BitConverter.ToInt16(DataBytes, index);
                        index += 2;
                        a16i.Add(ul);
                    }

                    return string.Join(",", a16i);

                case TagBuilder.ValueType.Array32BitIntSigned:
                    var a32i = new List<int>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var ul = BitConverter.ToInt32(DataBytes, index);
                        index += 4;
                        a32i.Add(ul);
                    }

                    return string.Join(",", a32i);
                case TagBuilder.ValueType.Array32BitIntUnsigned:
                    var a32ui = new List<uint>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var ul = BitConverter.ToUInt32(DataBytes, index);
                        index += 4;
                        a32ui.Add(ul);
                    }

                    return string.Join(",", a32ui);

                case TagBuilder.ValueType.Array8BitIntSigned:
                    var sb = new List<sbyte>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        sb.Add((sbyte) DataBytes[index]);
                        index += 1;
                    }

                    return string.Join(",", sb);

                case TagBuilder.ValueType.Array8BitIntUnsigned:
                    var b = new List<byte>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        b.Add(DataBytes[index]);
                        index += 1;
                    }

                    return string.Join(",", b);

                case TagBuilder.ValueType.ArrayFloat32Bit:
                    var sl = new List<float>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var sn = BitConverter.ToSingle(DataBytes, index);
                        index += 4;
                        sl.Add(sn);
                    }

                    return string.Join(",", sl);

                case TagBuilder.ValueType.ArrayFloat64Bit:
                    var dl = new List<double>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var dn = BitConverter.ToDouble(DataBytes, index);
                        index += 4;
                        dl.Add(dn);
                    }

                    return string.Join(",", dl);

                case TagBuilder.ValueType.ArrayBool:
                    var boo = new List<bool>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var bv = BitConverter.ToInt32(DataBytes, index) != 0;
                        boo.Add(bv);
                        index += 4;
                    }

                    return string.Join(",", boo);

                case TagBuilder.ValueType.ArrayFileTime:
                    var dto = new List<string>();
                    index = 0;
                    while (index < DataBytes.Length)
                    {
                        var ts = DateTime.FromFileTime(BitConverter.ToInt64(DataBytes, index)).ToUniversalTime();
                        dto.Add(ts.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
                        index += 8;
                    }

                    return string.Join(",", dto);

                case TagBuilder.ValueType.ArraySystemTime:
                    var st = new List<string>();
                    index = 0;

                    while (index < DataBytes.Length)
                    {
                        var stb = new byte[16];
                        Buffer.BlockCopy(DataBytes, index, stb, 0, 16);
                        index += 16;

                        var nst = GetSystemTime(stb).ToUniversalTime();

                        st.Add(nst.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
                    }

                    return string.Join(",", st);

                case TagBuilder.ValueType.ArrayGuid:
                    var gl = new List<string>();
                    index = 0;

                    while (index < DataBytes.Length)
                    {
                        var gb = new byte[16];
                        Buffer.BlockCopy(DataBytes, index, gb, 0, 16);
                        index += 16;
                        var ng = new Guid(gb);
                        gl.Add(ng.ToString());
                    }

                    return string.Join(",", gl);
                case TagBuilder.ValueType.ArraySizeType:

                case TagBuilder.ValueType.ArraySids:
                case TagBuilder.ValueType.Array32BitHex:
                case TagBuilder.ValueType.Array64BitHex:

                default:
                    throw new ArgumentOutOfRangeException(
                        $"When converting subsreplacedution array entry to string, ran into unknown Value type: {ValType}. Please submit to [email protected]!");
            }
        }

19 View Source File : BinaryReaderExtension.List.cs
License : MIT License
Project Creator : FingerCaster

public static List<sbyte> ReadSByteList(this BinaryReader binaryReader)
		{
			int count = binaryReader.Read7BitEncodedInt32();
			List<sbyte> list = new List<sbyte>(count);
			for (int i = 0; i < count; i++)
			{
				list.Add(binaryReader.ReadSByte());
			}
			return list;
		}

19 View Source File : DataTableExtension.List.cs
License : MIT License
Project Creator : FingerCaster

public static List<sbyte> ParseSByteList(string value)
		{
			if (string.IsNullOrEmpty(value) || value.ToLowerInvariant().Equals("null"))
				return null;
			string[] splitValue = value.Split(',');
			List<sbyte> list = new List<sbyte>(splitValue.Length);
			for (int i = 0; i < splitValue.Length; i++)
			{
				list.Add(SByte.Parse(splitValue[i]));
			}
			return list;
		}

19 View Source File : TritsConverter.cs
License : Apache License 2.0
Project Creator : iotaledger

public static sbyte[] ToTrits(string trytes, int length)
        {
            var tritss = ToTrits(trytes);

            var tritsList = new List<sbyte>(tritss);

            while (tritsList.Count < length)
                tritsList.Add(0);

            return tritsList.ToArray();
        }

19 View Source File : TritsConverter.cs
License : Apache License 2.0
Project Creator : iotaledger

public static sbyte[] ToTrits(long trytes, int length)
        {
            var tritss = ToTrits(trytes);

            var tritsList = new List<sbyte>(tritss);

            while (tritsList.Count < length)
                tritsList.Add(0);

            return tritsList.ToArray();
        }

19 View Source File : TritsConverter.cs
License : Apache License 2.0
Project Creator : iotaledger

public static sbyte[] ToTrits(long trytes)
        {
            if (trytes == 0)
                return new sbyte[] {0};

            var tritsList = new List<sbyte>();

            while (trytes != 0)
            {
                var remainder = (sbyte) (trytes % 3);
                trytes /= 3;

                if (remainder > MaxTritValue)
                {
                    remainder = MinTritValue;
                    trytes += 1;
                }
                else if (remainder < MinTritValue)
                {
                    remainder = MaxTritValue;
                    trytes -= 1;
                }

                tritsList.Add(remainder);
            }

            return tritsList.ToArray();
        }

19 View Source File : Utils.cs
License : GNU Lesser General Public License v3.0
Project Creator : Kermalis

public static sbyte[] Decompress(int sampleOffset, int sampleLength)
        {
            var config = (Config)Engine.Instance.Config;
            var samples = new List<sbyte>();
            sbyte compressionLevel = 0;
            int compressionByte = 0, compressionIdx = 0;

            for (int i = 0; true; i++)
            {
                byte b = config.ROM[sampleOffset + i];
                if (compressionByte == 0)
                {
                    compressionByte = 0x20;
                    compressionLevel = (sbyte)b;
                    samples.Add(compressionLevel);
                    if (++compressionIdx >= sampleLength)
                    {
                        break;
                    }
                }
                else
                {
                    if (compressionByte < 0x20)
                    {
                        compressionLevel += _compressionLookup[b >> 4];
                        samples.Add(compressionLevel);
                        if (++compressionIdx >= sampleLength)
                        {
                            break;
                        }
                    }
                    compressionByte--;
                    compressionLevel += _compressionLookup[b & 0xF];
                    samples.Add(compressionLevel);
                    if (++compressionIdx >= sampleLength)
                    {
                        break;
                    }
                }
            }

            return samples.ToArray();
        }

19 View Source File : ModelLoader.cs
License : Mozilla Public License 2.0
Project Creator : mcneel

public static dynamic AccessBuffer(Accessor.TypeEnum accessorType, int count, Accessor.ComponentTypeEnum componentType, int stride, byte[] arr)
        {
            dynamic result = null;

            var elementCount = count;                                   //how many times do we need to do this?
            var componentCount = GetTypeMultiplier(accessorType); ;     //each time we do this, how many times do I need to read the buffer?
            var byteCount = GetComponentTypeMultiplier(componentType);  //how many bytes is each component from ComponentTypeEnum
            var elementBytes = componentCount * byteCount;

            var strideDiff = stride > 0 ? stride - elementBytes : 0;

            using (var memoryStream = new MemoryStream(arr))
            using (var reader = new BinaryReader(memoryStream))
            {
                // TODO: clean this up
                switch (componentType)
                {
                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.BYTE:

                        var listSByte = new List<sbyte>();

                        //loop through element count

                        //loop through component count
                        //if stride, position the reader appropriately
                        // element bytes should be byteCount * componentCount
                        // stride diff should be stride - elementbytes

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listSByte.Add(reader.ReadSByte());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listSByte;

                        break;
                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.FLOAT:

                        var listSingle = new List<Single>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listSingle.Add(reader.ReadSingle());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listSingle;

                        break;

                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.SHORT:

                        var listShort = new List<Int16>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listShort.Add(reader.ReadInt16());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listShort;

                        break;

                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_BYTE:

                        var listByte = new List<byte>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listByte.Add(reader.ReadByte());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listByte;

                        break;
                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_INT:

                        var listUInt = new List<uint>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listUInt.Add(reader.ReadUInt32());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listUInt;

                        break;
                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_SHORT:

                        var listUInt16 = new List<UInt16>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listUInt16.Add(reader.ReadUInt16());
                            }

                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listUInt16;

                        break;
                }

            }

            return result;
        }

19 View Source File : Mocker.cs
License : MIT License
Project Creator : night-moon-studio

public static List<sbyte> MockListSbyte(int? len = null, bool notNull = false)
        {
            List<sbyte> result = null;
            if (!notNull)
                if (random.Next(0, 10) == 5)
                    return result;

            result = new List<sbyte>();
            len = len ?? random.Next(1, 100);
            for (int i = 0; i < len; i++)
                result.Add((sbyte)((random.NextDouble() * sbyte.MaxValue) * (random.Next(0, 2) == 0 ? 1 : -1)));

            return result;
        }

19 View Source File : cTSOValueSByteVector.cs
License : Mozilla Public License 2.0
Project Creator : RHY3756547

public object Deserialize(uint clsid, IoBuffer input, ISerializationContext serializer)
        {
            var result = new List<sbyte>();
            var count = input.GetUInt32();
            for(int i=0; i < count; i++){
                result.Add((sbyte)input.Get());
            }
            return ImmutableList.ToImmutableList(result);
        }

19 View Source File : Storage.cs
License : GNU General Public License v3.0
Project Creator : SvenMertin

public virtual void WriteByte(int value)
        {
            if (value < -128 || value > 127)
                throw new ArgumentException("Error writing byte: byte value may only range from -128 to 127.");
            storageList.Add(Convert.ToSByte(value));
        }

19 View Source File : Storage.cs
License : GNU General Public License v3.0
Project Creator : SvenMertin

public virtual void WriteUnsignedByte(int value)
        {
            if (value < 0 || value > 255)
                throw new ArgumentException("Error writing unsigned byte: byte value may only range from 0 to 255.");
            if (value > 127)
            {
                storageList.Add(Convert.ToSByte(value - 256));
            }
            else
                storageList.Add(Convert.ToSByte(value));
        }

19 View Source File : IsoMessage.cs
License : MIT License
Project Creator : Tochemey

public void Write(List<sbyte> outs,
      int lengthBytes)
    {
      if (lengthBytes > 4) throw new ArgumentException("The length header can have at most 4 bytes");

      var data = WriteData();

      if (lengthBytes > 0)
      {
        var len = data.Length;
        if (Etx > -1) len++;
        var buf = new sbyte[lengthBytes];
        var pos = 0;
        if (lengthBytes == 4)
        {
          buf[0] = (sbyte)((len & 0xff000000) >> 24);
          pos++;
        }

        if (lengthBytes > 2)
        {
          buf[pos] = (sbyte)((len & 0xff0000) >> 16);
          pos++;
        }

        if (lengthBytes > 1)
        {
          buf[pos] = (sbyte)((len & 0xff00) >> 8);
          pos++;
        }

        buf[pos] = (sbyte)(len & 0xff);
        outs.AddRange(buf);
      }


      outs.AddRange(data);

      //ETX
      if (Etx > -1) outs.Add((sbyte)Etx);
    }

19 View Source File : IsoMessage.cs
License : MIT License
Project Creator : Tochemey

public sbyte[] WriteData()
    {
      var sbyteList = new List<sbyte>();
      var stream = new MemoryStream();
      if (IsoHeader != null)
        try
        {
          var bytes = IsoHeader.GetSignedBytes(Encoding);
          sbyteList.AddRange(bytes);
        }
        catch (IOException)
        {
          //should never happen, writing to a ByteArrayOutputStream
        }
      else if (BinIsoHeader != null)
        try
        {
          sbyteList.AddRange(BinIsoHeader);
        }
        catch (IOException)
        {
          //should never happen, writing to a ByteArrayOutputStream
        }

      //Message Type
      if (Binary)
      {
        sbyteList.Add((sbyte)((Type & 0xff00) >> 8));
        sbyteList.Add((sbyte)(Type & 0xff));
      }
      else
      {
        try
        {
          var x = Type.ToString("x4");
          var bytes = x.GetSignedBytes(Encoding);
          sbyteList.AddRange(bytes);
        }
        catch (IOException)
        {
          //should never happen, writing to a ByteArrayOutputStream
        }
      }

      //Bitmap
      var bits = CreateBitmapBitSet();

      // Write bitmap to stream
      if (Binary || BinBitmap)
      {
        var pos = 128;
        var b = 0;
        for (var i = 0; i < bits.Length; i++)
        {
          if (bits.Get(i)) b |= pos;
          pos >>= 1;
          if (pos != 0) continue;
          sbyteList.Add((sbyte)b);
          pos = 128;
          b = 0;
        }
      }
      else
      {
        var sbyteList2 = new List<sbyte>();
        if (ForceStringEncoding)
        {
          sbyteList2 = sbyteList;
          sbyteList = new List<sbyte>();
        }

        var pos = 0;
        var lim = bits.Length / 4;
        for (var i = 0; i < lim; i++)
        {
          var nibble = 0;
          if (bits.Get(pos++)) nibble |= 8;
          if (bits.Get(pos++)) nibble |= 4;
          if (bits.Get(pos++)) nibble |= 2;
          if (bits.Get(pos++)) nibble |= 1;
          sbyteList.Add(Hex[nibble]);
        }

        if (ForceStringEncoding)
        {
          var hb = sbyteList.ToArray().ToString(Encoding.Default);
          sbyteList = sbyteList2;
          try
          {
            sbyteList.AddRange(hb.GetSignedBytes(Encoding));
          }
          catch (IOException)
          {
            //never happen
          }
        }
      }

      var byteArray = sbyteList.ToArray().ToUint8();
      stream.Write(byteArray,
        0,
        byteArray.Length);

      //Fields
      for (var i = 2; i < 129; i++)
      {
        var v = _fields[i];
        if (v == null) continue;
        try
        {
          v.Write(stream,
            Binary,
            ForceStringEncoding);
        }
        catch (IOException)
        {
          //should never happen, writing to a ByteArrayOutputStream
        }
      }

      return stream.ToArray().ToInt8();
    }

19 View Source File : IsoMessage.cs
License : MIT License
Project Creator : Tochemey

public sbyte[] WriteToBuffer(int lengthBytes)
    {
      if (lengthBytes > 4) throw new ArgumentException("The length header can have at most 4 bytes");
      var data = WriteData();
      var stream = new List<sbyte>(lengthBytes + data.Length + (Etx > -1 ? 1 : 0));
      if (lengthBytes > 0)
      {
        var len = data.Length;
        if (Etx > -1) len++;
        if (lengthBytes == 4) stream.Add((sbyte)((len & 0xff000000) >> 24));
        if (lengthBytes > 2) stream.Add((sbyte)((len & 0xff0000) >> 16));
        if (lengthBytes > 1) stream.Add((sbyte)((len & 0xff00) >> 8));
        stream.Add((sbyte)(len & 0xff));
      }

      stream.AddRange(data);

      //ETX
      if (Etx > -1) stream.Add((sbyte)Etx);

      return stream.ToArray();
    }

19 View Source File : SwiftArrayTests.cs
License : MIT License
Project Creator : xamarin

[Test]
		public void IEnumerable ()
		{
			using (var arr = new SwiftArray<sbyte> (1, 2, 3, 4, 5, 6, 7, 8, 9)) {
				var list = new List<sbyte> ();
				foreach (var item in arr)
					list.Add (item);
				Collectionreplacedert.AreEqual (new sbyte [] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, list, "Enumerator");

				arr.Dispose ();
				var enumerator = arr.GetEnumerator (); // No exception
				replacedert.Throws<ObjectDisposedException> (() => { foreach (var x in arr) { } }, "Enumerator ODE 3");
				replacedert.Throws<ObjectDisposedException> (() => { enumerator.MoveNext (); }, "Enumerator ODE 2");
				replacedert.DoesNotThrow (() => { var x = enumerator.Current; }, "Enumerator !ODE");
			}
		}