public SampleDispatcher decodeSampleRef()
        {
            int index = (int)ReadInt(4);

            try {
                DecoderRegistry.Entry e = ref_registry.get(index);
                return(e.getSampleDispatcher());
            } catch (NullReferenceException) {
                return(null);
            }
        }
        public void runOne()
        {
            bool done = false;

            while (!done)
            {
                int tag    = decodePacked32();
                int length = decodePacked32();
                switch (tag)
                {
                case Constant.VERSION: {
                    String version = decodeString();
                    if (version != Constant.CURRENT_VERSION)
                    {
                        throw new IOException("LabComm version mismatch " +
                                              version + " != " + Constant.CURRENT_VERSION);
                    }
                } break;

                case Constant.SAMPLE_DEF: {
                    int    index            = decodePacked32();
                    String name             = decodeIntentions();
                    int    signature_length = decodePacked32();
                    byte[] signature        = new byte[signature_length];
                    ReadBytes(signature, signature_length);
                    def_registry.add(index, name, signature);
                } break;

                case Constant.SAMPLE_REF: {
                    int    index            = decodePacked32();
                    String name             = decodeIntentions();
                    int    signature_length = decodePacked32();
                    byte[] signature        = new byte[signature_length];
                    ReadBytes(signature, signature_length);
                    ref_registry.add(index, name, signature);
                } break;

                case Constant.TYPE_DEF:
                case Constant.TYPE_BINDING: {
                    for (int i = 0; i < length; i++)
                    {
                        decodeByte();
                    }
                } break;

                default: {
                    DecoderRegistry.Entry e = def_registry.get(tag);
                    if (e == null)
                    {
                        throw new IOException("Unhandled tag " + tag);
                    }
                    SampleDispatcher d = e.getSampleDispatcher();
                    if (d == null)
                    {
                        throw new IOException("No dispatcher for '" + e.getName() + "'" + e.getSignature());
                    }
                    SampleHandler h = e.getHandler();
                    if (h == null)
                    {
                        throw new IOException("No handler for '" + e.getName() + "'");
                    }
                    d.decodeAndHandle(this, h);
                    done = true;
                } break;
                }
            }
        }