org.graylog.plugins.beats.BeatsFrameDecoder Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package org.graylog.plugins.beats;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.io.ByteStreams;
import com.google.common.primitives.Ints;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.zip.InflaterInputStream;
/**
* FrameDecoder for the Beats/Lumberjack protocol.
*
* @see Lumberjack protocol
*/
public class BeatsFrameDecoder extends ReplayingDecoder {
private static final Logger LOG = LoggerFactory.getLogger(BeatsFrameDecoder.class);
private static final byte PROTOCOL_VERSION = '2';
private static final byte FRAME_ACK = 'A';
private static final byte FRAME_COMPRESSED = 'C';
private static final byte FRAME_DATA = 'D';
private static final byte FRAME_JSON = 'J';
private static final byte FRAME_WINDOW_SIZE = 'W';
enum DecodingState {
PROTOCOL_VERSION,
FRAME_TYPE,
FRAME_COMPRESSED,
FRAME_DATA,
FRAME_JSON,
FRAME_WINDOW_SIZE
}
private long windowSize;
private long sequenceNum;
public BeatsFrameDecoder() {
super(DecodingState.PROTOCOL_VERSION);
}
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf buffer, List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy