Struct rspirv::binary::Decoder
[−]
[src]
pub struct Decoder<'a> { /* fields omitted */ }
The SPIR-V binary decoder.
Takes in a vector of bytes, and serves requests for raw SPIR-V words or values of a specific SPIR-V enum type. Successful decoding will surely consume the number of words decoded, while unsuccessful decoding may consume any number of bytes.
TODO: The decoder should not conume words if an error occurs.
Different from the Parser
,
this decoder is low-level; it has no knowledge of the SPIR-V grammar.
Given a vector of bytes, it solely responds to word decoding requests
via method calls: both raw words requests and decoding the raw words
into a value of a specific SPIR-V enum type.
It also provides a limit mechanism. Users can set a limit, and then
requesting words. If that limit is reached before the end of the
stream, State::LimitReached
will be
returned.
Errors
For its methods, there can be the following errors:
Error::LimitReached(offset)
if the most recent limit has reached.Error::StreamExpected(offset)
if more bytes are needed to decode the next word.Error::<spirv-enum>Unknown(offset, value)
if failed to decode the next word as the given<spirv-enum>
.
All errors contain the byte offset of the word failed decoding.
Examples
extern crate rspirv; extern crate spirv_headers as spirv; use rspirv::binary::{Decoder, DecodeError}; use spirv::SourceLanguage; fn main() { let v = vec![0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x02, 0x00, 0x00, 0x00]; let mut d = Decoder::new(&v); assert_eq!(Ok(0x78563412), d.word()); assert_eq!(Ok(0xefcdab90), d.word()); assert_eq!(Ok(SourceLanguage::GLSL), d.source_language()); assert_eq!(Err(DecodeError::StreamExpected(12)), d.word()); }
Methods
impl<'a> Decoder<'a>
[src]
fn new(bytes: &'a [u8]) -> Decoder<'a>
[src]
Creates a new Decoder
instance.
fn offset(&self) -> usize
[src]
Returns the offset of the byte to decode next.
fn word(&mut self) -> Result<Word, Error>
[src]
Decodes and returns the next raw SPIR-V word.
fn words(&mut self, n: usize) -> Result<Vec<Word>, Error>
[src]
Decodes and returns the next n
raw SPIR-V words.
impl<'a> Decoder<'a>
[src]
fn set_limit(&mut self, num_words: usize)
[src]
Sets the limit to num_words
words.
The decoder will return State::LimitReached
after num_words
words have been requested, if having not consumed
the whole stream.
fn clear_limit(&mut self)
[src]
Clear the previously set limit (if any).
fn has_limit(&self) -> bool
[src]
Returns true if a limit has been set on this decoder.
fn limit_reached(&self) -> bool
[src]
Returns true if the previously set limit has been reached.
This will always return false if no limit has been ever set.
impl<'a> Decoder<'a>
[src]
fn id(&mut self) -> Result<Word, Error>
[src]
Decodes and returns the next SPIR-V word as an id.
fn string(&mut self) -> Result<String, Error>
[src]
Decodes and returns a literal string.
This method will consume as many words as necessary until finding a
null character (\0
), or reaching the limit or end of the stream
and erroring out.
fn int32(&mut self) -> Result<u32, Error>
[src]
Decodes and returns the next SPIR-V word as a 32-bit literal integer.
fn int64(&mut self) -> Result<u64, Error>
[src]
Decodes and returns the next two SPIR-V words as a 64-bit literal integer.
fn float32(&mut self) -> Result<f32, Error>
[src]
Decodes and returns the next SPIR-V word as a 32-bit literal floating point number.
fn float64(&mut self) -> Result<f64, Error>
[src]
Decodes and returns the next two SPIR-V words as a 64-bit literal floating point number.
fn ext_inst_integer(&mut self) -> Result<u32, Error>
[src]
Decodes and returns the next SPIR-V word as a 32-bit extended-instruction-set number.
impl<'a> Decoder<'a>
[src]
fn image_operands(&mut self) -> Result<ImageOperands, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V ImageOperands value.
fn fpfast_math_mode(&mut self) -> Result<FPFastMathMode, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V FPFastMathMode value.
fn selection_control(&mut self) -> Result<SelectionControl, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V SelectionControl value.
fn loop_control(&mut self) -> Result<LoopControl, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V LoopControl value.
fn function_control(&mut self) -> Result<FunctionControl, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V FunctionControl value.
fn memory_semantics(&mut self) -> Result<MemorySemantics, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V MemorySemantics value.
fn memory_access(&mut self) -> Result<MemoryAccess, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V MemoryAccess value.
fn kernel_profiling_info(&mut self) -> Result<KernelProfilingInfo, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V KernelProfilingInfo value.
fn source_language(&mut self) -> Result<SourceLanguage, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V SourceLanguage value.
fn execution_model(&mut self) -> Result<ExecutionModel, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V ExecutionModel value.
fn addressing_model(&mut self) -> Result<AddressingModel, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V AddressingModel value.
fn memory_model(&mut self) -> Result<MemoryModel, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V MemoryModel value.
fn execution_mode(&mut self) -> Result<ExecutionMode, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V ExecutionMode value.
fn storage_class(&mut self) -> Result<StorageClass, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V StorageClass value.
fn dim(&mut self) -> Result<Dim, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V Dim value.
fn sampler_addressing_mode(&mut self) -> Result<SamplerAddressingMode, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V SamplerAddressingMode value.
fn sampler_filter_mode(&mut self) -> Result<SamplerFilterMode, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V SamplerFilterMode value.
fn image_format(&mut self) -> Result<ImageFormat, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V ImageFormat value.
fn image_channel_order(&mut self) -> Result<ImageChannelOrder, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V ImageChannelOrder value.
fn image_channel_data_type(&mut self) -> Result<ImageChannelDataType, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V ImageChannelDataType value.
fn fprounding_mode(&mut self) -> Result<FPRoundingMode, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V FPRoundingMode value.
fn linkage_type(&mut self) -> Result<LinkageType, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V LinkageType value.
fn access_qualifier(&mut self) -> Result<AccessQualifier, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V AccessQualifier value.
fn function_parameter_attribute(
&mut self
) -> Result<FunctionParameterAttribute, Error>
[src]
&mut self
) -> Result<FunctionParameterAttribute, Error>
Decodes and returns the next SPIR-V word as a SPIR-V FunctionParameterAttribute value.
fn decoration(&mut self) -> Result<Decoration, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V Decoration value.
fn built_in(&mut self) -> Result<BuiltIn, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V BuiltIn value.
fn scope(&mut self) -> Result<Scope, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V Scope value.
fn group_operation(&mut self) -> Result<GroupOperation, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V GroupOperation value.
fn kernel_enqueue_flags(&mut self) -> Result<KernelEnqueueFlags, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V KernelEnqueueFlags value.
fn capability(&mut self) -> Result<Capability, Error>
[src]
Decodes and returns the next SPIR-V word as a SPIR-V Capability value.