Análisis de protocolo FAST (3) completa una plantilla y problemas de eficiencia de análisis

disparates

El capítulo anterior presentó dos tipos de códigos de análisis (el proceso es básicamente el mismo), esta vez publicaré los datos del ejemplo juntos y discutiré la eficiencia del análisis.

Hay otro punto que debe evitarse. El documento de datos y el documento de plantilla proporcionados allí causarán errores al analizar los campos. Por ejemplo, una plantilla FAST se define como un campo uInt64, como se explica en el documento de protocolo. , es un entero de 64 bits sin signo, es decir, un entero positivo que va de 0 a 2 a la potencia 64. Según tengo entendido, es un tipo Long en Java, pero de hecho llamo al método getLong() para obtener Cuando el valor está configurado, existe una alta probabilidad de que se informe un error, es decir, el tipo de protocolo es diferente del tipo definido por Java (o mi comprensión puede ser incorrecta).

Esa es la razón de este tipo, soy perezoso, todos usan el método getString(), es decir, todos los valores se toman en forma de cadenas. Es lógico pensar que debería ser más eficiente obtener el valor correcto.

jugar

(1) Plantilla (plantilla.xml)

<?xml version="1.0" encoding="utf-8"?>
<templates xmlns="http://www.FIXprotocal.org/ns/FAST/td/1.1" templateNs="http://www.sse.com.cn/ns/templates/NGTS" ns="http://www.sse.com.cn/ns/STEP1.0.0">
  <!--Snapshot-->
  <template id="4001" name="MDSnapshotFullRefresh_4001">
    <typeRef name="MDSnapshotFullRefresh" />
    <string id="1500" name="MDStreamID">
      <copy />
    </string>
    <string id="48" name="SecurityID">
      <tail />
    </string>
    <byteVector id="55" name="Symbol" presence="optional">
      <default />
    </byteVector>
    <uInt64 id="8503" name="NumTrades" presence="optional">
      <delta />
    </uInt64>
    <uInt64 id="1020" name="TradeVolume" presence="optional">
      <delta />
    </uInt64>
    <decimal id="8504" name="TotalValueTraded" presence="optional">
      <delta />
    </decimal>
    <decimal id="140" name="PrevClosePx" presence="optional">
      <delta />
    </decimal>
    <decimal id="734" name="PrevSetPx" presence="optional">
      <delta />
    </decimal>
    <uInt64 id="8506" name="TotalLongPosition" presence="optional">
      <delta />
    </uInt64>
    <sequence name="MDFullGrp">
      <length id="268" name="NoMDEntries">
        <copy />
      </length>
      <string id="269" name="MDEntryType">
      </string>
      <decimal id="270" name="MDEntryPx" presence="optional">
        <delta />
      </decimal>
      <uInt64 id="271" name="MDEntrySize" presence="optional">
        <delta />
      </uInt64>
      <string id="273" name="MDEntryTime" presence="optional">
      	<tail />
      </string>
      <uInt32 id="290" name="MDEntryPositionNo" presence="optional">
      </uInt32>
    </sequence>
    <string id="8538" name="TradingPhaseCode" presence="optional">
      <copy />
    </string>
  </template>
    
</templates>

(2) El objeto correspondiente a la plantilla (MDSnapshotFullRefreshEntity, MDFullGrpEntity)

@Setter
@Getter
public class MDSnapshotFullRefreshEntity {
   
    private String MDStreamID;
   
    private String SecurityID;
    
    private String Symbol;
   
    private String NumTrades;
    
    private String TradeVolume;
    
    private String TotalValueTraded;
    
    private String PrevClosePx;
    
    private String PrevSetPx;
    
    private String TotalLongPosition;

    private List<MDFullGrpEntity> MDFullGrp;

}
@Setter
@Getter
public class MDFullGrpEntity {
    
    private String NoMDEntries;

    private String MDEntryType;

    private String MDEntryPx;

    private String MDEntrySize;
    
    private String MDEntryTime;
    
    private String MDEntryPositionNo;
    
    private String TradingPhaseCode;
}

(3) Clase de herramienta de análisis (FastDecoderUtils)

Aquí hay dos métodos de llamada de código analizado Aunque parecen similares, todavía hay algunas diferencias en la eficiencia.

@Slf4j
public class FastDecoderUtils{

    private static Context contextDecoder2;
    private static FastDecoder fastDecoder;

    private static XMLMessageTemplateLoader templateLoader;
    /**
     * 确保是FAST协议包,这里不会做协议校验,解析失败会抛出异常
     *
     * @param buff
     * @return
     */
    public static List<MDSnapshotFullRefreshEntity> decoder1(byte[] buff) throws Exception {
        if (buff == null) {
            return null;
        }

        List<MDSnapshotFullRefreshEntity> list = new ArrayList<>();
        if (templateLoader == null) {
            //从文件中导入模板,自己注意一下路径即可
            ClassPathResource classPathResource = new ClassPathResource("template/template.xml");
            InputStream inputStream1 = classPathResource.getStream();
            templateLoader = new XMLMessageTemplateLoader();
            templateLoader.setLoadTemplateIdFromAuxId(true);
            //载入模板
            templateLoader.load(inputStream1);
        }

        //载入数据源
        MessageInputStream mis = new MessageInputStream(new ByteArrayInputStream(buff));
        //注册模板
        mis.setTemplateRegistry(templateLoader.getTemplateRegistry());

        Message msg111 = null;

        //循环解析,直到解析完
        while ((msg111 = mis.readMessage()) != null) {
            MDSnapshotFullRefreshEntity refreshEntity = new MDSnapshotFullRefreshEntity();

            refreshEntity.setMDStreamID(msg111.getString("MDStreamID"));
            refreshEntity.setSecurityID(msg111.getString("SecurityID"));
            refreshEntity.setSymbol(new String(msg111.getBytes("Symbol"), "GBK"));
            refreshEntity.setNumTrades(msg111.getString("NumTrades"));
            refreshEntity.setTradeVolume(msg111.getString("TradeVolume"));
            refreshEntity.setTotalValueTraded(msg111.getString("TotalValueTraded"));
            refreshEntity.setPrevClosePx(msg111.getString("PrevClosePx"));
            refreshEntity.setPrevSetPx(msg111.getString("PrevSetPx"));
            refreshEntity.setTotalLongPosition(msg111.getString("TotalLongPosition"));

            List<MDFullGrpEntity> mdFullGrp = new ArrayList<>();
            for (int i = 0; i < msg111.getSequence("MDFullGrp").getLength(); i++) {
                GroupValue groupValue = msg111.getSequence("MDFullGrp").get(i);

                MDFullGrpEntity grpEntity = new MDFullGrpEntity();
                grpEntity.setNoMDEntries(groupValue.getString("NoMDEntries"));
                grpEntity.setMDEntryType(groupValue.getString("MDEntryType"));
                grpEntity.setMDEntryPx(groupValue.getString("MDEntryPx"));
                grpEntity.setMDEntrySize(groupValue.getString("MDEntrySize"));
                grpEntity.setMDEntryTime(groupValue.getString("MDEntryTime"));
                grpEntity.setMDEntryPositionNo(groupValue.getString("MDEntryPositionNo"));
                grpEntity.setTradingPhaseCode(groupValue.getString("TradingPhaseCode"));

                mdFullGrp.add(grpEntity);
            }
            refreshEntity.setMDFullGrp(mdFullGrp);
            list.add(refreshEntity);
        }
        return list;
    }

    /**
     * 确保是FAST协议包,这里不会做协议校验,解析失败会抛出异常
     * 
     * @param buff
     * @return
     */
    public static List<MDSnapshotFullRefreshEntity> decoder2(byte[] buff) throws Exception {
        if (buff == null) {
            return null;
        }

        List<MDSnapshotFullRefreshEntity> list = new ArrayList<>();

        if (contextDecoder2 == null) {
            ClassPathResource classPathResource = new ClassPathResource("template/template.xml");
            InputStream inputStream = classPathResource.getStream();
            //一个模板文件可能包含多个模板,我这里只有1个,省事就直接搞了
            MessageTemplate template = new XMLMessageTemplateLoader().load(inputStream)[0];
            contextDecoder2 = new Context();
            contextDecoder2.registerTemplate(4001, template);

        }
        //解码器
        fastDecoder = new FastDecoder(contextDecoder2, new ByteArrayInputStream(buff));
        //解码
        Message msg111 = null;
        while ((msg111 = fastDecoder.readMessage()) != null) {

            MDSnapshotFullRefreshEntity refreshEntity = new MDSnapshotFullRefreshEntity();

            refreshEntity.setMDStreamID(msg111.getString("MDStreamID"));
            refreshEntity.setSecurityID(msg111.getString("SecurityID"));
            refreshEntity.setSymbol(new String(msg111.getBytes("Symbol"), "GBK"));
            refreshEntity.setNumTrades(msg111.getString("NumTrades"));
            refreshEntity.setTradeVolume(msg111.getString("TradeVolume"));
            refreshEntity.setTotalValueTraded(msg111.getString("TotalValueTraded"));
            refreshEntity.setPrevClosePx(msg111.getString("PrevClosePx"));
            refreshEntity.setPrevSetPx(msg111.getString("PrevSetPx"));
            refreshEntity.setTotalLongPosition(msg111.getString("TotalLongPosition"));

            List<MDFullGrpEntity> mdFullGrp = new ArrayList<>();
            for (int i = 0; i < msg111.getSequence("MDFullGrp").getLength(); i++) {
                GroupValue groupValue = msg111.getSequence("MDFullGrp").get(i);

                MDFullGrpEntity grpEntity = new MDFullGrpEntity();
                grpEntity.setNoMDEntries(groupValue.getString("NoMDEntries"));
                grpEntity.setMDEntryType(groupValue.getString("MDEntryType"));
                grpEntity.setMDEntryPx(groupValue.getString("MDEntryPx"));
                grpEntity.setMDEntrySize(groupValue.getString("MDEntrySize"));
                grpEntity.setMDEntryTime(groupValue.getString("MDEntryTime"));
                grpEntity.setMDEntryPositionNo(groupValue.getString("MDEntryPositionNo"));
                grpEntity.setTradingPhaseCode(groupValue.getString("TradingPhaseCode"));

                mdFullGrp.add(grpEntity);
            }
            refreshEntity.setMDFullGrp(mdFullGrp);
            list.add(refreshEntity);
        }
        return list;
    }
}

(4) Datos de muestra y código de llamada

        byte[] testByte = {-4, 31, -95, 77, 68, 48, 48, -79, 48, 48, 48, 49, 50, -78, -119, -59, -87, -46, -75, -42, -9, -52, -30, -128, 46, -75, -127, 9, 98, 58, -113, 127, 127, 127, 127, -4, 10, 11, 36, -53, -128, -128, -123, -64, -77, 127, 127, 127, 127, -4, 10, 41, 60, -49, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 104, 46, -36, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 34, 17, -80, -128, -128, -128, -72, -125, 117, 88, 124, -46, -128, -128, -104, -77, -119, 49, 56, 48, -74, -81, -52, -84, 32, -128, 1, 80, -126, -127, 37, 13, 102, -85, -127, 29, 6, 41, -60, -128, -128, -64, -77, -126, 120, 38, -42, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, 127, 127, 127, 127, -3, 39, 49, 114, -71, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 1, 78, 31, -86, -128, -128, -128, -72, -127, 126, 42, 48, -116, -128, -128, -104, -75, -119, 49, 56, 48, -50, -56, -74, -88, 32, -128, 2, 83, -115, -127, 45, 18, 16, -31, -127, 16, 73, 6, -118, -128, -128, -64, -77, -127, 18, 83, 32, -95, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 126, 63, 44, -56, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 1, 95, 26, -9, -128, -128, -128, -72, -127, 126, 32, 101, -119, -128, -128, -104, -74, -119, -49, -5, -73, -47, 53, 48, 32, 32, -128, 123, 80, -36, -127, 78, 126, 8, -112, -127, 1, 126, 71, -25, -128, -128, -64, -77, -127, 5, 41, 41, -108, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 124, 38, 52, -57, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 4, 66, 91, -18, -128, -128, -128, -72, -127, 123, 61, 36, -110, -128, -128, -104, -72, -119, 51, 56, 48, -69, -7, -79, -66, 32, -128, 2, 27, -72, -127, 114, 97, 18, -74, -127, 106, 116, 110, -24, -128, -128, -64, -77, -127, 106, 127, 31, -65, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 74, 38, -110, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 54, 86, -15, -128, -128, -128, -72, -127, 73, 41, -113, -128, -128, -104, -71, -119, 49, 56, 48, -78, -88, -74, -81, 32, -128, 2, 73, -57, -127, 63, 52, 32, -29, -127, 29, 75, 47, -75, -128, -128, -64, -77, -127, 31, 71, 28, -102, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 126, 29, 97, -54, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 1, 111, 87, -45, -128, -128, -128, -72, -127, 126, 16, 40, -83, -128, -128, -104, 51, -80, -119, 51, 56, 48, -78, -88, -74, -81, 32, -128, 123, 121, -20, -127, 127, 41, 10, 12, -97, -127, 114, 108, 0, -80, -128, -128, -64, -77, -127, 115, 28, 109, -42, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 127, 57, 3, -71, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 0, 73, 125, -65, -128, -128, -128, -72, -127, 127, 54, 2, -63, -128, -128, -104, -79, -119, -55, -49, -42, -92, -72, -33, -48, -62, -128, 127, 35, -52, -127, 2, 9, 51, -95, -127, 85, 8, 29, -117, -128, -128, -64, -77, -127, 85, 0, 53, -115, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 125, 119, -11, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 12, 126, -72, -128, -128, -128, -72, -127, 115, 1, -56, -128, -128, -104, -78, -119, -55, -49, -42, -92, 49, 48, 48, 32, -128, 5, -64, -127, 125, 65, 11, -92, -127, 28, 11, 54, -107, -128, -128, -64, -77, -127, 28, 92, 50, -93, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 127, 59, 5, -112, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 0, 68, 122, -16, -128, -128, -128, -72, -127, 127, 52, 28, -12, -128, -128, -104, -77, -119, -55, -49, -42, -92, 49, 53, 48, 32, -128, 112, -112, -127, 124, 75, 8, -92, -127, 116, 60, 125, -59, -128, -128, -64, -77, -127, 116, 90, 73, -10, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 107, 93, -78, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 23, 49, -27, -128, -128, -128, -72, -127, 101, 121, -9, -128, -128, -104, -76, -119, -55, -49, -42, -92, -46, -8, -48, -48, -128, 1, 45, -64, -127, 15, 100, 17, -75, -126, 101, 91, 8, -48, -128, -128, -64, -77, -127, 105, 16, 59, -32, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 116, 121, -99, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 12, 53, -125, -128, -128, -128, -72, -127, 113, 108, -116, -128, -128, -104, -75, -119, 49, 56, 48, -72, -33, -79, -76, 32, -128, 124, -84, -127, 60, 21, 127, -49, 127, 127, 127, 127, -1, 31, 76, 127, -17, -128, -128, -64, -77, -126, 127, 63, 3, -114, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, 127, 127, 127, 127, -1, 28, 106, 33, -75, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -126, 99, 21, 94, -53, -128, -128, -128, -72, 127, 127, 127, 127, -1, 28, 106, 33, -75, -128, -128, -104, -74, -119, 49, 56, 48, -75, -51, -79, -76, 32, -128, 2, 31, -73, -127, 68, 61, 61, -18, -127, 20, 86, 86, -99, -128, -128, -64, -77, -127, 22, 39, 114, -100, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 126, 94, 45, -108, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 1, 44, 72, -6, -128, -128, -128, -72, -127, 126, 73, 80, -87, -128, -128, -104, -73, -119, 51, 56, 48, -72, -33, -79, -76, 32, -128, 125, 23, -120, -127, 125, 83, 85, -12, -127, 103, 65, 113, -71, -128, -128, -64, -77, -127, 103, 67, 4, -83, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -126, 102, 21, 17, -23, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, 127, 127, 127, 127, -1, 25, 114, 43, -81, -128, -128, -128, -72, -126, 102, 13, 84, -47, -128, -128, -104, -72, -119, 51, 56, 48, -75, -51, -79, -76, 32, -128, 89, -42, -127, 114, 125, 63, -6, -127, 3, 116, 90, -126, -128, -128, -64, -77, 127, 127, 127, 127, -1, 29, 96, 30, -121, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 72, 39, -90, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 56, 5, -72, -128, -128, -128, -72, -127, 71, 122, -56, -128, -128, -104, -71, -119, -55, -49, -42, -92, -41, -86, -43, -82, -128, 2, 116, -88, -127, 31, 81, 47, -21, -127, 97, 88, 27, -56, -128, -128, -64, -77, -126, 96, 4, 2, -68, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, 127, 127, 127, 127, -1, 1, 76, 46, -32, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -126, 126, 51, 81, -96, -128, -128, -128, -72, 127, 127, 127, 127, -1, 1, 69, 90, -89, -128, -128, -4, 31, -95, 77, 68, 48, 48, -79, 48, 48, 48, 49, 52, -78, -119, 51, 56, 48, -50, -56, -74, -88, 32, -128, 1, 22, -30, -127, 10, 84, 124, -78, 127, 127, 127, 127, -3, 4, 40, 110, -51, -128, -128, -123, -64, -77, 127, 127, 127, 127, -4, 44, 12, 49, -111, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 127, 37, 31, -85, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 0, 91, 7, -33, -128, -128, -128, -72, -127, 127, 34, 57, -117, -128, -128, -104, -75, -119, -45, -59, -54, -58, -41, -54, -44, -76, -128, 71, -69, -126, 118, 17, 51, -51, 127, 127, 127, 127, -1, 20, 72, 13, -72, -128, -128, -64, -77, -127, 110, 18, 57, -93, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 127, 57, 79, -68, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 0, 73, 74, -76, -128, -128, -128, -72, -127, 127, 31, 102, -53, -128, -128, -104, -74, -119, -45, -59, -54, -58, -42, -58, -44, -20, -128, 1, 19, -16, 127, 127, 127, 127, -1, 41, 105, 4, -88, -126, 107, 110, 80, -128, -128, -128, -64, -77, -127, 23, 123, 0, -22, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 127, 28, 52, -29, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 0, 111, 114, -4, -128, -128, -128, -72, -127, 126, 126, 44, -92, -128, -128, -104, -73, -119, -45, -59, -54, -58, -49, -5, -73, -47, -128, 126, 72, -2, -127, 10, 5, 115, -16, 127, 127, 127, 127, -2, 3, 105, 7, 120, -6, -128, -128, -64, -77, -127, 4, 105, 70, -7, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 125, 11, 97, -55, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 3, 28, 65, -93, -128, -128, -128, -72, -127, 124, 98, 123, -35, -128, -128, -104, -72, -119, -49, -5, -73, -47, -63, -20, -49, -56, -128, 2, 127, -14, -127, 42, 48, 103, -20, -127, 13, 78, 124, -88, -128, -128, -64, -77, -127, 3, 105, 66, -47, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 125, 80, 84, -20, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 2, 69, 127, -116, -128, -128, -128, -72, -127, 125, 55, 84, -9, -128, -128, -104, -71, -119, 49, 56, 48, -70, -20, -64, -5, 32, -128, 126, 31, -67, -127, 127, 41, 115, 112, -96, -126, 124, 20, 21, 45, -16, -128, -128, -64, -77, -127, 92, 99, 123, -4, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 85, 74, -18, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 43, 14, -104, -128, -128, -128, -72, -126, 113, 75, 5, -92, -128, -128, -104, 53, -80, -119, 51, 56, 48, -70, -20, -64, -5, 32, -128, 126, 67, -59, -127, 120, 60, 99, -9, -127, 31, 76, 100, -56, -128, -128, -64, -77, 127, 127, 127, 127, -1, 46, 34, 47, -100, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 127, 51, 106, -21, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -126, 85, 72, 0, -44, -128, -128, -128, -72, 127, 127, 127, 127, -1, 42, 55, 127, -84, -128, -128, -104, -79, -119, -55, -49, -71, -6, -70, -20, -64, -5, -128, 0, 106, -57, -127, 2, 50, 21, -81, -127, 86, 84, 127, -46, -128, -128, -64, -77, -126, 81, 47, 73, -48, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, 127, 127, 127, 127, -1, 5, 35, 4, -92, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -126, 122, 93, 20, -75, -128, -128, -128, -72, 127, 127, 127, 127, -1, 5, 34, 16, -90, -128, -128, -104, -78, -119, -55, -49, -47, -21, -70, -20, -64, -5, -128, 30, -122, -127, 1, 7, 4, -14, 127, 127, 127, 127, -1, 0, 95, 50, 117, -44, -128, -128, -64, -77, -127, 4, 62, 83, -88, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 105, 72, -2, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 22, 86, -94, -128, -128, -128, -72, -127, 94, 61, -3, -128, -128, -104, -77, -119, -55, -49, -61, -15, -70, -20, -64, -5, -128, 126, 106, -47, -127, 124, 38, 15, -83, -126, 127, 41, 100, 1, -6, -128, -128, -64, -77, -126, 119, 56, 74, -74, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, 127, 127, 127, 127, -1, 13, 75, 88, -111, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 34, 71, -98, -128, -128, -128, -72, -127, 91, 41, -119, -128, -128, -104, -75, -119, -54, -48, -42, -75, -80, -39, -57, -65, -128, 5, 77, -30, -126, 11, 76, 34, -1, -127, 0, 74, 78, -59, -128, -128, -64, -77, -127, 1, 26, 43, -88, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 65, 97, -39, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 0, 64, 39, -93, -128, -128, -128, -72, -127, 127, 63, 88, -35, -128, -128, -104, -72, -119, -55, -49, -42, -92, -69, -73, -79, -93, -128, 123, 64, -84, 127, 127, 127, 127, -1, 22, 101, 91, -66, -127, 123, 77, 56, -76, -128, -128, -64, -77, -126, 113, 41, 3, -96, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, 127, 127, 127, 127, -1, 10, 22, 42, -9, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 25, 74, -121, -128, -128, -128, -72, -127, 100, 122, -80, -128, -128, -104, -71, -119, -69, -90, -71, -55, -51, -88, 32, 32, -128, 8, 101, -97, -127, 1, 9, 72, 93, -77, -127, 6, 29, 56, -51, -128, -128, -64, -77, -127, 6, 102, 45, -42, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 65, 90, -23, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 63, 67, -111, -128, -128, -128, -72, -127, 64, 60, -17, -128, -128, -104, 54, -80, -119, -69, -90, -48, -62, -53, -65, -62, -73, -128, 120, 32, -2, -127, 126, 96, 109, 30, -71, -127, 120, 14, 92, -28, -128, -128, -64, -77, -127, 120, 31, 16, -83, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 96, 112, -82, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 33, 101, -11, -128, -128, -128, -72, -127, 92, 77, -45, -128, -128, -104, -79, -119, -69, -90, -42, -48, -71, -6, -44, -20, -128, 96, -127, -127, 32, 87, 108, -69, -126, 119, 73, 111, -77, -128, -128, -64, -77, -127, 2, 16, 42, -5, -128, 49, 48, 51, 49, 48, 51, 48, -80, -128, -64, -76, -127, 101, 32, -61, -128, -128, -128, -128, -75, -128, -128, -128, -128, -73, -127, 26, 95, -67, -128, -128, -128, -72, -127, 99, 66, -7, -128, -128};
        try {
            long time = System.currentTimeMillis();
            for (int i = 0; i < 5000; i++) {
                FastDecoderUtils.decoder2(testByte);
            }
            log.error("方法1用时:{}", System.currentTimeMillis() - time);

            Thread.sleep(2000);

            time = System.currentTimeMillis();
            for (int i = 0; i < 5000; i++) {
                FastDecoderUtils.decoder1(testByte);
            }
            log.error("方法2用时:{}", System.currentTimeMillis() - time);
        } catch (Exception e) {
            e.printStackTrace();
        }

Fuera de tema: el testByte anterior son datos reales. Si no puede analizarlo correctamente con esta plantilla, debe encontrar sus propios motivos.

Resumir

La comparación de código de los dos métodos de análisis, personalmente, creo que el segundo es más amigable para mi comprensión personal. Primero encuentre una plantilla, luego cree un nuevo contexto y luego encuentre un decodificador para decodificar. El proceso es muy sencillo. Sin embargo, a la verdad siempre le gusta dar una bofetada en la cara.

Este paquete de datos contiene alrededor de 34 piezas de datos. De acuerdo con la comparación del número de análisis de bucle, la eficiencia del método 1 es mucho mayor que la del método 2, y la brecha se vuelve más grande a medida que avanza. Puede ser la razón por qué el decodificador tiene que ser reconstruido todo el tiempo Aquí hay algunas comparaciones de resultados de ejecución:

100 veces: método 1 (146 milisegundos), método 2 (164 milisegundos)

500 veces: método 1 (635 ms), método 2 (736 ms)

1000 veces: método 1 (386 ms), método 2 (2230 ms)

5000 veces: método 1 (2939 ms), método 2 (34628 ms)

En resumen, se recomienda utilizar el método 1.

Supongo que te gusta

Origin blog.csdn.net/qq_33601179/article/details/122407384
Recomendado
Clasificación