Github user trixpan commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1418#discussion_r103651066
  
    --- 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 --
    
    I suspect so. I tested with both smaller and larger values and they all 
work ok. Happy to convert into a property tho so it can be adjusted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to