<commit_before>package org.yamcs.xtceproc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamcs.parameter.ParameterValue;
import org.yamcs.utils.BitBuffer;
import org.yamcs.utils.DecodingException;
import org.yamcs.xtce.BaseDataType;
import org.yamcs.xtce.ContainerEntry;
import org.yamcs.xtce.DataEncoding;
import org.yamcs.xtce.Parameter;
import org.yamcs.xtce.ParameterEntry;
import org.yamcs.xtce.ParameterType;
import org.yamcs.xtce.SequenceEntry;

public class SequenceEntryProcessor {
    static Logger log=LoggerFactory.getLogger(SequenceEntryProcessor.class.getName());
    ContainerProcessingContext pcontext;

    SequenceEntryProcessor(ContainerProcessingContext pcontext) {
        this.pcontext = pcontext;
    }

    public void extract(SequenceEntry se) {
        try {
            if(se instanceof ContainerEntry) {
                extractContainerEntry((ContainerEntry)se);
            } else if (se instanceof ParameterEntry) {
                extractParameterEntry((ParameterEntry)se);
            } else {
                throw new UnsupportedOperationException("processing type "+se+" not implemented");
            }
        } catch (XtceProcException e) {
            log.warn("Exception when extracting\n {} :\n",se, e);
            throw e;
        }
    }


    private void extractContainerEntry(ContainerEntry ce) {
        BitBuffer buf = pcontext.buffer;
        if(buf.getPosition()%8!=0) 
            log.warn("Container Entry that doesn't start at byte boundary is not supported.{} is supposed to start at bit {}", ce, buf.getPosition());
        if(buf.getPosition()>buf.sizeInBits()) {
            log.warn("Container Entry that doesn't fit in the buffer: {} is supposed to start at bit {}"
                    + " while the packet buffer has capacity {} bits", ce,  buf.getPosition(), buf.sizeInBits());
            return;
        }
        BitBuffer buf1 = buf.slice();
        ContainerProcessingContext cpc1 = new ContainerProcessingContext(pcontext.pdata, buf1, pcontext.result, pcontext.subscription, pcontext.options);
        cpc1.sequenceContainerProcessor.extract(ce.getRefContainer());
        if(ce.getRefContainer().getSizeInBits()<0)
            buf.setPosition(buf.getPosition()+buf1.getPosition());
        else 
            buf.setPosition(buf.getPosition()+ce.getRefContainer().getSizeInBits());
    }

    private void extractParameterEntry(ParameterEntry pe) {
        BitBuffer buf = pcontext.buffer;

        Parameter param = pe.getParameter();
        ParameterType ptype = param.getParameterType();
        if(ptype == null) {
            throw new XtceProcException("Encountered parameter entry with a parameter '"+param.getName()+" without a type");
        }
        DataEncoding encoding = ((BaseDataType)ptype).getEncoding();
        if(encoding == null) {
            throw new XtceProcException("Encountered parameter entry with a parameter '"+param.getName()+" without an encoding");
        }
        ParameterValue pv = new ParameterValue(param);
        pv.setAbsoluteBitOffset(pcontext.containerAbsoluteByteOffset*8+buf.getPosition());
        pv.setBitSize(encoding.getSizeInBits());
        pcontext.dataEncodingProcessor.extractRaw(((BaseDataType)ptype).getEncoding(), pv);
        pcontext.pdata.parameterTypeProcessor.calibrate(pcontext, pv);
        
        pv.setAcquisitionTime(pcontext.result.acquisitionTime);
        pv.setGenerationTime(pcontext.result.generationTime);
        pv.setExpireMillis(pcontext.result.expireMillis);
        pv.setParameterEntry(pe);

        pcontext.result.params.add(pv);
    }
}<commit_msg>doc update<commit_after>package org.yamcs.xtceproc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamcs.parameter.ParameterValue;
import org.yamcs.utils.BitBuffer;
import org.yamcs.utils.DecodingException;
import org.yamcs.xtce.BaseDataType;
import org.yamcs.xtce.ContainerEntry;
import org.yamcs.xtce.DataEncoding;
import org.yamcs.xtce.Parameter;
import org.yamcs.xtce.ParameterEntry;
import org.yamcs.xtce.ParameterType;
import org.yamcs.xtce.SequenceEntry;

public class SequenceEntryProcessor {
    static Logger log=LoggerFactory.getLogger(SequenceEntryProcessor.class.getName());
    ContainerProcessingContext pcontext;

    SequenceEntryProcessor(ContainerProcessingContext pcontext) {
        this.pcontext = pcontext;
    }

    public void extract(SequenceEntry se) {
        try {
            if(se instanceof ContainerEntry) {
                extractContainerEntry((ContainerEntry)se);
            } else if (se instanceof ParameterEntry) {
                extractParameterEntry((ParameterEntry)se);
            } else {
                throw new UnsupportedOperationException("processing type "+se+" not implemented");
            }
        } catch (XtceProcException e) {
            log.warn("Exception when extracting\n {} :\n",se, e);
            throw e;
        }
    }


    private void extractContainerEntry(ContainerEntry ce) {
        BitBuffer buf = pcontext.buffer;
        if(buf.getPosition()%8!=0) 
            log.warn("Container Entry that doesn't start at byte boundary is not supported.{} is supposed to start at bit {}", ce, buf.getPosition());
        if(buf.getPosition()>buf.sizeInBits()) {
            log.warn("Container Entry that doesn't fit in the buffer: {} is supposed to start at bit {}"
                    + " while the packet buffer has capacity {} bits", ce,  buf.getPosition(), buf.sizeInBits());
            return;
        }
        BitBuffer buf1 = buf.slice();
        ContainerProcessingContext cpc1 = new ContainerProcessingContext(pcontext.pdata, buf1, pcontext.result, pcontext.subscription, pcontext.options);
        cpc1.sequenceContainerProcessor.extract(ce.getRefContainer());
        if(ce.getRefContainer().getSizeInBits()<0)
            buf.setPosition(buf.getPosition()+buf1.getPosition());
        else 
            buf.setPosition(buf.getPosition()+ce.getRefContainer().getSizeInBits());
    }

    private void extractParameterEntry(ParameterEntry pe) {
        BitBuffer buf = pcontext.buffer;

        Parameter param = pe.getParameter();
        ParameterType ptype = param.getParameterType();
        if(ptype == null) {
            throw new XtceProcException("Encountered entry for parameter '"+param.getName()+" without a type");
        }
        DataEncoding encoding = ((BaseDataType)ptype).getEncoding();
        if(encoding == null) {
            throw new XtceProcException("Encountered parameter entry with a parameter '"+param.getName()+" without an encoding");
        }
        ParameterValue pv = new ParameterValue(param);
        pv.setAbsoluteBitOffset(pcontext.containerAbsoluteByteOffset*8+buf.getPosition());
        pv.setBitSize(encoding.getSizeInBits());
        pcontext.dataEncodingProcessor.extractRaw(((BaseDataType)ptype).getEncoding(), pv);
        pcontext.pdata.parameterTypeProcessor.calibrate(pcontext, pv);
        
        pv.setAcquisitionTime(pcontext.result.acquisitionTime);
        pv.setGenerationTime(pcontext.result.generationTime);
        pv.setExpireMillis(pcontext.result.expireMillis);
        pv.setParameterEntry(pe);

        pcontext.result.params.add(pv);
    }
}
{'fraction_non_alphanumeric': 0.10654154016008832, 'fraction_numerical': 0.003036157880209771, 'mean_word_length': 3.141142857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4155515', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1968, 'n_words': 397}