[ https://issues.apache.org/jira/browse/NIFI-3238?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15889352#comment-15889352 ]
ASF GitHub Bot commented on NIFI-3238: -------------------------------------- Github user mattyb149 commented on a diff in the pull request: https://github.com/apache/nifi/pull/1418#discussion_r103595838 --- Diff: nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/src/main/java/org/apache/nifi/processors/beats/frame/BeatsDecoder.java --- @@ -0,0 +1,330 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.processors.beats.frame; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.util.LinkedList; +import java.util.List; +import java.util.zip.InflaterInputStream; + +import org.apache.nifi.stream.io.ByteArrayInputStream; +import org.apache.nifi.stream.io.ByteArrayOutputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Decodes a Beats frame by maintaining a state based on each byte that has been processed. This class + * should not be shared by multiple threads. + */ +public class BeatsDecoder { + + + static final Logger logger = LoggerFactory.getLogger(BeatsDecoder.class); + + private BeatsFrame.Builder frameBuilder; + private BeatsState currState = BeatsState.VERSION; + private byte decodedFrameType; + + private byte[] unprocessedData; + + private final Charset charset; + private final ByteArrayOutputStream currBytes; + + private long windowSize; + + static final int MIN_FRAME_HEADER_LENGTH = 2; // Version + Type + static final int WINDOWSIZE_LENGTH = MIN_FRAME_HEADER_LENGTH + 4; // 32bit unsigned window size + static final int COMPRESSED_MIN_LENGTH = MIN_FRAME_HEADER_LENGTH + 4; // 32 bit unsigned + payload + static final int JSON_MIN_LENGTH = MIN_FRAME_HEADER_LENGTH + 8; // 32 bit unsigned sequence number + 32 bit unsigned payload length + + public static final byte FRAME_WINDOWSIZE = 0x57, FRAME_DATA = 0x44, FRAME_COMPRESSED = 0x43, FRAME_ACK = 0x41, FRAME_JSON = 0x4a; + + /** + * @param charset the charset to decode bytes from the frame + */ + public BeatsDecoder(final Charset charset) { + this(charset, new ByteArrayOutputStream(4096)); --- End diff -- Is 4K ok as a default size? Should it be passed in here and perhaps default somewhere else in case it needs to be configurable? > ListenLumberjack should support the *beat protocol > -------------------------------------------------- > > Key: NIFI-3238 > URL: https://issues.apache.org/jira/browse/NIFI-3238 > Project: Apache NiFi > Issue Type: Improvement > Reporter: Andre F de Miranda > Assignee: Andre F de Miranda > > ListenLumberjack currently only supports v1 of the Lumberjack protocol. This > version has been deprecated in favor of v2, which is used on *beat (e.g. > filebeat, packetbeat, etc) edge components of the ELK stack. > We should consider deprecating ListenLumberjack or to extend it to handle > both v1 and v2 of the protocol. -- This message was sent by Atlassian JIRA (v6.3.15#6346)