Skip to main content

Module primitives

Module primitives 

Source
Expand description

Application-tagged primitive encode/decode per ASHRAE 135-2020 Clause 20.2.

Provides both raw value codecs (no tag header) and application/context-tagged convenience functions for all BACnet primitive types.

The bounded scalar encoders also have _to_sink entrypoints accepting crate::sink::EncodeSink. Each appends its complete value, including any tag header, in one atomic write and returns the appended byte count. Known capacity shortages never call the sink; a custom sink’s error is unchanged. The scalar staging buffer is at most eleven bytes. These functions preserve the existing encoders’ input semantics and do not add value validation.

encode_timestamp_choice_to_sink and encode_timestamp_to_sink extend the same one-write contract to complete timestamps, with twelve-byte and sixteen-byte staging bounds respectively. These bounds describe encoded output, not the full call stack.

The CharacterString, OCTET STRING and BIT STRING _to_sink encoders write a header and a caller’s payload as one value with EncodeSink::write_parts. CharacterStringRef and ApplicationValueRef read strings and application-tagged values without copying them. Those, the scalar decoders and the sink encoders need no allocator; the BytesMut encoders and the owned PropertyValue decoders need alloc.

Modules§

charset
Character set identifiers.

Structs§

CharacterStringRef
A CharacterString’s contents, borrowed from the octets they were decoded from: the character-set octet, then the string in that character set (Clause 20.2.9).

Enums§

ApplicationValueRef
One application-tagged value of a primitive datatype (Clause 20.2.2 to 20.2.14), borrowed from the octets it was decoded from.

Constants§

MAX_TIMESTAMP_SEQUENCE_NUMBER
Largest encodable sequence-number value: the production constrains it to Unsigned (0..65535).
PRIORITY_DATE_TIME_TAG
The context tag of the date-time choice of BACnetPriorityValue.

Functions§

character_string_len
Return the encoded length of a character string (charset byte + UTF-8 bytes). Only with alloc: the sink encoders refuse an over-long string with SinkFull instead.
decode_application_value
Decode a single application-tagged value from data at offset.
decode_application_value_ref
Decode one application-tagged primitive value from data at offset, without copying it; returns the value and the offset past it.
decode_bit_string
Decode a bit string from content bytes.
decode_bit_string_ref
Decode a bit string from content bytes without copying its data octets.
decode_character_string
Decode a character string from content bytes.
decode_double
Decode an IEEE-754 double-precision float from 8 big-endian bytes.
decode_priority_date_time
Decode the date-time choice of BACnetPriorityValue at offset, returning the Date, the Time and the offset past the closing tag.
decode_real
Decode an IEEE-754 single-precision float from 4 big-endian bytes.
decode_signed
Decode a signed integer from two’s-complement big-endian bytes (1-4 bytes).
decode_timestamp
Decode a BACnetTimeStamp from inside a context opening/closing tag pair.
decode_timestamp_choice
Decode a bare-CHOICE BACnetTimeStamp starting at offset.
decode_unsigned
Decode an unsigned integer from big-endian bytes (1-8 bytes).
decode_unsigned_u8
Decode an unsigned integer that fits in a u8 from 1-8 big-endian bytes. Leading zero bytes are accepted; values above u8::MAX are rejected.
decode_unsigned_u16
Decode an unsigned integer that fits in a u16 from 1-8 big-endian bytes. Leading zero bytes are accepted; values above u16::MAX are rejected.
decode_unsigned_u32
Decode an unsigned integer that fits in a u32 from 1-8 big-endian bytes. Leading zero bytes are accepted; values above u32::MAX are rejected.
encode_app_bit_string
Encode an application-tagged BitString. It keeps its own code rather than delegating to encode_app_bit_string_to_sink: past u32::MAX octets it saturates the length, where the sink encoder refuses.
encode_app_bit_string_to_sink
Append an application-tagged BIT STRING. Returns the octets appended.
encode_app_boolean
Encode an application-tagged Boolean.
encode_app_boolean_to_sink
Append an application-tagged Boolean with its value in the header and no contents.
encode_app_character_string
Encode an application-tagged CharacterString (UTF-8). Delegates to encode_app_character_string_to_sink; a string too long for a header’s 32-bit length is Error::Encode, with nothing written.
encode_app_character_string_to_sink
Append an application-tagged UTF-8 CharacterString. Returns the octets appended.
encode_app_date
Encode an application-tagged Date.
encode_app_date_to_sink
Append an application-tagged Date preserving its four fields without validation.
encode_app_double
Encode an application-tagged Double (f64).
encode_app_double_to_sink
Append an application-tagged Double preserving every payload bit.
encode_app_enumerated
Encode an application-tagged Enumerated.
encode_app_enumerated_to_sink
Append an application-tagged Enumerated with its minimum-width contents.
encode_app_null
Encode an application-tagged Null.
encode_app_null_to_sink
Append an application-tagged Null with no contents.
encode_app_object_id
Encode an application-tagged ObjectIdentifier.
encode_app_object_id_to_sink
Append an application-tagged ObjectIdentifier preserving its 10-bit type and 22-bit instance.
encode_app_octet_string
Encode an application-tagged OctetString. It keeps its own code rather than delegating to encode_app_octet_string_to_sink: past u32::MAX octets it saturates the length, where the sink encoder refuses.
encode_app_octet_string_to_sink
Append an application-tagged OCTET STRING. Returns the octets appended.
encode_app_real
Encode an application-tagged Real (f32).
encode_app_real_to_sink
Append an application-tagged Real preserving every payload bit.
encode_app_signed
Encode an application-tagged Signed.
encode_app_signed_to_sink
Append an application-tagged Signed with its minimum-width contents.
encode_app_time
Encode an application-tagged Time.
encode_app_time_to_sink
Append an application-tagged Time preserving its four fields without validation.
encode_app_unsigned
Encode an application-tagged Unsigned.
encode_app_unsigned_to_sink
Append an application-tagged Unsigned with its minimum-width contents.
encode_bit_string
Encode a bit string: leading unused-bits count followed by data bytes. Delegates to encode_bit_string_to_sink.
encode_bit_string_to_sink
Append a BIT STRING’s contents, without a tag: the unused-bit count, then the data octets. Returns the octets appended. Like the BytesMut encoder, it doesn’t check the count.
encode_character_string
Encode a UTF-8 character string with leading charset byte. Delegates to encode_character_string_to_sink.
encode_character_string_to_sink
Append a UTF-8 CharacterString’s contents, without a tag: the character-set octet X’00’, then the string’s octets. Returns the octets appended.
encode_ctx_bit_string
Encode a context-tagged BitString. It keeps its own code rather than delegating to encode_ctx_bit_string_to_sink: past u32::MAX octets it saturates the length, where the sink encoder refuses.
encode_ctx_bit_string_to_sink
Append a BIT STRING under context tag tag. Returns the octets appended.
encode_ctx_boolean
Encode a context-tagged Boolean.
encode_ctx_boolean_to_sink
Append a context-tagged Boolean with one content octet.
encode_ctx_character_string
Encode a context-tagged CharacterString (UTF-8). Delegates to encode_ctx_character_string_to_sink; a string too long for a header’s 32-bit length is Error::Encode, with nothing written.
encode_ctx_character_string_to_sink
Append a UTF-8 CharacterString under context tag tag. Returns the octets appended.
encode_ctx_date
Encode a context-tagged Date.
encode_ctx_date_to_sink
Append a context-tagged Date preserving its four fields without validation.
encode_ctx_double
Encode a context-tagged Double (f64).
encode_ctx_double_to_sink
Append a context-tagged Double preserving every payload bit.
encode_ctx_enumerated
Encode a context-tagged Enumerated.
encode_ctx_enumerated_to_sink
Append a context-tagged Enumerated with its minimum-width contents.
encode_ctx_object_id
Encode a context-tagged ObjectIdentifier.
encode_ctx_object_id_to_sink
Append a context-tagged ObjectIdentifier preserving its 10-bit type and 22-bit instance.
encode_ctx_octet_string
Encode a context-tagged OctetString. It keeps its own code rather than delegating to encode_ctx_octet_string_to_sink: past u32::MAX octets it saturates the length, where the sink encoder refuses.
encode_ctx_octet_string_to_sink
Append an OCTET STRING under context tag tag. Returns the octets appended.
encode_ctx_real
Encode a context-tagged Real (f32).
encode_ctx_real_to_sink
Append a context-tagged Real preserving every payload bit.
encode_ctx_signed
Encode a context-tagged Signed.
encode_ctx_signed_to_sink
Append a context-tagged Signed with its minimum-width contents.
encode_ctx_unsigned
Encode a context-tagged Unsigned.
encode_ctx_unsigned_to_sink
Append a context-tagged Unsigned with its minimum-width contents.
encode_double
Encode an IEEE-754 double-precision float (big-endian, 8 bytes).
encode_double_to_sink
Append the eight IEEE-754 octets of a Double in big-endian order without a tag.
encode_priority_date_time
Append one Priority_Array element holding a date-time: opening tag 1, the application-tagged Date and Time, closing tag 1 (twelve octets).
encode_property_value
Encode a PropertyValue as an application-tagged value. Only with alloc.
encode_real
Encode an IEEE-754 single-precision float (big-endian, 4 bytes).
encode_real_to_sink
Append the four IEEE-754 octets of a Real in big-endian order without a tag.
encode_signed
Encode a signed integer using minimum octets, two’s complement, big-endian.
encode_signed_to_sink
Append a signed integer in the minimum two’s-complement width without a tag.
encode_timestamp
Encode a BACnetTimeStamp wrapped in a context opening/closing tag pair.
encode_timestamp_choice
Encode a BACnetTimeStamp as a bare CHOICE element (no enclosing field tag). Delegates to encode_timestamp_choice_to_sink through the growable buffer; the existing result type is retained.
encode_timestamp_choice_to_sink
Append a complete bare BACnetTimeStamp CHOICE in one sink write.
encode_timestamp_to_sink
Append an outer context frame and its complete timestamp in one sink write.
encode_unsigned
Encode an unsigned integer using the minimum number of big-endian octets.
encode_unsigned_to_sink
Append an unsigned integer in the minimum big-endian width without a tag.
signed_len
Return the number of bytes needed to encode a signed value.
unsigned_len
Return the number of bytes needed to encode an unsigned value.
validate_application_value
Check that an application-tagged value starts at offset and is structurally well formed, returning the offset just past it.