@@ -78,6 +78,24 @@ enum class TableInitExprStatus {
7878 TableWithoutInitExpression,
7979};
8080
81+ struct ComponentNamedType {
82+ std::string_view name;
83+ ComponentType type;
84+ };
85+
86+ struct ComponentExternalInfo {
87+ ComponentBinarySort sort;
88+ ComponentBinaryCoreSort core_sort;
89+ ComponentBinaryExternal external;
90+ Index index;
91+ };
92+
93+ struct ComponentExportInfo {
94+ ComponentBinarySort sort;
95+ ComponentBinaryCoreSort core_sort;
96+ Index index;
97+ };
98+
8199class BinaryReaderDelegate {
82100 public:
83101 struct State {
@@ -558,11 +576,76 @@ class BinaryReaderDelegate {
558576 const State* state = nullptr ;
559577};
560578
579+ class ComponentBinaryReaderDelegate {
580+ public:
581+ virtual ~ComponentBinaryReaderDelegate () {}
582+
583+ virtual bool OnError (const Error&) = 0;
584+ virtual void OnSetState (const BinaryReaderDelegate::State* s) { state = s; }
585+
586+ virtual Result OnCoreModule (const void * data,
587+ size_t size,
588+ const ReadBinaryOptions& options) = 0;
589+ virtual Result BeginComponent (uint32_t version, size_t depth) = 0;
590+ virtual Result EndComponent () = 0;
591+
592+ virtual Result BeginAliasSection (uint32_t count) = 0;
593+ virtual Result EndAliasSection () = 0;
594+ virtual Result OnAliasExport (ComponentBinarySort sort,
595+ ComponentBinaryCoreSort core_sort,
596+ uint32_t instance_index,
597+ std::string_view export_name) = 0;
598+ virtual Result OnAliasOuter (ComponentBinarySort sort,
599+ ComponentBinaryCoreSort core_sort,
600+ uint32_t counter,
601+ uint32_t index) = 0;
602+
603+ virtual Result BeginTypeSection (uint32_t count) = 0;
604+ virtual Result EndTypeSection () = 0;
605+ virtual Result OnPrimitiveType (ComponentType type) = 0;
606+ virtual Result OnRecordType (uint32_t field_count,
607+ ComponentNamedType* fields) = 0;
608+ virtual Result OnVariantType (uint32_t case_count,
609+ ComponentNamedType* cases) = 0;
610+ virtual Result OnListType (ComponentType type) = 0;
611+ virtual Result OnListFixedType (ComponentType type, uint32_t size) = 0;
612+ virtual Result OnOptionType (ComponentType type) = 0;
613+ virtual Result OnResultType (ComponentType result, ComponentType error) = 0;
614+ virtual Result OnOwnType (Index index) = 0;
615+ virtual Result OnBorrowType (Index index) = 0;
616+ virtual Result OnFuncType (ComponentBinaryType type,
617+ uint32_t param_count,
618+ ComponentNamedType* params,
619+ ComponentType result) = 0;
620+ virtual Result BeginInstanceType (uint32_t count) = 0;
621+ virtual Result EndInstanceType () = 0;
622+ virtual Result BeginComponentType (uint32_t count) = 0;
623+ virtual Result EndComponentType () = 0;
624+
625+ virtual Result BeginImportSection (uint32_t count) = 0;
626+ virtual Result EndImportSection () = 0;
627+ virtual Result BeginExportSection (uint32_t count) = 0;
628+ virtual Result EndExportSection () = 0;
629+ virtual Result OnImport (std::string_view external_name,
630+ std::string_view* version_suffix,
631+ ComponentExternalInfo* external_info) = 0;
632+ virtual Result OnExport (std::string_view external_name,
633+ std::string_view* version_suffix,
634+ ComponentExternalInfo* external_info,
635+ ComponentExportInfo* export_info) = 0;
636+ const BinaryReaderDelegate::State* state = nullptr ;
637+ };
638+
561639Result ReadBinary (const void * data,
562640 size_t size,
563641 BinaryReaderDelegate* reader,
564642 const ReadBinaryOptions& options);
565643
644+ Result ReadBinaryComponent (const void * data,
645+ size_t size,
646+ ComponentBinaryReaderDelegate* component_delegate,
647+ const ReadBinaryOptions& options);
648+
566649size_t ReadU32Leb128 (const uint8_t * ptr,
567650 const uint8_t * end,
568651 uint32_t * out_value);
0 commit comments