示例#1
0
        internal ICollection <Protocol> decode(OctetsStream os, Transport transport)
        {
            ICollection <Protocol> protocols = new List <Protocol>();
            Manager manager = transport.getManager();

            while (os.remain() > 0)
            {
                os.begin();
                try
                {
                    int  type = os.unmarshal_int();
                    int  size = os.unmarshal_size();
                    Stub stub;
                    if (stubs.TryGetValue(type, out stub))
                    {
                        stub.check(size);
                        if (size > os.remain())
                        {
                            os.rollback();
                            break; // not enough
                        }
                        int      startpos = os.position();
                        Protocol p        = stub.newInstance();
                        try { p.unmarshal(os); }
                        catch (MarshalException e)
                        {
                            throw new CodecException("State.decode (" + type + ", " + size + ")", e);
                        }
                        p.setTransport(transport);
                        protocols.Add(p);
                        if ((os.position() - startpos) != size)
                        {
                            throw new CodecException("State.decode(" + type + ", " + size + ")=" + (os.position() - startpos));
                        }
                    }
                    else
                    {
                        throw new CodecException("unknown protocol (" + type + ", " + size + ")");
                    }
                    os.commit();
                }
                catch (MarshalException)
                {
                    os.rollback();
                    break;
                }
            }
            return(protocols);
        }