示例#1
0
 internal int GetLength()
 {
     return(ValueLengthUtil.Get(this.Head) - 1);
 }
示例#2
0
        internal int GetByteSize()
        {
            long size;
            byte head        = TypeCode;
            int  valueLength = ValueLengthUtil.Get(head);

            if (valueLength != 0)
            {
                size = valueLength;
            }
            else
            {
                switch (Type)
                {
                case SliceType.Array:
                case SliceType.Object:
                    if (head == 0x13 || head == 0x14)
                    {
                        // compact Array or Object
                        size = NumberUtil.ReadVariableValueLength(vpack, start + 1, false);
                    }
                    else     /* if (head <= 0x14) */
                    {
                        size = NumberUtil.ToLong(vpack, start + 1, ObjectArrayUtil.GetOffsetSize(head));
                    }
                    break;

                case SliceType.String:
                    // long UTF-8 String
                    size = GetLongStringLength() + 1 + 8;
                    break;

                case SliceType.Binary:
                    size = 1 + head - ((byte)0xbf) + GetBinaryLengthUnchecked();
                    break;

                case SliceType.Bcd:
                    if (head <= 0xcf)
                    {
                        size = 1 + head + ((byte)0xc7) + NumberUtil.ToLong(vpack, start + 1, head - ((byte)0xc7));
                    }
                    else
                    {
                        size = 1 + head - ((byte)0xcf) + NumberUtil.ToLong(vpack, start + 1, head - ((byte)0xcf));
                    }
                    break;

                case SliceType.Custom:
                    if (head == 0xf4 || head == 0xf5 || head == 0xf6)
                    {
                        size = 2 + NumberUtil.ToLong(vpack, start + 1, 1);
                    }
                    else if (head == 0xf7 || head == 0xf8 || head == 0xf9)
                    {
                        size = 3 + NumberUtil.ToLong(vpack, start + 1, 2);
                    }
                    else if (head == 0xfa || head == 0xfb || head == 0xfc)
                    {
                        size = 5 + NumberUtil.ToLong(vpack, start + 1, 4);
                    }
                    else     /* if (head == 0xfd || head == 0xfe || head == 0xff) */
                    {
                        size = 9 + NumberUtil.ToLong(vpack, start + 1, 8);
                    }
                    break;

                default:
                    // TODO
                    throw new Exception("Internal error");
                }
            }
            return((int)size);
        }