Skip to content

Instantly share code, notes, and snippets.

@ivelin
Created June 19, 2019 17:19
Show Gist options
  • Save ivelin/2ec21d2b5298bf88ae3b36947d338cff to your computer and use it in GitHub Desktop.
Save ivelin/2ec21d2b5298bf88ae3b36947d338cff to your computer and use it in GitHub Desktop.
"""PcapDataset"""
import tensorflow as tf
from tensorflow_io.core.python.ops import data_ops as data_ops
from tensorflow_io import _load_library
pcap_ops = _load_library('_pcap_ops.so')
class PcapDataset(data_ops.Dataset):
"""A pcap Dataset. Pcap is a popular file format for capturing network packets.
"""
def __init__(self, filenames, batch=None):
"""Create a pcap Reader.
Args:
filenames: A `tf.string` tensor containing one or more filenames.
"""
batch = 0 if batch is None else batch
dtypes = [tf.float64, tf.string]
shapes = [
tf.TensorShape([]), tf.TensorShape([])] if batch == 0 else [
tf.TensorShape([None]), tf.TensorShape([None])]
super(PcapDataset, self).__init__(
pcap_ops.pcap_dataset,
pcap_ops.pcap_input(filenames),
batch, dtypes, shapes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment