1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::errors::MessageRejectErrorEnum;
use crate::{field_map::LocalField, tag::Tag};
use simple_error::SimpleResult;
pub trait FieldTag {
fn tag(&self) -> Tag;
}
// FieldValueWriter is an interface for writing field values
pub trait FieldValueWriter {
// write_to appends the field value bytes to buf
fn write_to(&self, buf: &mut Vec<u8>);
// write returns the field value as a new Vec<u8>
fn write(&self) -> Vec<u8> {
let mut buf = Vec::new();
self.write_to(&mut buf);
buf
}
}
// FieldValueReader is an interface for reading field values
pub trait FieldValueReader {
// read reads the contents of the []byte into FieldValue.
// returns an error if there are issues in the data processing
fn read(&mut self, input: &[u8]) -> SimpleResult<()>;
}
// The FieldValue interface is used to write/extract typed field values to/from raw bytes
pub trait FieldValue: FieldValueWriter + FieldValueReader {}
// FieldWriter is an interface for a writing a field
pub trait FieldWriter: FieldValueWriter + FieldTag {}
// Field is the interface implemented by all typed Fields in a Message
pub trait Field: FieldWriter + FieldValueReader {}
// FieldGroupWriter is an interface for writing a FieldGroup
pub trait FieldGroupWriter: FieldTag {
fn write(&self) -> LocalField;
}
// FieldGroupReader is an interface for reading a FieldGroup
pub trait FieldGroupReader: FieldTag {
fn read(&mut self, tag_value: LocalField) -> Result<LocalField, MessageRejectErrorEnum>;
}
// FieldGroup is the interface implemented by all typed Groups in a Message
pub trait FieldGroup: FieldTag + FieldGroupWriter + FieldGroupReader {}