pub trait SubObjectAccess: Sync + Send {
// Required methods
fn read(&self, offset: usize, buf: &mut [u8]) -> Result<usize, AbortCode>;
fn read_size(&self) -> usize;
fn write(&self, data: &[u8]) -> Result<(), AbortCode>;
// Provided methods
fn begin_partial(&self) -> Result<(), AbortCode> { ... }
fn write_partial(&self, _buf: &[u8]) -> Result<(), AbortCode> { ... }
fn end_partial(&self) -> Result<(), AbortCode> { ... }
}Expand description
Allow transparent byte level access to a sub object
Required Methods§
Sourcefn read(&self, offset: usize, buf: &mut [u8]) -> Result<usize, AbortCode>
fn read(&self, offset: usize, buf: &mut [u8]) -> Result<usize, AbortCode>
Read data from the sub object
Read up to buf.len() bytes, starting at offset
§Arguments
offset: The offset into the object to begin the readbuf: The output buffer to fill
§Returns
The number of bytes read into buf, on success
§Errors
AbortCode::WriteOnlyif the sub object does not support readingAbortCode::ResourceNotAvailableif the sub object depends on a runtime registered handler which has not been registered
Sourcefn read_size(&self) -> usize
fn read_size(&self) -> usize
Return the amount of data which can be read
This should return the maximum number of bytes which can be read from the object
For most objects, this is simply it’s allocated size – e.g. for a UInt32 DataType
read_size always return 4. Others may have variable or run-time determined size, for
example VisibleString objects can ctonshorter than their allocated size.
Note: Callers cannot assume that a call to read will return the same number of bytes as read_size. It is possible for the available number of bytes to change between a call to read_size and a subsequent call to read.
Sourcefn write(&self, data: &[u8]) -> Result<(), AbortCode>
fn write(&self, data: &[u8]) -> Result<(), AbortCode>
Write data to the sub object
For most objects, the length of data must match the size of the object exactly. However, for some objects, such as Domain, VisibleString, UnicodeString, or objects with custom callback implementations it may be possible to write shorter values.
§Errors
AbortCode::DataTypeMismatchLengthHighifdata.len()exceeds the object sizeAbortCode::DataTypeMismatchLengthLowifdata.len()is smaller than the object size and the object does not support thisAbortCode::ReadOnlyif the object does not support writingAbortCode::InvalidValueif the value is not allowedAbortCode::ValueTooHighif the value is higher than the allowed range of this objectAbortCode::ValueTooLowif the value is lower than the allowed range of this objectAbortCode::ResourceNotAvailableif the object cannot be written because of the application state. For example, this is returned if a required callback has not been registered on the object.
Other error types may be returned by special purpose objects implemented via custom callback.
Provided Methods§
Sourcefn begin_partial(&self) -> Result<(), AbortCode>
fn begin_partial(&self) -> Result<(), AbortCode>
Begin a multi-part write to the object
Not all objects support partial writes. Primarily it is large objects which support it in
order to allow transfer of data in multiple blocks. It is up to the application to ensure
that no other writes occur while a partial write is in progress, or else the object data may
be corrupted and/or a call to write_partial may return an abort code on a subsequent call.
Partial writes should always be performed according to the following sequence:
- One call to
begin_partial - Zero or more calls to
write_partial - One call to
end_partial
§Errors
- `AbortCode::UnsupportedAccess if the object does not support partial writes
AbortCode::ReadOnlyif the object does not support writingAbortCode::ResourceNotAvailableif the object cannot be written because of the application state. For example, this is returned if a required callback has not been registered on the object.
Sourcefn write_partial(&self, _buf: &[u8]) -> Result<(), AbortCode>
fn write_partial(&self, _buf: &[u8]) -> Result<(), AbortCode>
Write part of multi-part data to the object
Calls to write_partial must be preceded by a call to begin_partial, and followed by a call to end_partial.
§Errors
AbortCode::DataTypeMismatchLengthHighifdata.len()exceeds the object size
Sourcefn end_partial(&self) -> Result<(), AbortCode>
fn end_partial(&self) -> Result<(), AbortCode>
Finish a multi-part write