예제 #1
0
 public TransmissionType(TransmissionTypeIdentifier identifier, TransmissionTypeClass cls, int index, uint offset, ulong contentLength, byte exponent = 0)
 {
     Identifier    = identifier;
     Index         = index;
     Class         = cls;
     Offset        = offset;
     ContentLength = contentLength;
     Exponent      = exponent;
 }
예제 #2
0
    public static byte[] Compose(TransmissionTypeIdentifier identifier, byte[] data)
    {
        if (data == null || data.Length == 0)
        {
            return new byte[] { (byte)identifier }
        }
        ;

        var cls = (TransmissionTypeClass)((int)identifier >> 6);

        if (cls == TransmissionTypeClass.Fixed)
        {
            return(DC.Combine(new byte[] { (byte)identifier }, 0, 1, data, 0, (uint)data.Length));
        }
        else
        {
            var len = (ulong)data.LongLength;

            if (len == 0)
            {
                return(new byte[1] {
                    (byte)identifier
                });
            }
            else if (len <= 0xFF)
            {
                var rt = new byte[2 + len];
                rt[0] = (byte)((byte)identifier | 0x8);
                rt[1] = (byte)len;
                Buffer.BlockCopy(data, 0, rt, 2, (int)len);
                return(rt);
            }
            else if (len <= 0xFF_FF)
            {
                var rt = new byte[3 + len];
                rt[0] = (byte)((byte)identifier | 0x10);
                rt[1] = (byte)((len >> 8) & 0xFF);
                rt[2] = (byte)(len & 0xFF);
                Buffer.BlockCopy(data, 0, rt, 3, (int)len);
                return(rt);
            }
            else if (len <= 0xFF_FF_FF)
            {
                var rt = new byte[4 + len];
                rt[0] = (byte)((byte)identifier | 0x18);
                rt[1] = (byte)((len >> 16) & 0xFF);
                rt[2] = (byte)((len >> 8) & 0xFF);
                rt[3] = (byte)(len & 0xFF);
                Buffer.BlockCopy(data, 0, rt, 4, (int)len);
                return(rt);
            }
            else if (len <= 0xFF_FF_FF_FF)
            {
                var rt = new byte[5 + len];
                rt[0] = (byte)((byte)identifier | 0x20);
                rt[1] = (byte)((len >> 24) & 0xFF);
                rt[2] = (byte)((len >> 16) & 0xFF);
                rt[3] = (byte)((len >> 8) & 0xFF);
                rt[4] = (byte)(len & 0xFF);
                Buffer.BlockCopy(data, 0, rt, 5, (int)len);
                return(rt);
            }
            else if (len <= 0xFF_FF_FF_FF_FF)
            {
                var rt = new byte[6 + len];
                rt[0] = (byte)((byte)identifier | 0x28);
                rt[1] = (byte)((len >> 32) & 0xFF);
                rt[2] = (byte)((len >> 24) & 0xFF);
                rt[3] = (byte)((len >> 16) & 0xFF);
                rt[4] = (byte)((len >> 8) & 0xFF);
                rt[5] = (byte)(len & 0xFF);
                Buffer.BlockCopy(data, 0, rt, 6, (int)len);
                return(rt);
            }
            else if (len <= 0xFF_FF_FF_FF_FF_FF)
            {
                var rt = new byte[7 + len];
                rt[0] = (byte)((byte)identifier | 0x30);
                rt[1] = (byte)((len >> 40) & 0xFF);
                rt[2] = (byte)((len >> 32) & 0xFF);
                rt[3] = (byte)((len >> 24) & 0xFF);
                rt[4] = (byte)((len >> 16) & 0xFF);
                rt[5] = (byte)((len >> 8) & 0xFF);
                rt[6] = (byte)(len & 0xFF);
                Buffer.BlockCopy(data, 0, rt, 7, (int)len);
                return(rt);
            }
            else //if (len <= 0xFF_FF_FF_FF_FF_FF_FF)
            {
                var rt = new byte[8 + len];
                rt[0] = (byte)((byte)identifier | 0x38);
                rt[1] = (byte)((len >> 48) & 0xFF);
                rt[2] = (byte)((len >> 40) & 0xFF);
                rt[3] = (byte)((len >> 32) & 0xFF);
                rt[4] = (byte)((len >> 24) & 0xFF);
                rt[5] = (byte)((len >> 16) & 0xFF);
                rt[6] = (byte)((len >> 8) & 0xFF);
                rt[7] = (byte)(len & 0xFF);
                Buffer.BlockCopy(data, 0, rt, 8, (int)len);
                return(rt);
            }
            //else // if (len <= 0xFF_FF_FF_FF_FF_FF_FF_FF)
            //{
            //    var rt = new byte[9 + len];
            //    rt[0] = (byte)((byte)identifier | 0x8);
            //    rt[1] = (byte)((len >> 56) & 0xFF);
            //    rt[2] = (byte)((len >> 48) & 0xFF);
            //    rt[3] = (byte)((len >> 40) & 0xFF);
            //    rt[4] = (byte)((len >> 32) & 0xFF);
            //    rt[5] = (byte)((len >> 24) & 0xFF);
            //    rt[6] = (byte)((len >> 16) & 0xFF);
            //    rt[7] = (byte)((len >> 8) & 0xFF);
            //    rt[8] = (byte)(len & 0xFF);
            //    Buffer.BlockCopy(data, 0, rt, 9, (int)len);
            //    return rt;
            //}


            //    // add length
            //    int bytes = 1;
            //for (var i = 56; i > 0; i -= 8, bytes++)
            //    if (len <= (0xFF_FF_FF_FF_FF_FF_FF_FF >> i))
            //        break;

            //var rt = new byte[1 + bytes + data.Length];
            //rt[0] = (byte)((byte)identifier | (bytes << 3));

            //for (var i = 1; i <= bytes; i++)
            //    rt[i] = data.LongLength >> i * 8;

            //Buffer.BlockCopy(data, 0, rt, 1 + bytes, data.Length);
        }
    }