Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create gh actions #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/action-rs/grcov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
branch: true
ignore-not-existing: true
llvm: true
filter: covered
output-type: lcov
output-path: ./lcov.info
prefix-dir: /home/user/build/
ignore:
- "/*"
- "C:/*"
- "../*"
path-mapping:
- "/path1"
- "/path2"
65 changes: 65 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Rust

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy, rustfmt
override: true
- uses: actions/checkout@v2
- name: Check fmt
run: cargo fmt -- --check
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
- name: Build
run: cargo build
- name: Run tests
run: cargo test

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Cargo clean
uses: actions-rs/cargo@v1
with:
command: clean
- name: Cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --no-fail-fast # Customize args for your own needs
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
- name: Placeholder (run the example)
uses: actions-rs/cargo@v1
with:
command: run
args: --example producer -- # needs a file there
- id: coverage
uses: actions-rs/[email protected]
- name: Coveralls upload
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ${{ steps.coverage.outputs.report }}
9 changes: 4 additions & 5 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ impl<T: BufRead> Iterator for PcapIterator<T> {
.fill_buf()
.and_then(|b| {
(if first_block {
parse_header(b)
.and_then(|(u, h)| Ok(Some((b.len() - u.len(), Block::Header(h)))))
parse_header(b).map(|(u, h)| Some((b.len() - u.len(), Block::Header(h))))
} else {
parse_record(b, endianness, nano_sec)
.and_then(|(u, r)| Ok(Some((b.len() - u.len(), Block::Record(r)))))
.map(|(u, r)| Some((b.len() - u.len(), Block::Record(r))))
})
.or_else(|e| match e {
Err::Incomplete(_)
Expand All @@ -64,7 +63,7 @@ impl<T: BufRead> Iterator for PcapIterator<T> {
})
})
.unwrap_or(None)
.and_then(|(c, block)| {
.map(|(c, block)| {
self.first_block = false;
if c != 0 {
self.reader.consume(c);
Expand All @@ -73,7 +72,7 @@ impl<T: BufRead> Iterator for PcapIterator<T> {
self.endianness = h.endianness;
self.nano_sec = h.nano_sec;
}
Some(block)
block
})
}
}
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use nom::{

/// Enumerates all frame format supported by pcap.
#[allow(non_camel_case_types)]
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum LinkType {
NULL,
Expand Down Expand Up @@ -293,12 +294,12 @@ named_args!(parse_header_e(e: Endianness, nsec: bool)<Header>,
|val:&LinkType| { *val != LinkType::UNKNOWN }
) >>
(Header {
major: major,
minor: minor,
this_zone: this_zone,
sigfigs: sigfigs,
snaplen: snaplen,
network: network,
major,
minor,
this_zone,
sigfigs,
snaplen,
network,
nano_sec: nsec,
endianness: e
})
Expand Down Expand Up @@ -326,9 +327,9 @@ named_args!(pub parse_record(e: Endianness, nano_sec: bool)<Record>, do_parse!(
data: take!(incl_len) >>

(Record {
ts_sec: ts_sec,
ts_sec,
ts_nanosec: if nano_sec {ts_subsec} else {ts_subsec*1000},
orig_len: orig_len,
orig_len,
data: Vec::from(data)
})
));
Expand Down