Module: Ace::Hitl::Hermes::Molecules::HermesFormats
- Defined in:
- lib/ace/hitl/hermes/molecules/hermes_formats.rb
Overview
Message format registry (spec 8wm.t.vs1 §9): the decode gate every message file passes before any other validation. Supports exactly ace.hitl.hermes.message/v1; unknown versions and every encoding/size violation fail closed.
Constant Summary collapse
- SUPPORTED =
[HermesContract::MESSAGE_SCHEMA].freeze
Class Method Summary collapse
-
.decode!(bytes) ⇒ Object
bytes -> parsed JSON object (Hash).
- .supported ⇒ Object
Class Method Details
.decode!(bytes) ⇒ Object
bytes -> parsed JSON object (Hash). Raises InvalidMessageError for size/encoding/JSON violations, UnknownFormatError for an unsupported or absent schema id.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ace/hitl/hermes/molecules/hermes_formats.rb', line 26 def decode!(bytes) unless bytes.bytesize <= HermesContract::MAX_BYTES raise InvalidMessageError, "message exceeds the #{HermesContract::MAX_BYTES}-byte size bound " \ "(#{bytes.bytesize} bytes)" end content = bytes.dup.force_encoding(Encoding::UTF_8) unless content.valid_encoding? raise InvalidMessageError, "message is not valid UTF-8" end hash = begin JSON.parse(content) rescue JSON::ParserError => e raise InvalidMessageError, "message is not valid JSON: #{e.}" end unless hash.is_a?(Hash) raise InvalidMessageError, "message must be a JSON object" end schema = hash["schema"] unless SUPPORTED.include?(schema) raise UnknownFormatError, "unsupported message schema #{schema.inspect} (supported: " \ "#{SUPPORTED.join(", ")})" end hash end |
.supported ⇒ Object
19 20 21 |
# File 'lib/ace/hitl/hermes/molecules/hermes_formats.rb', line 19 def supported SUPPORTED.dup end |