示例#1
0
 private int length()
 {
     return(ValueLengthUtil.get(this.head()) - 1);
 }
示例#2
0
        public virtual int getByteSize()
        {
            long size;
            byte head        = head();
            int  valueLength = ValueLengthUtil.get(head
                                                   );

            if (valueLength != 0)
            {
                size = valueLength;
            }
            else
            {
                switch (this.type())
                {
                case ValueType.ARRAY:
                case ValueType.OBJECT:
                {
                    if (head == unchecked ((int)0x13) || head == unchecked ((int)0x14))
                    {
                        // compact Array or Object
                        size = NumberUtil.readVariableValueLength(
                            this.vpack, this.start + 1, false);
                    }
                    else
                    {
                        /* if (head <= 0x14) */
                        size = NumberUtil.toLong(this.vpack, this.start + 1,
                                                 ObjectArrayUtil.getOffsetSize(head));
                    }
                    break;
                }

                case ValueType.STRING:
                {
                    // long UTF-8 String
                    size = this.getLongStringLength() + 1 + 8;
                    break;
                }

                case ValueType.BINARY:
                {
                    size = 1 + head - unchecked ((byte)unchecked ((int)0xbf)) + this.getBinaryLengthUnchecked
                               ();
                    break;
                }

                case ValueType.BCD:
                {
                    if ((sbyte)head <= unchecked ((int)0xcf))
                    {
                        size = 1 + head + unchecked ((byte)unchecked ((int)0xc7)) + NumberUtil
                               .toLong(this.vpack, this.start + 1, head - unchecked ((byte)unchecked ((int)0xc7)));
                    }
                    else
                    {
                        size = 1 + head - unchecked ((byte)unchecked ((int)0xcf)) + NumberUtil
                               .toLong(this.vpack, this.start + 1, head - unchecked ((byte)unchecked ((int)0xcf)));
                    }
                    break;
                }

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

                default:
                {
                    // TODO
                    throw new java.lang.InternalError();
                }
                }
            }
            return((int)size);
        }