objstr/api/objstr.rs
1use std::io::{Error, SeekFrom};
2
3pub trait ObjStr {
4
5 /// Seeks to the given object in the stream.
6 fn seek(&mut self, pos: SeekFrom) -> Result<(), Error>;
7
8 /// Read the next object from the stream.
9 fn read(&mut self) -> Result<Vec<u8>, Error>;
10
11 /// Returns the length of the current object (+ the following objects if objs > 1) and subtracts ops*contents from the length.
12 ///
13 /// If contents::0 and objs::0, 0 is returned.
14 ///
15 /// If contents::0 and objs::1, the length of the current object is returned.
16 ///
17 /// If contents::1 and objs::0, error occurs.
18 ///
19 /// If contents::1 and objs::1, the length of the current object-content is returned.
20 ///
21 /// If contents::1 and objs::2, the length of the current object plus the length of the following object is subtracted 4*op_code(2*op_set) returned.
22 ///
23 /// If contents::2 and objs::0, error occurs.
24 ///
25 /// If contents::2 and objs::1, the length of the current object subtracted 4*op_code(2*op_set) is returned.
26 fn len(&mut self, contents: u8, objs: u8) -> Result<u64, Error>;
27
28 /// Overwrites the current object or objects with the given object-contents.
29 ///
30 /// If objs::0, error occurs.
31 ///
32 /// If objs::1 and data.len() < 1, error occurs.
33 ///
34 /// If objs::1 and data.len() == 1, the current object is overwritten.
35 ///
36 /// If objs::2 and data.len() == 1, the current object and the following object are overwritten.
37 ///
38 /// If objs::1 and data.len() < 1, the current object will be overwritten with multiple objects.
39 ///
40 /// If objs::2 and data.len() < 1, the current object and the following objects will be overwritten with multiple objects.
41 fn overwrite(&mut self, data: Vec<Vec<u8>>, objs: u8) -> Result<(), Error>;
42
43 /// Appends an object to the end of the stream.
44 fn append(&mut self, data: Vec<u8>) -> Result<(), Error>;
45
46 /// Deletes the current and all following objects.
47 fn cut(&mut self) -> Result<(), Error>;
48}