public int encode()

in proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java [197:356]


    public int encode(ByteBuffer b)
    {
        int size = size();

        final int count = (int) count();

        if(b.remaining()>=size)
        {
            if(!isElementOfArray())
            {
                if(size>257 || count >255)
                {
                    b.put((byte)0xf0);
                    b.putInt(size-5);
                    b.putInt(count);
                }
                else
                {
                    b.put((byte)0xe0);
                    b.put((byte)(size-2));
                    b.put((byte)count);
                }
            }
            else
            {
                ArrayElement parent = (ArrayElement)parent();
                if(parent.constructorType()==SMALL)
                {
                    b.put((byte)(size-1));
                    b.put((byte)count);
                }
                else
                {
                    b.putInt(size-4);
                    b.putInt(count);
                }
            }
            Element element = _first;
            if(isDescribed())
            {
                b.put((byte)0);
                if(element == null)
                {
                    b.put((byte)0x40);
                }
                else
                {
                    element.encode(b);
                    element = element.next();
                }
            }
            switch(_arrayType)
            {
                case NULL:
                    b.put((byte)0x40);
                    break;
                case BOOL:
                    b.put((byte)0x56);
                    break;
                case UBYTE:
                    b.put((byte)0x50);
                    break;
                case BYTE:
                    b.put((byte)0x51);
                    break;
                case USHORT:
                    b.put((byte)0x60);
                    break;
                case SHORT:
                    b.put((byte)0x61);
                    break;
                case UINT:
                    switch (constructorType())
                    {
                        case TINY:
                            b.put((byte)0x43);
                            break;
                        case SMALL:
                            b.put((byte)0x52);
                            break;
                        case LARGE:
                            b.put((byte)0x70);
                            break;
                    }
                    break;
                case INT:
                    b.put(_constructorType == SMALL ? (byte)0x54 : (byte)0x71);
                    break;
                case CHAR:
                    b.put((byte)0x73);
                    break;
                case ULONG:
                    switch (constructorType())
                    {
                        case TINY:
                            b.put((byte)0x44);
                            break;
                        case SMALL:
                            b.put((byte)0x53);
                            break;
                        case LARGE:
                            b.put((byte)0x80);
                            break;
                    }
                    break;
                case LONG:
                    b.put(_constructorType == SMALL ? (byte)0x55 : (byte)0x81);
                    break;
                case TIMESTAMP:
                    b.put((byte)0x83);
                    break;
                case FLOAT:
                    b.put((byte)0x72);
                    break;
                case DOUBLE:
                    b.put((byte)0x82);
                    break;
                case DECIMAL32:
                    b.put((byte)0x74);
                    break;
                case DECIMAL64:
                    b.put((byte)0x84);
                    break;
                case DECIMAL128:
                    b.put((byte)0x94);
                    break;
                case UUID:
                    b.put((byte)0x98);
                    break;
                case BINARY:
                    b.put(_constructorType == SMALL ? (byte)0xa0 : (byte)0xb0);
                    break;
                case STRING:
                    b.put(_constructorType == SMALL ? (byte)0xa1 : (byte)0xb1);
                    break;
                case SYMBOL:
                    b.put(_constructorType == SMALL ? (byte)0xa3 : (byte)0xb3);
                    break;
                case ARRAY:
                    b.put(_constructorType == SMALL ? (byte)0xe0 : (byte)0xf0);
                    break;
                case LIST:
                    b.put(_constructorType == TINY ? (byte)0x45 :_constructorType == SMALL ? (byte)0xc0 : (byte)0xd0);
                    break;
                case MAP:
                    b.put(_constructorType == SMALL ? (byte)0xc1 : (byte)0xd1);
                    break;
            }
            while(element!=null)
            {
                element.encode(b);
                element = element.next();
            }
            return size;
        }
        else
        {
            return 0;
        }
    }