Example #1
0
            private static byte[] Marker(long size)
            {
                if (size <= 15)
                {
                    return new[] { (byte)(0x80 + size) }
                }
                ;

                var output = new List <byte>();

                if (size <= 255)
                {
                    output.Add(0xD0);
                }

                else if (size <= 65535)
                {
                    output.Add(0xD1);
                }

                else if (size <= 4294967295)
                {
                    output.Add(0xD2);
                }

                if (size > uint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(size), size, "Size given is too big.");
                }

                output.AddRange(PackStream.GetLength(size));
                return(output.ToArray());
            }
Example #2
0
            private static byte[] GetMarker(long fields)
            {
                if (fields <= 15)
                {
                    return new[] { (byte)(0xA0 + fields) }
                }
                ;

                var output = new List <byte>();

                if (fields <= byte.MaxValue)
                {
                    output.Add(0xD8);
                }

                if (fields <= ushort.MaxValue)
                {
                    output.Add(0xD9);
                }

                if (fields <= uint.MaxValue)
                {
                    output.Add(0xDA);
                }

                if (fields > uint.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(fields), "Too many fields defined!");
                }

                output.AddRange(PackStream.GetLength(fields));
                return(output.ToArray());
            }