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

merge main into protocol changes #921

Merged
merged 148 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
efe1135
Update Reply protocol definition and codec (#717)
Mallets Feb 9, 2024
d6ffebf
Clean-up of protocol types (#729)
Mallets Feb 15, 2024
cc8d4a1
Allow DeclareInterest for any keyexpr (#739)
Mallets Feb 26, 2024
24e5ef5
ConsolidationMode can be Auto (#738)
Mallets Feb 28, 2024
e41f768
Fix bug building reply
OlivierHecart Feb 28, 2024
77ab676
Merge with main
Mallets Mar 8, 2024
a8cdbbe
Revised Encoding API and wire format (#764)
Mallets Mar 12, 2024
b11a20e
Fix protocol comment
Mallets Mar 12, 2024
fcbceb0
Improve Endpoint and Locator doc
Mallets Mar 12, 2024
41e2557
Protocol changes: EntityId (into protocol_changes) (#774)
OlivierHecart Mar 12, 2024
f12f338
refactor Query.reply() (#796)
DenisBiryukov91 Mar 12, 2024
e06b46d
Simplify Error message (#813)
Mallets Mar 13, 2024
55119a5
make Sample ields pub(crate) provide accessors for external users
DenisBiryukov91 Mar 13, 2024
cc68ffb
remove Publisher::write (#819)
milyin Mar 13, 2024
f3af52a
format and clippy
DenisBiryukov91 Mar 13, 2024
0ca41e8
mark remaining sample-mutating methods as unstable and hidden
DenisBiryukov91 Mar 13, 2024
ea7179f
Add express support in the pipeline
Mallets Mar 14, 2024
62bf7d3
Add express support to publisher and put
Mallets Mar 14, 2024
d808ba2
Merge main
Mallets Mar 14, 2024
8489338
merge
DenisBiryukov91 Mar 14, 2024
4d8ec6c
fix(828): ensuring valid JSON response from REST API (#831)
gabrik Mar 14, 2024
622b230
Add express support (#829)
Mallets Mar 15, 2024
fef5d9a
merge
DenisBiryukov91 Mar 15, 2024
d73da7d
clippy
DenisBiryukov91 Mar 15, 2024
2e9db3f
Merge pull request #822 from DenisBiryukov91/release/protocol_changes…
milyin Mar 15, 2024
1d1d4ed
Rename IntoCallbackReceiver trait to IntoHandler trait (#816)
Mallets Mar 18, 2024
665c90f
Optimize zint encode/decode (#838)
Mallets Mar 18, 2024
7300f4c
Remove pull API and protocol support (#821)
Mallets Mar 19, 2024
5b18594
replaced sample new to put/delete
milyin Mar 19, 2024
1038beb
interceptors removed
milyin Mar 19, 2024
09a84b3
interceptors removed
milyin Mar 19, 2024
886c37c
storage sample added
milyin Mar 19, 2024
780c82a
some compile error fixes
milyin Mar 19, 2024
af0d167
removed interceptor proxy
milyin Mar 19, 2024
067823d
sample builders
milyin Mar 20, 2024
4f1ba2f
compiles
milyin Mar 20, 2024
9a71712
Merge branch 'protocol_changes' into sample_api_rework
milyin Mar 22, 2024
d7cb97a
SampleBuilderTrait
milyin Mar 22, 2024
a05b93d
reply builder unfinished
milyin Mar 23, 2024
0992ff8
replybuilder unfinished
milyin Mar 23, 2024
62378ad
new reply_sample
milyin Mar 24, 2024
cc580a5
sample decompose, opt setters
milyin Mar 24, 2024
2708402
samples, plugins updated
milyin Mar 24, 2024
b80fd0a
interceptors removed from plugin storage API
milyin Mar 24, 2024
265d1cf
Merge branch 'remove_storage_interceptors' into sample_api_rework
milyin Mar 24, 2024
7d2abd4
deconstruct sample api used
milyin Mar 24, 2024
2b1071f
comment, clippy fix
milyin Mar 24, 2024
3386237
clippy fix
milyin Mar 24, 2024
f52140a
zenoh-ext links zenoh with unstable
milyin Mar 24, 2024
a629c76
samplefields used
milyin Mar 24, 2024
1945492
restored old storage manager code
milyin Mar 25, 2024
65a4d7f
interceptors removed from plugin storage API (#859)
milyin Mar 25, 2024
48d8d77
separate qosbuilder trait
milyin Mar 25, 2024
322a4e0
removed `with_keyexpr` from trait
milyin Mar 25, 2024
9515c7d
put, delete builder
milyin Mar 25, 2024
4e14cf9
build fixes
milyin Mar 26, 2024
c7cc575
Support RingBuffer to get the latest sample. (#851)
evshary Mar 26, 2024
fa4b98d
Remove unmantained complete_n feature (#862)
Mallets Mar 26, 2024
5b9e3bd
Merge branch 'protocol_changes' into sample_api_rework
milyin Mar 26, 2024
8cd60d0
Publication updated
milyin Mar 26, 2024
00e0a59
build fix
milyin Mar 26, 2024
e601271
reply_sample restored
milyin Mar 27, 2024
ea4020d
build fixes
milyin Mar 27, 2024
5f0b531
clippy warning fix
milyin Mar 27, 2024
5a9bf0a
Payload API (#866)
Mallets Mar 27, 2024
2be4fa9
clippy warning fix (#867)
milyin Mar 27, 2024
8c90028
Merge branch 'clippy_truncate_warning_fix' into sample_api_rework
milyin Mar 27, 2024
fdec8dc
Merge branch 'protocol_changes' into sample_api_rework
milyin Mar 27, 2024
4485354
removed extra truncate appeared from different PRs
milyin Mar 27, 2024
b6a243d
Merge branch 'protocol_changes' into sample_api_rework
milyin Mar 27, 2024
ce5b610
sample api for GetBuilder
milyin Mar 28, 2024
0bce160
restored "express" name
milyin Mar 28, 2024
3620c3a
removed 'timestamp_opt'
milyin Mar 28, 2024
aafd2a4
with removed, into<opttion<>> added
milyin Mar 28, 2024
fb6509d
into to encoding returned
milyin Mar 28, 2024
2ff6bc2
example build fix
milyin Mar 28, 2024
5bbef9c
with removed
milyin Mar 28, 2024
9809799
Add protocol version to error message (#871)
sashacmc Mar 28, 2024
c427ac7
resolvable removed from simple builders
milyin Mar 28, 2024
d4c77c0
Merge main
Mallets Mar 28, 2024
6c6050b
Fix cargo clippy
Mallets Mar 28, 2024
1a2ba1a
Fix code format
Mallets Mar 28, 2024
7162ff1
Fix cargo clippy
Mallets Mar 28, 2024
10baf8c
doctests fixed
milyin Mar 28, 2024
e74caa4
Merge branch 'protocol_changes' into sample_api_rework
milyin Mar 28, 2024
48cb96b
sample bulider in separarte module
milyin Mar 28, 2024
ddb93a2
separate module
milyin Mar 28, 2024
ab96aab
SampleBuilder put/delete
milyin Mar 28, 2024
82c1c99
set value api
milyin Mar 28, 2024
b5a1f6b
with removed
milyin Mar 28, 2024
1c95157
commented code removed
milyin Mar 28, 2024
90a149e
Merge pull request #872 from eclipse-zenoh/protocol_tokio
milyin Mar 28, 2024
d9eb96a
map-from removed
milyin Mar 28, 2024
0ee0908
Merge branch 'protocol_changes' into sample_api_rework
milyin Mar 28, 2024
e4501f4
build warnings fixed
milyin Mar 28, 2024
1562a17
Protocol interest (#870)
Mallets Mar 28, 2024
21fb083
Protocol batchsize (#873)
Mallets Mar 29, 2024
312c03a
Query.reply and reply_del, now accept TryIntoKeyExpr instead of IntoK…
DenisBiryukov91 Mar 29, 2024
43a4937
SampleBuilder uses generics
Mallets Mar 29, 2024
6c305a1
Improve Query builders with generics
Mallets Mar 29, 2024
bca953d
Reorg sample files
Mallets Mar 29, 2024
9d1a540
Remove error op struct in SampleBuilder
Mallets Mar 29, 2024
7904d09
Add forgotten file
Mallets Mar 29, 2024
1eede12
Merge branch 'protocol_changes' into sample_api_rework
milyin Mar 31, 2024
8d282a8
Merge pull request #882 from eclipse-zenoh/sample_api_rework_builder
milyin Mar 31, 2024
2992d45
Merge branch 'sample_api_rework' of github.com:eclipse-zenoh/zenoh in…
milyin Mar 31, 2024
ab349b2
support of TryIntoKeyexpr
milyin Apr 1, 2024
e4c4be1
removed "op" namespace to align naming with ReplyBuilder
milyin Apr 1, 2024
d631f76
publication builder shortened
milyin Apr 1, 2024
9b8aaa6
parametrized publication builder
milyin Apr 1, 2024
bbe07f7
removed PutPublication, DeletePublication
milyin Apr 1, 2024
4d0f6e5
removed extra uses
milyin Apr 1, 2024
23931f9
more cleanup
milyin Apr 1, 2024
e816f4e
Add unicast open/close time tests (#898)
Mallets Apr 4, 2024
2da0aeb
Declare message can be Push/Request/RequestContinuous/Response (#902)
Mallets Apr 5, 2024
8f8eb25
typedefs for complex builder types (#890)
milyin Apr 5, 2024
71a9423
Declare message can be Push/Request/RequestContinuous/Response 2 (#906)
OlivierHecart Apr 5, 2024
eb1a80a
Fix use and unstable visibility
Mallets Apr 5, 2024
a43e451
Add payload and encoding accessors for Query
Mallets Apr 5, 2024
1ad8c84
cargo fmt --all
Mallets Apr 5, 2024
232177f
Merge pull request #907 from eclipse-zenoh/sample_api_rework_unstable
milyin Apr 5, 2024
5ee2bdb
Declare message can be Push/Request/RequestContinuous/Response 3 (#908)
OlivierHecart Apr 5, 2024
b330289
Merge pull request #858 from eclipse-zenoh/sample_api_rework
milyin Apr 6, 2024
5aedd2c
Payload tuple generic impl
Mallets Apr 8, 2024
3dea601
Payload iter impl
Mallets Apr 8, 2024
a25676b
Improve payload serde
Mallets Apr 8, 2024
d024607
[u8;N] payload support. from_reader functionality.
Mallets Apr 9, 2024
2a6bade
Improve payload test
Mallets Apr 9, 2024
6793a6b
Payload zserde improvement
Mallets Apr 9, 2024
7240f01
Fix encoding doc: suffix to schema
Mallets Apr 9, 2024
989509c
impl Seek for ZBufReader
Mallets Apr 9, 2024
140526b
impl Seek for PayloadReader
Mallets Apr 9, 2024
2dceb52
Fix tests
Mallets Apr 9, 2024
c2c6217
Add SHM support for deserializer
Mallets Apr 9, 2024
e4ee306
Fix SharedMemoryBuf deserialize
Mallets Apr 9, 2024
cf861e1
Fix clippy examples
Mallets Apr 9, 2024
28e23ab
Add writer method to payload
Mallets Apr 9, 2024
042964e
Add ZSlice payload support
Mallets Apr 10, 2024
abded10
Improve payload
Mallets Apr 10, 2024
fb7754a
Merge protocol_changes
Mallets Apr 10, 2024
adf422d
allowed build zenoh without unstable feature set (#910)
milyin Apr 10, 2024
6dea614
Merge protocol_changes
Mallets Apr 10, 2024
7d9d57c
Fix tests
Mallets Apr 10, 2024
27063b6
Integrating #918
Mallets Apr 10, 2024
a1c2a02
Fix ZBur io::Read impl
Mallets Apr 10, 2024
3c8c97f
Merge pull request #919 from eclipse-zenoh/protocol_attachment
milyin Apr 10, 2024
d0d97c9
Merge branch 'main' into protocol_changes_update2
milyin Apr 10, 2024
834be85
compilation fixes
milyin Apr 10, 2024
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
199 changes: 146 additions & 53 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ libloading = "0.8"
log = "0.4.17"
lz4_flex = "0.11"
nix = { version = "0.27", features = ["fs"] }
num_cpus = "1.15.0"
num_cpus = "1.16.0"
ordered-float = "4.1.1"
panic-message = "0.3.0"
paste = "1.0.12"
petgraph = "0.6.3"
phf = { version = "0.11.2", features = ["macros"] }
pnet = "0.34"
pnet_datalink = "0.34"
proc-macro2 = "1.0.51"
Expand All @@ -139,7 +140,9 @@ secrecy = { version = "0.8.0", features = ["serde", "alloc"] }
serde = { version = "1.0.154", default-features = false, features = [
"derive",
] } # Default features are disabled due to usage in no_std crates
serde_json = "1.0.94"
serde_cbor = "0.11.2"
serde_json = "1.0.114"
serde-pickle = "1.1.1"
serde_yaml = "0.9.19"
sha3 = "0.10.6"
shared_memory = "0.12.4"
Expand All @@ -157,6 +160,7 @@ tokio-rustls = "0.25.0"
console-subscriber = "0.2"
typenum = "1.16.0"
uhlc = { version = "0.7.0", default-features = false } # Default features are disabled due to usage in no_std crates
unwrap-infallible = "0.1.5"
unzip-n = "0.1.2"
url = "2.3.1"
urlencoding = "2.1.2"
Expand Down
15 changes: 14 additions & 1 deletion commons/zenoh-buffers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ pub mod buffer {
let mut slices = self.slices();
match slices.len() {
0 => Cow::Borrowed(b""),
1 => Cow::Borrowed(slices.next().unwrap()),
// SAFETY: it's safe to use unwrap_unchecked() beacuse we are explicitly checking the length is 1.
1 => Cow::Borrowed(unsafe { slices.next().unwrap_unchecked() }),
_ => Cow::Owned(slices.fold(Vec::new(), |mut acc, it| {
acc.extend(it);
acc
Expand Down Expand Up @@ -198,6 +199,18 @@ pub mod reader {
fn rewind(&mut self, mark: Self::Mark) -> bool;
}

pub trait AdvanceableReader: Reader {
fn skip(&mut self, offset: usize) -> Result<(), DidntRead>;
fn backtrack(&mut self, offset: usize) -> Result<(), DidntRead>;
fn advance(&mut self, offset: isize) -> Result<(), DidntRead> {
if offset > 0 {
self.skip(offset as usize)
} else {
self.backtrack((-offset) as usize)
}
}
}

#[derive(Debug, Clone, Copy)]
pub struct DidntSiphon;

Expand Down
190 changes: 171 additions & 19 deletions commons/zenoh-buffers/src/zbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
use crate::ZSliceKind;
use crate::{
buffer::{Buffer, SplitBuffer},
reader::{BacktrackableReader, DidntRead, DidntSiphon, HasReader, Reader, SiphonableReader},
reader::{
AdvanceableReader, BacktrackableReader, DidntRead, DidntSiphon, HasReader, Reader,
SiphonableReader,
},
writer::{BacktrackableWriter, DidntWrite, HasWriter, Writer},
ZSlice,
ZSlice, ZSliceBuffer,
};
use alloc::{sync::Arc, vec::Vec};
use core::{cmp, iter, mem, num::NonZeroUsize, ops::RangeBounds, ptr};
#[cfg(feature = "std")]
use std::io;
use zenoh_collections::SingleOrVec;

fn get_mut_unchecked<T>(arc: &mut Arc<T>) -> &mut T {
Expand All @@ -34,8 +39,10 @@ pub struct ZBuf {

impl ZBuf {
#[must_use]
pub fn empty() -> Self {
Self::default()
pub const fn empty() -> Self {
Self {
slices: SingleOrVec::empty(),
}
}

pub fn clear(&mut self) {
Expand All @@ -56,6 +63,21 @@ impl ZBuf {
}
}

pub fn to_zslice(&self) -> ZSlice {
let mut slices = self.zslices();
match self.slices.len() {
0 => ZSlice::empty(),
// SAFETY: it's safe to use unwrap_unchecked() beacuse we are explicitly checking the length is 1.
1 => unsafe { slices.next().unwrap_unchecked().clone() },
_ => slices
.fold(Vec::new(), |mut acc, it| {
acc.extend(it.as_slice());
acc
})
.into(),
}
}

pub fn splice<Range: RangeBounds<usize>>(&mut self, erased: Range, replacement: &[u8]) {
let start = match erased.start_bound() {
core::ops::Bound::Included(n) => *n,
Expand All @@ -72,6 +94,7 @@ impl ZBuf {
}
self.insert(start, replacement);
}

fn remove(&mut self, mut start: usize, mut end: usize) {
assert!(start <= end);
assert!(end <= self.len());
Expand Down Expand Up @@ -100,6 +123,7 @@ impl ZBuf {
let drain_end = end_slice_idx + (end_slice.start >= end_slice.end) as usize;
self.slices.drain(drain_start..drain_end);
}

fn insert(&mut self, mut at: usize, slice: &[u8]) {
if slice.is_empty() {
return;
Expand Down Expand Up @@ -195,17 +219,34 @@ impl PartialEq for ZBuf {
}

// From impls
impl From<ZSlice> for ZBuf {
fn from(t: ZSlice) -> Self {
let mut zbuf = ZBuf::empty();
zbuf.push_zslice(t);
zbuf
}
}

impl<T> From<Arc<T>> for ZBuf
where
T: ZSliceBuffer + 'static,
{
fn from(t: Arc<T>) -> Self {
let zslice: ZSlice = t.into();
Self::from(zslice)
}
}

impl<T> From<T> for ZBuf
where
T: Into<ZSlice>,
T: ZSliceBuffer + 'static,
{
fn from(t: T) -> Self {
let mut zbuf = ZBuf::empty();
let zslice: ZSlice = t.into();
zbuf.push_zslice(zslice);
zbuf
Self::from(zslice)
}
}

// Reader
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct ZBufPos {
Expand Down Expand Up @@ -265,7 +306,7 @@ impl<'a> Reader for ZBufReader<'a> {
}

fn read_exact(&mut self, into: &mut [u8]) -> Result<(), DidntRead> {
let len = self.read(into)?;
let len = Reader::read(self, into)?;
if len.get() == into.len() {
Ok(())
} else {
Expand Down Expand Up @@ -312,7 +353,7 @@ impl<'a> Reader for ZBufReader<'a> {
match (slice.len() - self.cursor.byte).cmp(&len) {
cmp::Ordering::Less => {
let mut buffer = crate::vec::uninit(len);
self.read_exact(&mut buffer)?;
Reader::read_exact(self, &mut buffer)?;
Ok(buffer.into())
}
cmp::Ordering::Equal => {
Expand Down Expand Up @@ -383,13 +424,81 @@ impl<'a> SiphonableReader for ZBufReader<'a> {
}

#[cfg(feature = "std")]
impl<'a> std::io::Read for ZBufReader<'a> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
impl<'a> io::Read for ZBufReader<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match <Self as Reader>::read(self, buf) {
Ok(n) => Ok(n.get()),
Err(_) => Ok(0),
}
}
}

impl<'a> AdvanceableReader for ZBufReader<'a> {
fn skip(&mut self, offset: usize) -> Result<(), DidntRead> {
let mut remaining_offset = offset;
while remaining_offset > 0 {
let s = self.inner.slices.get(self.cursor.slice).ok_or(DidntRead)?;
let remains_in_current_slice = s.len() - self.cursor.byte;
let advance = remaining_offset.min(remains_in_current_slice);
remaining_offset -= advance;
self.cursor.byte += advance;
if self.cursor.byte == s.len() {
self.cursor.slice += 1;
self.cursor.byte = 0;
}
}
Ok(())
}

fn backtrack(&mut self, offset: usize) -> Result<(), DidntRead> {
let mut remaining_offset = offset;
while remaining_offset > 0 {
let backtrack = remaining_offset.min(self.cursor.byte);
remaining_offset -= backtrack;
self.cursor.byte -= backtrack;
if self.cursor.byte == 0 {
if self.cursor.slice == 0 {
break;
}
self.cursor.slice -= 1;
self.cursor.byte = self
.inner
.slices
.get(self.cursor.slice)
.ok_or(DidntRead)?
.len();
}
}
if remaining_offset == 0 {
Ok(())
} else {
Err(DidntRead)
}
}
}

#[cfg(feature = "std")]
impl<'a> io::Seek for ZBufReader<'a> {
fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> {
let current_pos = self
.inner
.slices()
.take(self.cursor.slice)
.fold(0, |acc, s| acc + s.len())
+ self.cursor.byte;
let current_pos = i64::try_from(current_pos)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("{}", e)))?;

let offset = match pos {
std::io::SeekFrom::Start(s) => i64::try_from(s).unwrap_or(i64::MAX) - current_pos,
std::io::SeekFrom::Current(s) => s,
std::io::SeekFrom::End(s) => self.inner.len() as i64 + s - current_pos,
};
match self.advance(offset as isize) {
Ok(()) => Ok((offset + current_pos) as u64),
Err(_) => Err(std::io::Error::new(
std::io::ErrorKind::UnexpectedEof,
"UnexpectedEof",
std::io::ErrorKind::InvalidInput,
"InvalidInput",
)),
}
}
Expand Down Expand Up @@ -609,18 +718,18 @@ impl BacktrackableWriter for ZBufWriter<'_> {
}

#[cfg(feature = "std")]
impl<'a> std::io::Write for ZBufWriter<'a> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
impl<'a> io::Write for ZBufWriter<'a> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
match <Self as Writer>::write(self, buf) {
Ok(n) => Ok(n.get()),
Err(_) => Err(std::io::Error::new(
std::io::ErrorKind::UnexpectedEof,
Err(_) => Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"UnexpectedEof",
)),
}
}

fn flush(&mut self) -> std::io::Result<()> {
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
Expand Down Expand Up @@ -663,4 +772,47 @@ mod tests {

assert_eq!(zbuf1, zbuf2);
}

#[cfg(feature = "std")]
#[test]
fn zbuf_seek() {
use super::{HasReader, ZBuf};
use crate::reader::Reader;
use std::io::Seek;

let mut buf = ZBuf::empty();
buf.push_zslice([0u8, 1u8, 2u8, 3u8].into());
buf.push_zslice([4u8, 5u8, 6u8, 7u8, 8u8].into());
buf.push_zslice([9u8, 10u8, 11u8, 12u8, 13u8, 14u8].into());
let mut reader = buf.reader();

assert_eq!(reader.stream_position().unwrap(), 0);
assert_eq!(reader.read_u8().unwrap(), 0);
assert_eq!(reader.seek(std::io::SeekFrom::Current(6)).unwrap(), 7);
assert_eq!(reader.read_u8().unwrap(), 7);
assert_eq!(reader.seek(std::io::SeekFrom::Current(-5)).unwrap(), 3);
assert_eq!(reader.read_u8().unwrap(), 3);
assert_eq!(reader.seek(std::io::SeekFrom::Current(10)).unwrap(), 14);
assert_eq!(reader.read_u8().unwrap(), 14);
reader.seek(std::io::SeekFrom::Current(100)).unwrap_err();

assert_eq!(reader.seek(std::io::SeekFrom::Start(0)).unwrap(), 0);
assert_eq!(reader.read_u8().unwrap(), 0);
assert_eq!(reader.seek(std::io::SeekFrom::Start(12)).unwrap(), 12);
assert_eq!(reader.read_u8().unwrap(), 12);
assert_eq!(reader.seek(std::io::SeekFrom::Start(15)).unwrap(), 15);
reader.read_u8().unwrap_err();
reader.seek(std::io::SeekFrom::Start(100)).unwrap_err();

assert_eq!(reader.seek(std::io::SeekFrom::End(0)).unwrap(), 15);
reader.read_u8().unwrap_err();
assert_eq!(reader.seek(std::io::SeekFrom::End(-5)).unwrap(), 10);
assert_eq!(reader.read_u8().unwrap(), 10);
assert_eq!(reader.seek(std::io::SeekFrom::End(-15)).unwrap(), 0);
assert_eq!(reader.read_u8().unwrap(), 0);
reader.seek(std::io::SeekFrom::End(-20)).unwrap_err();

assert_eq!(reader.seek(std::io::SeekFrom::Start(10)).unwrap(), 10);
reader.seek(std::io::SeekFrom::Current(-100)).unwrap_err();
}
}
Loading
Loading