@dcl/protocol 1.0.0-2731649607.commit-890a990 → 1.0.0-27358757907.commit-3c70e8a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +266 -0
- package/out-js/about.gen.d.ts +1 -0
- package/out-js/about.gen.js +6 -0
- package/out-js/about.gen.js.map +1 -0
- package/out-js/comms.gen.d.ts +1 -0
- package/out-js/comms.gen.js +6 -0
- package/out-js/comms.gen.js.map +1 -0
- package/out-js/decentraland/common/border_rect.gen.d.ts +49 -0
- package/out-js/decentraland/common/border_rect.gen.js +201 -0
- package/out-js/decentraland/common/border_rect.gen.js.map +1 -0
- package/out-js/decentraland/common/colors.gen.d.ts +59 -0
- package/out-js/decentraland/common/colors.gen.js +260 -0
- package/out-js/decentraland/common/colors.gen.js.map +1 -0
- package/out-js/decentraland/common/content_mapping.gen.d.ts +31 -0
- package/out-js/decentraland/common/content_mapping.gen.js +80 -0
- package/out-js/decentraland/common/content_mapping.gen.js.map +1 -0
- package/out-js/decentraland/common/sdk/user_data.gen.d.ts +63 -0
- package/out-js/decentraland/common/sdk/user_data.gen.js +330 -0
- package/out-js/decentraland/common/sdk/user_data.gen.js.map +1 -0
- package/out-js/decentraland/common/texture.gen.d.ts +105 -0
- package/out-js/decentraland/common/texture.gen.js +475 -0
- package/out-js/decentraland/common/texture.gen.js.map +1 -0
- package/out-js/decentraland/common/vectors.gen.d.ts +71 -0
- package/out-js/decentraland/common/vectors.gen.js +338 -0
- package/out-js/decentraland/common/vectors.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/comms_api.gen.d.ts +206 -0
- package/out-js/decentraland/kernel/apis/comms_api.gen.js +792 -0
- package/out-js/decentraland/kernel/apis/comms_api.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/communications_controller.gen.d.ts +105 -0
- package/out-js/decentraland/kernel/apis/communications_controller.gen.js +400 -0
- package/out-js/decentraland/kernel/apis/communications_controller.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/dev_tools.gen.d.ts +58 -0
- package/out-js/decentraland/kernel/apis/dev_tools.gen.js +142 -0
- package/out-js/decentraland/kernel/apis/dev_tools.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/engine_api.gen.d.ts +338 -0
- package/out-js/decentraland/kernel/apis/engine_api.gen.js +1452 -0
- package/out-js/decentraland/kernel/apis/engine_api.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/environment_api.gen.d.ts +283 -0
- package/out-js/decentraland/kernel/apis/environment_api.gen.js +1122 -0
- package/out-js/decentraland/kernel/apis/environment_api.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/ethereum_controller.gen.d.ts +225 -0
- package/out-js/decentraland/kernel/apis/ethereum_controller.gen.js +878 -0
- package/out-js/decentraland/kernel/apis/ethereum_controller.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/parcel_identity.gen.d.ts +146 -0
- package/out-js/decentraland/kernel/apis/parcel_identity.gen.js +557 -0
- package/out-js/decentraland/kernel/apis/parcel_identity.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/permissions.gen.d.ts +100 -0
- package/out-js/decentraland/kernel/apis/permissions.gen.js +360 -0
- package/out-js/decentraland/kernel/apis/permissions.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/players.gen.d.ts +127 -0
- package/out-js/decentraland/kernel/apis/players.gen.js +372 -0
- package/out-js/decentraland/kernel/apis/players.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/portable_experiences.gen.d.ts +178 -0
- package/out-js/decentraland/kernel/apis/portable_experiences.gen.js +607 -0
- package/out-js/decentraland/kernel/apis/portable_experiences.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/restricted_actions.gen.d.ts +303 -0
- package/out-js/decentraland/kernel/apis/restricted_actions.gen.js +1056 -0
- package/out-js/decentraland/kernel/apis/restricted_actions.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/runtime.gen.d.ts +217 -0
- package/out-js/decentraland/kernel/apis/runtime.gen.js +801 -0
- package/out-js/decentraland/kernel/apis/runtime.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/scene.gen.d.ts +59 -0
- package/out-js/decentraland/kernel/apis/scene.gen.js +171 -0
- package/out-js/decentraland/kernel/apis/scene.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/signed_fetch.gen.d.ts +139 -0
- package/out-js/decentraland/kernel/apis/signed_fetch.gen.js +615 -0
- package/out-js/decentraland/kernel/apis/signed_fetch.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/social_controller.gen.d.ts +72 -0
- package/out-js/decentraland/kernel/apis/social_controller.gen.js +207 -0
- package/out-js/decentraland/kernel/apis/social_controller.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/testing.gen.d.ts +249 -0
- package/out-js/decentraland/kernel/apis/testing.gen.js +1073 -0
- package/out-js/decentraland/kernel/apis/testing.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/user_action_module.gen.d.ts +56 -0
- package/out-js/decentraland/kernel/apis/user_action_module.gen.js +128 -0
- package/out-js/decentraland/kernel/apis/user_action_module.gen.js.map +1 -0
- package/out-js/decentraland/kernel/apis/user_identity.gen.d.ts +86 -0
- package/out-js/decentraland/kernel/apis/user_identity.gen.js +236 -0
- package/out-js/decentraland/kernel/apis/user_identity.gen.js.map +1 -0
- package/out-js/decentraland/kernel/comms/rfc4/comms.gen.d.ts +334 -0
- package/out-js/decentraland/kernel/comms/rfc4/comms.gen.js +2093 -0
- package/out-js/decentraland/kernel/comms/rfc4/comms.gen.js.map +1 -0
- package/out-js/decentraland/kernel/comms/rfc5/ws_comms.gen.d.ts +183 -0
- package/out-js/decentraland/kernel/comms/rfc5/ws_comms.gen.js +906 -0
- package/out-js/decentraland/kernel/comms/rfc5/ws_comms.gen.js.map +1 -0
- package/out-js/decentraland/kernel/comms/v3/archipelago.gen.d.ts +224 -0
- package/out-js/decentraland/kernel/comms/v3/archipelago.gen.js +1204 -0
- package/out-js/decentraland/kernel/comms/v3/archipelago.gen.js.map +1 -0
- package/out-js/decentraland/quests/definitions.gen.d.ts +541 -0
- package/out-js/decentraland/quests/definitions.gen.js +2728 -0
- package/out-js/decentraland/quests/definitions.gen.js.map +1 -0
- package/out-js/decentraland/realm/about.gen.d.ts +229 -0
- package/out-js/decentraland/realm/about.gen.js +1185 -0
- package/out-js/decentraland/realm/about.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/animator.gen.d.ts +62 -0
- package/out-js/decentraland/sdk/components/animator.gen.js +192 -0
- package/out-js/decentraland/sdk/components/animator.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/audio_source.gen.d.ts +61 -0
- package/out-js/decentraland/sdk/components/audio_source.gen.js +151 -0
- package/out-js/decentraland/sdk/components/audio_source.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/audio_stream.gen.d.ts +50 -0
- package/out-js/decentraland/sdk/components/audio_stream.gen.js +138 -0
- package/out-js/decentraland/sdk/components/audio_stream.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/avatar_attach.gen.d.ts +76 -0
- package/out-js/decentraland/sdk/components/avatar_attach.gen.js +262 -0
- package/out-js/decentraland/sdk/components/avatar_attach.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/avatar_base.gen.d.ts +36 -0
- package/out-js/decentraland/sdk/components/avatar_base.gen.js +129 -0
- package/out-js/decentraland/sdk/components/avatar_base.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/avatar_emote_command.gen.d.ts +37 -0
- package/out-js/decentraland/sdk/components/avatar_emote_command.gen.js +95 -0
- package/out-js/decentraland/sdk/components/avatar_emote_command.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/avatar_equipped_data.gen.d.ts +36 -0
- package/out-js/decentraland/sdk/components/avatar_equipped_data.gen.js +90 -0
- package/out-js/decentraland/sdk/components/avatar_equipped_data.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/avatar_modifier_area.gen.d.ts +60 -0
- package/out-js/decentraland/sdk/components/avatar_modifier_area.gen.js +153 -0
- package/out-js/decentraland/sdk/components/avatar_modifier_area.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/avatar_shape.gen.d.ts +82 -0
- package/out-js/decentraland/sdk/components/avatar_shape.gen.js +298 -0
- package/out-js/decentraland/sdk/components/avatar_shape.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/billboard.gen.d.ts +54 -0
- package/out-js/decentraland/sdk/components/billboard.gen.js +128 -0
- package/out-js/decentraland/sdk/components/billboard.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/camera_mode.gen.d.ts +36 -0
- package/out-js/decentraland/sdk/components/camera_mode.gen.js +70 -0
- package/out-js/decentraland/sdk/components/camera_mode.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/camera_mode_area.gen.d.ts +48 -0
- package/out-js/decentraland/sdk/components/camera_mode_area.gen.js +85 -0
- package/out-js/decentraland/sdk/components/camera_mode_area.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/common/camera_type.gen.d.ts +10 -0
- package/out-js/decentraland/sdk/components/common/camera_type.gen.js +46 -0
- package/out-js/decentraland/sdk/components/common/camera_type.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/common/id.gen.d.ts +1 -0
- package/out-js/decentraland/sdk/components/common/id.gen.js +6 -0
- package/out-js/decentraland/sdk/components/common/id.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/common/input_action.gen.d.ts +41 -0
- package/out-js/decentraland/sdk/components/common/input_action.gen.js +209 -0
- package/out-js/decentraland/sdk/components/common/input_action.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/common/loading_state.gen.d.ts +11 -0
- package/out-js/decentraland/sdk/components/common/loading_state.gen.js +57 -0
- package/out-js/decentraland/sdk/components/common/loading_state.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/common/raycast_hit.gen.d.ts +45 -0
- package/out-js/decentraland/sdk/components/common/raycast_hit.gen.js +163 -0
- package/out-js/decentraland/sdk/components/common/raycast_hit.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/common/texts.gen.d.ts +23 -0
- package/out-js/decentraland/sdk/components/common/texts.gen.js +120 -0
- package/out-js/decentraland/sdk/components/common/texts.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/engine_info.gen.d.ts +41 -0
- package/out-js/decentraland/sdk/components/engine_info.gen.js +95 -0
- package/out-js/decentraland/sdk/components/engine_info.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/gltf_container.gen.d.ts +41 -0
- package/out-js/decentraland/sdk/components/gltf_container.gen.js +101 -0
- package/out-js/decentraland/sdk/components/gltf_container.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/gltf_container_loading_state.gen.d.ts +35 -0
- package/out-js/decentraland/sdk/components/gltf_container_loading_state.gen.js +70 -0
- package/out-js/decentraland/sdk/components/gltf_container_loading_state.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/gltf_node_modifiers.gen.d.ts +57 -0
- package/out-js/decentraland/sdk/components/gltf_node_modifiers.gen.js +164 -0
- package/out-js/decentraland/sdk/components/gltf_node_modifiers.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/material.gen.d.ts +108 -0
- package/out-js/decentraland/sdk/components/material.gen.js +536 -0
- package/out-js/decentraland/sdk/components/material.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/mesh_collider.gen.d.ts +130 -0
- package/out-js/decentraland/sdk/components/mesh_collider.gen.js +471 -0
- package/out-js/decentraland/sdk/components/mesh_collider.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/mesh_renderer.gen.d.ts +104 -0
- package/out-js/decentraland/sdk/components/mesh_renderer.gen.js +382 -0
- package/out-js/decentraland/sdk/components/mesh_renderer.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/nft_shape.gen.d.ts +74 -0
- package/out-js/decentraland/sdk/components/nft_shape.gen.js +259 -0
- package/out-js/decentraland/sdk/components/nft_shape.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/player_identity_data.gen.d.ts +37 -0
- package/out-js/decentraland/sdk/components/player_identity_data.gen.js +83 -0
- package/out-js/decentraland/sdk/components/player_identity_data.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/pointer_events.gen.d.ts +110 -0
- package/out-js/decentraland/sdk/components/pointer_events.gen.js +306 -0
- package/out-js/decentraland/sdk/components/pointer_events.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/pointer_events_result.gen.d.ts +42 -0
- package/out-js/decentraland/sdk/components/pointer_events_result.gen.js +133 -0
- package/out-js/decentraland/sdk/components/pointer_events_result.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/pointer_lock.gen.d.ts +35 -0
- package/out-js/decentraland/sdk/components/pointer_lock.gen.js +69 -0
- package/out-js/decentraland/sdk/components/pointer_lock.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/raycast.gen.d.ts +79 -0
- package/out-js/decentraland/sdk/components/raycast.gen.js +274 -0
- package/out-js/decentraland/sdk/components/raycast.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/raycast_result.gen.d.ts +48 -0
- package/out-js/decentraland/sdk/components/raycast_result.gen.js +132 -0
- package/out-js/decentraland/sdk/components/raycast_result.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/realm_info.gen.d.ts +43 -0
- package/out-js/decentraland/sdk/components/realm_info.gen.js +151 -0
- package/out-js/decentraland/sdk/components/realm_info.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/text_shape.gen.d.ts +81 -0
- package/out-js/decentraland/sdk/components/text_shape.gen.js +345 -0
- package/out-js/decentraland/sdk/components/text_shape.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/tween.gen.d.ts +220 -0
- package/out-js/decentraland/sdk/components/tween.gen.js +1213 -0
- package/out-js/decentraland/sdk/components/tween.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/tween_sequence.gen.d.ts +39 -0
- package/out-js/decentraland/sdk/components/tween_sequence.gen.js +122 -0
- package/out-js/decentraland/sdk/components/tween_sequence.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/tween_state.gen.d.ts +40 -0
- package/out-js/decentraland/sdk/components/tween_state.gen.js +122 -0
- package/out-js/decentraland/sdk/components/tween_state.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/ui_background.gen.d.ts +63 -0
- package/out-js/decentraland/sdk/components/ui_background.gen.js +197 -0
- package/out-js/decentraland/sdk/components/ui_background.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/ui_dropdown.gen.d.ts +45 -0
- package/out-js/decentraland/sdk/components/ui_dropdown.gen.js +187 -0
- package/out-js/decentraland/sdk/components/ui_dropdown.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/ui_dropdown_result.gen.d.ts +30 -0
- package/out-js/decentraland/sdk/components/ui_dropdown_result.gen.js +69 -0
- package/out-js/decentraland/sdk/components/ui_dropdown_result.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/ui_input.gen.d.ts +44 -0
- package/out-js/decentraland/sdk/components/ui_input.gen.js +172 -0
- package/out-js/decentraland/sdk/components/ui_input.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/ui_input_result.gen.d.ts +32 -0
- package/out-js/decentraland/sdk/components/ui_input_result.gen.js +83 -0
- package/out-js/decentraland/sdk/components/ui_input_result.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/ui_text.gen.d.ts +50 -0
- package/out-js/decentraland/sdk/components/ui_text.gen.js +177 -0
- package/out-js/decentraland/sdk/components/ui_text.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/ui_transform.gen.d.ts +238 -0
- package/out-js/decentraland/sdk/components/ui_transform.gen.js +1547 -0
- package/out-js/decentraland/sdk/components/ui_transform.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/video_player.gen.d.ts +51 -0
- package/out-js/decentraland/sdk/components/video_player.gen.js +177 -0
- package/out-js/decentraland/sdk/components/video_player.gen.js.map +1 -0
- package/out-js/decentraland/sdk/components/visibility_component.gen.d.ts +39 -0
- package/out-js/decentraland/sdk/components/visibility_component.gen.js +83 -0
- package/out-js/decentraland/sdk/components/visibility_component.gen.js.map +1 -0
- package/out-js/decentraland/sdk/development/local_development.gen.d.ts +70 -0
- package/out-js/decentraland/sdk/development/local_development.gen.js +283 -0
- package/out-js/decentraland/sdk/development/local_development.gen.js.map +1 -0
- package/out-js/decentraland/sdk/ecs6/components_ecs6.gen.d.ts +1005 -0
- package/out-js/decentraland/sdk/ecs6/components_ecs6.gen.js +7842 -0
- package/out-js/decentraland/sdk/ecs6/components_ecs6.gen.js.map +1 -0
- package/out-js/decentraland/sdk/ecs6/engine_interface_ecs6.gen.d.ts +398 -0
- package/out-js/decentraland/sdk/ecs6/engine_interface_ecs6.gen.js +2512 -0
- package/out-js/decentraland/sdk/ecs6/engine_interface_ecs6.gen.js.map +1 -0
- package/out-js/decentraland/social_service/errors.gen.d.ts +96 -0
- package/out-js/decentraland/social_service/errors.gen.js +405 -0
- package/out-js/decentraland/social_service/errors.gen.js.map +1 -0
- package/out-js/decentraland/social_service/v1/social_service_v1.gen.d.ts +501 -0
- package/out-js/decentraland/social_service/v1/social_service_v1.gen.js +2517 -0
- package/out-js/decentraland/social_service/v1/social_service_v1.gen.js.map +1 -0
- package/out-js/decentraland/social_service/v2/social_service_v2.gen.d.ts +1827 -0
- package/out-js/decentraland/social_service/v2/social_service_v2.gen.js +9308 -0
- package/out-js/decentraland/social_service/v2/social_service_v2.gen.js.map +1 -0
- package/out-js/google/protobuf/descriptor.gen.d.ts +436 -0
- package/out-js/google/protobuf/descriptor.gen.js +3173 -0
- package/out-js/google/protobuf/descriptor.gen.js.map +1 -0
- package/out-js/google/protobuf/empty.gen.d.ts +38 -0
- package/out-js/google/protobuf/empty.gen.js +54 -0
- package/out-js/google/protobuf/empty.gen.js.map +1 -0
- package/out-js/quests.gen.d.ts +1 -0
- package/out-js/quests.gen.js +6 -0
- package/out-js/quests.gen.js.map +1 -0
- package/out-js/sdk-apis.gen.d.ts +1 -0
- package/out-js/sdk-apis.gen.js +6 -0
- package/out-js/sdk-apis.gen.js.map +1 -0
- package/out-js/sdk-components.gen.d.ts +1 -0
- package/out-js/sdk-components.gen.js +6 -0
- package/out-js/sdk-components.gen.js.map +1 -0
- package/out-js/sdk-development.gen.d.ts +1 -0
- package/out-js/sdk-development.gen.js +6 -0
- package/out-js/sdk-development.gen.js.map +1 -0
- package/out-js/social.gen.d.ts +1 -0
- package/out-js/social.gen.js +6 -0
- package/out-js/social.gen.js.map +1 -0
- package/out-ts/about.gen.ts +3 -0
- package/out-ts/comms.gen.ts +3 -0
- package/out-ts/decentraland/common/border_rect.gen.ts +230 -0
- package/out-ts/decentraland/common/colors.gen.ts +293 -0
- package/out-ts/decentraland/common/content_mapping.gen.ts +93 -0
- package/out-ts/decentraland/common/sdk/user_data.gen.ts +370 -0
- package/out-ts/decentraland/common/texture.gen.ts +539 -0
- package/out-ts/decentraland/common/vectors.gen.ts +377 -0
- package/out-ts/decentraland/kernel/apis/comms_api.gen.ts +884 -0
- package/out-ts/decentraland/kernel/apis/communications_controller.gen.ts +434 -0
- package/out-ts/decentraland/kernel/apis/dev_tools.gen.ts +161 -0
- package/out-ts/decentraland/kernel/apis/engine_api.gen.ts +1587 -0
- package/out-ts/decentraland/kernel/apis/environment_api.gen.ts +1264 -0
- package/out-ts/decentraland/kernel/apis/ethereum_controller.gen.ts +982 -0
- package/out-ts/decentraland/kernel/apis/parcel_identity.gen.ts +608 -0
- package/out-ts/decentraland/kernel/apis/permissions.gen.ts +397 -0
- package/out-ts/decentraland/kernel/apis/players.gen.ts +415 -0
- package/out-ts/decentraland/kernel/apis/portable_experiences.gen.ts +668 -0
- package/out-ts/decentraland/kernel/apis/restricted_actions.gen.ts +1150 -0
- package/out-ts/decentraland/kernel/apis/runtime.gen.ts +911 -0
- package/out-ts/decentraland/kernel/apis/scene.gen.ts +192 -0
- package/out-ts/decentraland/kernel/apis/signed_fetch.gen.ts +691 -0
- package/out-ts/decentraland/kernel/apis/social_controller.gen.ts +230 -0
- package/out-ts/decentraland/kernel/apis/testing.gen.ts +1270 -0
- package/out-ts/decentraland/kernel/apis/user_action_module.gen.ts +146 -0
- package/out-ts/decentraland/kernel/apis/user_identity.gen.ts +264 -0
- package/out-ts/decentraland/kernel/comms/rfc4/comms.gen.ts +2389 -0
- package/out-ts/decentraland/kernel/comms/rfc5/ws_comms.gen.ts +1029 -0
- package/out-ts/decentraland/kernel/comms/v3/archipelago.gen.ts +1338 -0
- package/out-ts/decentraland/quests/definitions.gen.ts +3020 -0
- package/out-ts/decentraland/realm/about.gen.ts +1415 -0
- package/out-ts/decentraland/sdk/components/animator.gen.ts +240 -0
- package/out-ts/decentraland/sdk/components/audio_source.gen.ts +209 -0
- package/out-ts/decentraland/sdk/components/audio_stream.gen.ts +182 -0
- package/out-ts/decentraland/sdk/components/avatar_attach.gen.ts +289 -0
- package/out-ts/decentraland/sdk/components/avatar_base.gen.ts +149 -0
- package/out-ts/decentraland/sdk/components/avatar_emote_command.gen.ts +115 -0
- package/out-ts/decentraland/sdk/components/avatar_equipped_data.gen.ts +105 -0
- package/out-ts/decentraland/sdk/components/avatar_modifier_area.gen.ts +188 -0
- package/out-ts/decentraland/sdk/components/avatar_shape.gen.ts +383 -0
- package/out-ts/decentraland/sdk/components/billboard.gen.ts +148 -0
- package/out-ts/decentraland/sdk/components/camera_mode.gen.ts +86 -0
- package/out-ts/decentraland/sdk/components/camera_mode_area.gen.ts +115 -0
- package/out-ts/decentraland/sdk/components/common/camera_type.gen.ts +43 -0
- package/out-ts/decentraland/sdk/components/common/id.gen.ts +3 -0
- package/out-ts/decentraland/sdk/components/common/input_action.gen.ts +206 -0
- package/out-ts/decentraland/sdk/components/common/loading_state.gen.ts +54 -0
- package/out-ts/decentraland/sdk/components/common/raycast_hit.gen.ts +204 -0
- package/out-ts/decentraland/sdk/components/common/texts.gen.ts +117 -0
- package/out-ts/decentraland/sdk/components/engine_info.gen.ts +119 -0
- package/out-ts/decentraland/sdk/components/gltf_container.gen.ts +127 -0
- package/out-ts/decentraland/sdk/components/gltf_container_loading_state.gen.ts +89 -0
- package/out-ts/decentraland/sdk/components/gltf_node_modifiers.gen.ts +204 -0
- package/out-ts/decentraland/sdk/components/material.gen.ts +655 -0
- package/out-ts/decentraland/sdk/components/mesh_collider.gen.ts +536 -0
- package/out-ts/decentraland/sdk/components/mesh_renderer.gen.ts +454 -0
- package/out-ts/decentraland/sdk/components/nft_shape.gen.ts +288 -0
- package/out-ts/decentraland/sdk/components/player_identity_data.gen.ts +102 -0
- package/out-ts/decentraland/sdk/components/pointer_events.gen.ts +415 -0
- package/out-ts/decentraland/sdk/components/pointer_events_result.gen.ts +170 -0
- package/out-ts/decentraland/sdk/components/pointer_lock.gen.ts +85 -0
- package/out-ts/decentraland/sdk/components/raycast.gen.ts +333 -0
- package/out-ts/decentraland/sdk/components/raycast_result.gen.ts +168 -0
- package/out-ts/decentraland/sdk/components/realm_info.gen.ts +183 -0
- package/out-ts/decentraland/sdk/components/text_shape.gen.ts +470 -0
- package/out-ts/decentraland/sdk/components/tween.gen.ts +1336 -0
- package/out-ts/decentraland/sdk/components/tween_sequence.gen.ts +134 -0
- package/out-ts/decentraland/sdk/components/tween_state.gen.ts +136 -0
- package/out-ts/decentraland/sdk/components/ui_background.gen.ts +223 -0
- package/out-ts/decentraland/sdk/components/ui_dropdown.gen.ts +231 -0
- package/out-ts/decentraland/sdk/components/ui_dropdown_result.gen.ts +80 -0
- package/out-ts/decentraland/sdk/components/ui_input.gen.ts +215 -0
- package/out-ts/decentraland/sdk/components/ui_input_result.gen.ts +97 -0
- package/out-ts/decentraland/sdk/components/ui_text.gen.ts +219 -0
- package/out-ts/decentraland/sdk/components/ui_transform.gen.ts +1775 -0
- package/out-ts/decentraland/sdk/components/video_player.gen.ts +231 -0
- package/out-ts/decentraland/sdk/components/visibility_component.gen.ts +108 -0
- package/out-ts/decentraland/sdk/development/local_development.gen.ts +316 -0
- package/out-ts/decentraland/sdk/ecs6/components_ecs6.gen.ts +8957 -0
- package/out-ts/decentraland/sdk/ecs6/engine_interface_ecs6.gen.ts +2886 -0
- package/out-ts/decentraland/social_service/errors.gen.ts +442 -0
- package/out-ts/decentraland/social_service/v1/social_service_v1.gen.ts +2799 -0
- package/out-ts/decentraland/social_service/v2/social_service_v2.gen.ts +10674 -0
- package/out-ts/google/protobuf/descriptor.gen.ts +3470 -0
- package/out-ts/google/protobuf/empty.gen.ts +72 -0
- package/out-ts/quests.gen.ts +3 -0
- package/out-ts/sdk-apis.gen.ts +3 -0
- package/out-ts/sdk-components.gen.ts +3 -0
- package/out-ts/sdk-development.gen.ts +3 -0
- package/out-ts/social.gen.ts +3 -0
- package/package.json +27 -10
- package/proto/decentraland/common/border_rect.proto +18 -0
- package/proto/decentraland/common/colors.proto +21 -0
- package/proto/decentraland/common/content_mapping.proto +7 -0
- package/proto/decentraland/common/entity.proto +13 -0
- package/proto/decentraland/common/floats.proto +8 -0
- package/proto/decentraland/common/options.proto +30 -0
- package/proto/decentraland/common/quantization_example.proto +132 -0
- package/{kernel/apis/UserIdentity.proto → proto/decentraland/common/sdk/user_data.proto} +1 -17
- package/proto/decentraland/common/texture.proto +45 -0
- package/proto/decentraland/common/vectors.proto +26 -0
- package/proto/decentraland/kernel/apis/comms_api.proto +61 -0
- package/proto/decentraland/kernel/apis/communications_controller.proto +29 -0
- package/{kernel/apis/DevTools.proto → proto/decentraland/kernel/apis/dev_tools.proto} +3 -0
- package/proto/decentraland/kernel/apis/engine_api.proto +118 -0
- package/proto/decentraland/kernel/apis/environment_api.proto +76 -0
- package/{kernel/apis/EthereumController.proto → proto/decentraland/kernel/apis/ethereum_controller.proto} +12 -1
- package/{kernel/apis/ParcelIdentity.proto → proto/decentraland/kernel/apis/parcel_identity.proto} +6 -5
- package/proto/decentraland/kernel/apis/permissions.proto +36 -0
- package/proto/decentraland/kernel/apis/players.proto +35 -0
- package/proto/decentraland/kernel/apis/portable_experiences.proto +55 -0
- package/proto/decentraland/kernel/apis/restricted_actions.proto +100 -0
- package/proto/decentraland/kernel/apis/runtime.proto +71 -0
- package/proto/decentraland/kernel/apis/scene.proto +16 -0
- package/{kernel/apis/SignedFetch.proto → proto/decentraland/kernel/apis/signed_fetch.proto} +9 -0
- package/proto/decentraland/kernel/apis/social_controller.proto +19 -0
- package/proto/decentraland/kernel/apis/testing.proto +100 -0
- package/{kernel/apis/UserActionModule.proto → proto/decentraland/kernel/apis/user_action_module.proto} +2 -0
- package/proto/decentraland/kernel/apis/user_identity.proto +22 -0
- package/proto/decentraland/kernel/comms/rfc4/comms.proto +176 -0
- package/proto/decentraland/kernel/comms/rfc5/ws_comms.proto +104 -0
- package/proto/decentraland/kernel/comms/v1/broker.proto +114 -0
- package/proto/decentraland/kernel/comms/v1/comms.proto +68 -0
- package/proto/decentraland/kernel/comms/v2/comms.proto +61 -0
- package/proto/decentraland/kernel/comms/v3/archipelago.proto +86 -0
- package/proto/decentraland/kernel/comms/v3/comms.proto +64 -0
- package/proto/decentraland/pulse/pulse_client.proto +77 -0
- package/proto/decentraland/pulse/pulse_server.proto +138 -0
- package/proto/decentraland/pulse/pulse_shared.proto +48 -0
- package/proto/decentraland/quests/definitions.proto +185 -0
- package/proto/decentraland/realm/about.proto +138 -0
- package/{ecs → proto/decentraland/sdk}/components/README.md +3 -3
- package/proto/decentraland/sdk/components/animator.proto +31 -0
- package/proto/decentraland/sdk/components/asset_load.proto +10 -0
- package/proto/decentraland/sdk/components/asset_load_loading_state.proto +16 -0
- package/proto/decentraland/sdk/components/audio_analysis.proto +44 -0
- package/proto/decentraland/sdk/components/audio_event.proto +12 -0
- package/proto/decentraland/sdk/components/audio_source.proto +31 -0
- package/proto/decentraland/sdk/components/audio_stream.proto +22 -0
- package/proto/decentraland/sdk/components/avatar_attach.proto +51 -0
- package/proto/decentraland/sdk/components/avatar_base.proto +15 -0
- package/proto/decentraland/sdk/components/avatar_emote_command.proto +13 -0
- package/proto/decentraland/sdk/components/avatar_equipped_data.proto +13 -0
- package/proto/decentraland/sdk/components/avatar_locomotion_settings.proto +21 -0
- package/proto/decentraland/sdk/components/avatar_modifier_area.proto +32 -0
- package/proto/decentraland/sdk/components/avatar_shape.proto +49 -0
- package/proto/decentraland/sdk/components/billboard.proto +29 -0
- package/proto/decentraland/sdk/components/camera_mode.proto +12 -0
- package/proto/decentraland/sdk/components/camera_mode_area.proto +25 -0
- package/proto/decentraland/sdk/components/common/camera_transition.proto +11 -0
- package/proto/decentraland/sdk/components/common/camera_type.proto +9 -0
- package/{ecs → proto/decentraland/sdk}/components/common/id.proto +1 -0
- package/proto/decentraland/sdk/components/common/input_action.proto +37 -0
- package/proto/decentraland/sdk/components/common/loading_state.proto +10 -0
- package/proto/decentraland/sdk/components/common/media_state.proto +13 -0
- package/proto/decentraland/sdk/components/common/raycast_hit.proto +16 -0
- package/proto/decentraland/sdk/components/common/texts.proto +21 -0
- package/proto/decentraland/sdk/components/engine_info.proto +15 -0
- package/proto/decentraland/sdk/components/gltf_container.proto +19 -0
- package/proto/decentraland/sdk/components/gltf_container_loading_state.proto +13 -0
- package/proto/decentraland/sdk/components/gltf_node_modifiers.proto +25 -0
- package/proto/decentraland/sdk/components/input_modifier.proto +22 -0
- package/proto/decentraland/sdk/components/light_source.proto +28 -0
- package/proto/decentraland/sdk/components/main_camera.proto +11 -0
- package/proto/decentraland/sdk/components/map_pin.proto +16 -0
- package/proto/decentraland/sdk/components/material.proto +57 -0
- package/proto/decentraland/sdk/components/mesh_collider.proto +62 -0
- package/proto/decentraland/sdk/components/mesh_renderer.proto +43 -0
- package/proto/decentraland/sdk/components/nft_shape.proto +48 -0
- package/proto/decentraland/sdk/components/particle_system.proto +133 -0
- package/proto/decentraland/sdk/components/physics_combined_force.proto +21 -0
- package/proto/decentraland/sdk/components/physics_combined_impulse.proto +23 -0
- package/proto/decentraland/sdk/components/player_identity_data.proto +13 -0
- package/proto/decentraland/sdk/components/pointer_events.proto +64 -0
- package/proto/decentraland/sdk/components/pointer_events_result.proto +19 -0
- package/proto/decentraland/sdk/components/pointer_lock.proto +11 -0
- package/proto/decentraland/sdk/components/primary_pointer_info.proto +39 -0
- package/proto/decentraland/sdk/components/raycast.proto +58 -0
- package/proto/decentraland/sdk/components/raycast_result.proto +21 -0
- package/proto/decentraland/sdk/components/realm_info.proto +15 -0
- package/proto/decentraland/sdk/components/skybox_time.proto +20 -0
- package/proto/decentraland/sdk/components/text_shape.proto +45 -0
- package/proto/decentraland/sdk/components/trigger_area.proto +23 -0
- package/proto/decentraland/sdk/components/trigger_area_result.proto +34 -0
- package/proto/decentraland/sdk/components/tween.proto +117 -0
- package/proto/decentraland/sdk/components/tween_sequence.proto +18 -0
- package/proto/decentraland/sdk/components/tween_state.proto +18 -0
- package/proto/decentraland/sdk/components/ui_background.proto +34 -0
- package/proto/decentraland/sdk/components/ui_canvas_information.proto +30 -0
- package/proto/decentraland/sdk/components/ui_dropdown.proto +22 -0
- package/proto/decentraland/sdk/components/ui_dropdown_result.proto +11 -0
- package/proto/decentraland/sdk/components/ui_input.proto +20 -0
- package/proto/decentraland/sdk/components/ui_input_result.proto +12 -0
- package/proto/decentraland/sdk/components/ui_text.proto +26 -0
- package/proto/decentraland/sdk/components/ui_transform.proto +178 -0
- package/proto/decentraland/sdk/components/video_event.proto +25 -0
- package/proto/decentraland/sdk/components/video_player.proto +24 -0
- package/proto/decentraland/sdk/components/virtual_camera.proto +18 -0
- package/proto/decentraland/sdk/components/visibility_component.proto +16 -0
- package/proto/decentraland/sdk/development/local_development.proto +29 -0
- package/proto/decentraland/sdk/ecs6/components_ecs6.proto +678 -0
- package/proto/decentraland/sdk/ecs6/engine_interface_ecs6.proto +151 -0
- package/proto/decentraland/social_service/errors.proto +30 -0
- package/proto/decentraland/social_service/v1/social_service_v1.proto +163 -0
- package/proto/decentraland/social_service/v2/social_service_v2.proto +721 -0
- package/protoc-gen-bitwise/generator_csharp.py +176 -0
- package/protoc-gen-bitwise/options_pb2.py +171 -0
- package/protoc-gen-bitwise/plugin.py +92 -0
- package/protoc-gen-bitwise/runtime/cs/BitReader.cs +112 -0
- package/protoc-gen-bitwise/runtime/cs/BitWriter.cs +117 -0
- package/protoc-gen-bitwise/runtime/cs/Quantize.cs +35 -0
- package/public/about.proto +5 -0
- package/public/comms.proto +5 -0
- package/public/quests.proto +5 -0
- package/public/sdk-apis.proto +25 -0
- package/public/sdk-components.proto +43 -0
- package/public/sdk-development.proto +5 -0
- package/public/social.proto +6 -0
- package/ecs/components/Animator.proto +0 -18
- package/ecs/components/AudioSource.proto +0 -12
- package/ecs/components/AudioStream.proto +0 -10
- package/ecs/components/AvatarAttach.proto +0 -16
- package/ecs/components/AvatarModifierArea.proto +0 -16
- package/ecs/components/AvatarShape.proto +0 -20
- package/ecs/components/Billboard.proto +0 -10
- package/ecs/components/BoxShape.proto +0 -11
- package/ecs/components/CameraModeArea.proto +0 -15
- package/ecs/components/CylinderShape.proto +0 -12
- package/ecs/components/GLTFShape.proto +0 -11
- package/ecs/components/NFTShape.proto +0 -16
- package/ecs/components/OnPointerDown.proto +0 -12
- package/ecs/components/OnPointerDownResult.proto +0 -17
- package/ecs/components/OnPointerUp.proto +0 -12
- package/ecs/components/OnPointerUpResult.proto +0 -17
- package/ecs/components/PlaneShape.proto +0 -11
- package/ecs/components/SphereShape.proto +0 -10
- package/ecs/components/TextShape.proto +0 -33
- package/ecs/components/UiTransform.proto +0 -159
- package/ecs/components/common/ActionButton.proto +0 -18
- package/ecs/components/common/Color3.proto +0 -8
- package/ecs/components/common/Vector3.proto +0 -7
- package/kernel/apis/CommunicationsController.proto +0 -11
- package/kernel/apis/EngineAPI.proto +0 -180
- package/kernel/apis/EnvironmentAPI.proto +0 -70
- package/kernel/apis/ExperimentalAPI.proto +0 -16
- package/kernel/apis/Permissions.proto +0 -30
- package/kernel/apis/Players.proto +0 -28
- package/kernel/apis/PortableExperiences.proto +0 -40
- package/kernel/apis/RestrictedActions.proto +0 -25
- package/kernel/apis/SceneStateStorageController.proto +0 -114
- package/kernel/apis/SocialController.proto +0 -15
- package/kernel/comms/v1/broker.proto +0 -114
- package/kernel/comms/v1/comms.proto +0 -68
- package/kernel/comms/v2/comms.proto +0 -59
- package/renderer-protocol/RendererProtocol.proto +0 -24
- /package/{ecs → proto/decentraland/sdk}/components/Transform.md +0 -0
- /package/{ecs → proto/decentraland/sdk}/components/common/id.md +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""
|
|
2
|
+
C# code generator for the protoc-gen-bitwise plugin.
|
|
3
|
+
|
|
4
|
+
For every proto message that contains at least one uint32 field annotated with
|
|
5
|
+
[(quantized)], this module emits a C# partial class that adds a computed float
|
|
6
|
+
property named {FieldName}Quantized. The getter decodes the stored uint32 to
|
|
7
|
+
a float; the setter encodes a float back to a uint32. Standard protobuf
|
|
8
|
+
handles serialization of the uint32 wire field; this class adds a typed float
|
|
9
|
+
accessor on top.
|
|
10
|
+
|
|
11
|
+
Protobuf encodes small uint32 values via varint, so a value that fits in
|
|
12
|
+
2^20 costs 3 bytes on the wire — cheaper than a raw IEEE 754 float (4 bytes).
|
|
13
|
+
|
|
14
|
+
Only uint32 fields are supported. bit_packed and unannotated fields are
|
|
15
|
+
passed through without generating any accessor.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from google.protobuf import descriptor_pb2
|
|
19
|
+
|
|
20
|
+
from options_pb2 import get_field_options
|
|
21
|
+
|
|
22
|
+
# FieldDescriptorProto type constants (aliased for readability)
|
|
23
|
+
_FT = descriptor_pb2.FieldDescriptorProto
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
27
|
+
# Helpers
|
|
28
|
+
# ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
def _snake_to_pascal(name: str) -> str:
|
|
31
|
+
"""position_x → PositionX"""
|
|
32
|
+
return ''.join(word.capitalize() for word in name.split('_'))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _package_to_namespace(package: str) -> str:
|
|
36
|
+
"""decentraland.kernel.comms.v3 → Decentraland.Kernel.Comms.V3"""
|
|
37
|
+
if not package:
|
|
38
|
+
return 'Generated'
|
|
39
|
+
return '.'.join(part.capitalize() for part in package.split('.'))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _format_float(value: float) -> str:
|
|
43
|
+
"""Format a Python float as a C# float literal (e.g. -100.0f)."""
|
|
44
|
+
text = f'{value:.8g}'
|
|
45
|
+
if '.' not in text and 'e' not in text and 'E' not in text:
|
|
46
|
+
text += '.0'
|
|
47
|
+
return text + 'f'
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _format_step(step: float) -> str:
|
|
51
|
+
"""Format a quantization step size for display in a doc comment (e.g. ≈ 0.003)."""
|
|
52
|
+
return f'\u2248 {step:.6g}'
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# ---------------------------------------------------------------------------
|
|
56
|
+
# Per-message code generation
|
|
57
|
+
# ---------------------------------------------------------------------------
|
|
58
|
+
|
|
59
|
+
def _gen_message(msg_proto, indent: str = ' ') -> list[str] | None:
|
|
60
|
+
"""
|
|
61
|
+
Generate a C# partial class for a proto message.
|
|
62
|
+
|
|
63
|
+
For each uint32 field with a [(quantized)] annotation, emits a cached float
|
|
64
|
+
property {FieldName}Quantized backed by the raw uint32 field.
|
|
65
|
+
|
|
66
|
+
Returns a list of lines (without trailing newline) or None if the message
|
|
67
|
+
has no quantized uint32 fields.
|
|
68
|
+
"""
|
|
69
|
+
props: list[tuple[str, str, str, int, float]] = [] # (prop_name, mn, mx, bits, step)
|
|
70
|
+
|
|
71
|
+
for field in msg_proto.field:
|
|
72
|
+
# Repeated/map fields are not supported
|
|
73
|
+
if field.label == _FT.LABEL_REPEATED:
|
|
74
|
+
continue
|
|
75
|
+
|
|
76
|
+
# Only uint32 fields are candidates for quantized accessors
|
|
77
|
+
if field.type != _FT.TYPE_UINT32:
|
|
78
|
+
continue
|
|
79
|
+
|
|
80
|
+
quantized, _ = get_field_options(field.options)
|
|
81
|
+
if quantized is None:
|
|
82
|
+
continue
|
|
83
|
+
|
|
84
|
+
step = (quantized.max - quantized.min) / ((1 << quantized.bits) - 1)
|
|
85
|
+
|
|
86
|
+
props.append((
|
|
87
|
+
_snake_to_pascal(field.name),
|
|
88
|
+
_format_float(quantized.min),
|
|
89
|
+
_format_float(quantized.max),
|
|
90
|
+
quantized.bits,
|
|
91
|
+
step,
|
|
92
|
+
))
|
|
93
|
+
|
|
94
|
+
if not props:
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
i = indent
|
|
98
|
+
backings: list[str] = []
|
|
99
|
+
lines: list[str] = []
|
|
100
|
+
lines.append(f'public partial class {msg_proto.name}')
|
|
101
|
+
lines.append('{')
|
|
102
|
+
|
|
103
|
+
for prop_name, mn, mx, bits, step in props:
|
|
104
|
+
backing = '_' + prop_name[0].lower() + prop_name[1:]
|
|
105
|
+
backings.append(backing)
|
|
106
|
+
lines.append(f'{i}private float? {backing};')
|
|
107
|
+
lines.append(f'{i}/// <summary>Float accessor for <see cref="{prop_name}"/>. Range [{mn}, {mx}], {bits} bits, step {_format_step(step)}.</summary>')
|
|
108
|
+
lines.append(f'{i}public float {prop_name}Quantized')
|
|
109
|
+
lines.append(f'{i}{{')
|
|
110
|
+
lines.append(f'{i}{i}get => {backing} ??= Quantize.Decode({prop_name}, {mn}, {mx}, {bits});')
|
|
111
|
+
lines.append(f'{i}{i}set {{ {backing} = value; {prop_name} = Quantize.Encode(value, {mn}, {mx}, {bits}); }}')
|
|
112
|
+
lines.append(f'{i}}}')
|
|
113
|
+
lines.append('')
|
|
114
|
+
|
|
115
|
+
lines.append(f'{i}/// <summary>Clears all cached decoded values. Call after mutating raw uint32 fields directly.</summary>')
|
|
116
|
+
lines.append(f'{i}public void ResetDecodedCache()')
|
|
117
|
+
lines.append(f'{i}{{')
|
|
118
|
+
for backing in backings:
|
|
119
|
+
lines.append(f'{i}{i}{backing} = null;')
|
|
120
|
+
lines.append(f'{i}}}')
|
|
121
|
+
|
|
122
|
+
lines.append('}')
|
|
123
|
+
return lines
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# ---------------------------------------------------------------------------
|
|
127
|
+
# Per-file code generation (public entry point)
|
|
128
|
+
# ---------------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
def generate_csharp(file_proto) -> dict | None:
|
|
131
|
+
"""
|
|
132
|
+
Generate a C# source file for a FileDescriptorProto.
|
|
133
|
+
|
|
134
|
+
Returns a dict with keys 'name' (output path) and 'content' (C# source),
|
|
135
|
+
or None if the file contains no quantized uint32 fields.
|
|
136
|
+
"""
|
|
137
|
+
namespace = _package_to_namespace(file_proto.package)
|
|
138
|
+
|
|
139
|
+
# Output is placed flat in the output root, matching --csharp_out convention.
|
|
140
|
+
# e.g. "decentraland/kernel/comms/v3/my_message.proto"
|
|
141
|
+
# → "MyMessage.Bitwise.cs"
|
|
142
|
+
proto_file = file_proto.name.rsplit('/', 1)[-1]
|
|
143
|
+
stem = _snake_to_pascal(proto_file.replace('.proto', ''))
|
|
144
|
+
out_name = f'{stem}.Bitwise.cs'
|
|
145
|
+
|
|
146
|
+
header = [
|
|
147
|
+
'// <auto-generated>',
|
|
148
|
+
'// Generated by protoc-gen-bitwise. DO NOT EDIT.',
|
|
149
|
+
f'// Source: {file_proto.name}',
|
|
150
|
+
'// </auto-generated>',
|
|
151
|
+
'',
|
|
152
|
+
'using Decentraland.Networking.Bitwise;',
|
|
153
|
+
'',
|
|
154
|
+
f'namespace {namespace}',
|
|
155
|
+
'{',
|
|
156
|
+
]
|
|
157
|
+
footer = [
|
|
158
|
+
'',
|
|
159
|
+
f'}} // namespace {namespace}',
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
body: list[str] = []
|
|
163
|
+
for msg in file_proto.message_type:
|
|
164
|
+
msg_lines = _gen_message(msg)
|
|
165
|
+
if msg_lines is None:
|
|
166
|
+
continue
|
|
167
|
+
# Indent each line by 4 spaces (inside the namespace block)
|
|
168
|
+
for line in msg_lines:
|
|
169
|
+
body.append((' ' + line) if line else '')
|
|
170
|
+
body.append('')
|
|
171
|
+
|
|
172
|
+
if not body:
|
|
173
|
+
return None # nothing to emit
|
|
174
|
+
|
|
175
|
+
content = '\n'.join(header + body + footer) + '\n'
|
|
176
|
+
return {'name': out_name, 'content': content}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Manual parser for the custom bitwise field options defined in options.proto.
|
|
3
|
+
|
|
4
|
+
Rather than relying on protobuf extension registration (which requires a properly
|
|
5
|
+
compiled _pb2 module), this module parses the raw serialized FieldOptions bytes
|
|
6
|
+
directly using the protobuf binary wire format. All protobuf runtimes preserve
|
|
7
|
+
unknown/unregistered extension bytes when round-tripping, so
|
|
8
|
+
field.options.SerializeToString() always contains the extension data even when
|
|
9
|
+
the extension is not registered in the Python runtime.
|
|
10
|
+
|
|
11
|
+
Wire format reference:
|
|
12
|
+
tag = (field_number << 3) | wire_type
|
|
13
|
+
wire_type 0 = varint, 1 = 64-bit, 2 = length-delimited, 5 = 32-bit
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import struct
|
|
17
|
+
|
|
18
|
+
# Extension field numbers as defined in options.proto
|
|
19
|
+
QUANTIZED_FIELD_NUMBER = 50001
|
|
20
|
+
BIT_PACKED_FIELD_NUMBER = 50002
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# ---------------------------------------------------------------------------
|
|
24
|
+
# Low-level wire-format helpers
|
|
25
|
+
# ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
def _read_varint(data: bytes, pos: int):
|
|
28
|
+
"""Decode a protobuf varint starting at *pos*. Returns (value, new_pos)."""
|
|
29
|
+
result = 0
|
|
30
|
+
shift = 0
|
|
31
|
+
while pos < len(data):
|
|
32
|
+
byte = data[pos]
|
|
33
|
+
pos += 1
|
|
34
|
+
result |= (byte & 0x7F) << shift
|
|
35
|
+
if not (byte & 0x80):
|
|
36
|
+
break
|
|
37
|
+
shift += 7
|
|
38
|
+
return result, pos
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _read_float32(data: bytes, pos: int):
|
|
42
|
+
"""Decode a little-endian 32-bit float. Returns (value, new_pos)."""
|
|
43
|
+
value, = struct.unpack_from('<f', data, pos)
|
|
44
|
+
return value, pos + 4
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _skip_field(data: bytes, pos: int, wire_type: int) -> int:
|
|
48
|
+
"""Advance *pos* past a field with the given wire_type."""
|
|
49
|
+
if wire_type == 0:
|
|
50
|
+
_, pos = _read_varint(data, pos)
|
|
51
|
+
elif wire_type == 1:
|
|
52
|
+
pos += 8
|
|
53
|
+
elif wire_type == 2:
|
|
54
|
+
length, pos = _read_varint(data, pos)
|
|
55
|
+
pos += length
|
|
56
|
+
elif wire_type == 5:
|
|
57
|
+
pos += 4
|
|
58
|
+
# wire types 3 and 4 (start/end group) are deprecated; skip gracefully
|
|
59
|
+
return pos
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# ---------------------------------------------------------------------------
|
|
63
|
+
# Option message classes
|
|
64
|
+
# ---------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
class QuantizedFloatOptions:
|
|
67
|
+
"""Mirrors the QuantizedFloatOptions proto message."""
|
|
68
|
+
|
|
69
|
+
__slots__ = ('min', 'max', 'bits')
|
|
70
|
+
|
|
71
|
+
def __init__(self, min_val: float = 0.0, max_val: float = 0.0, bits: int = 0):
|
|
72
|
+
self.min = min_val
|
|
73
|
+
self.max = max_val
|
|
74
|
+
self.bits = bits
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
def from_bytes(cls, data: bytes) -> 'QuantizedFloatOptions':
|
|
78
|
+
obj = cls()
|
|
79
|
+
pos = 0
|
|
80
|
+
while pos < len(data):
|
|
81
|
+
tag, pos = _read_varint(data, pos)
|
|
82
|
+
field_num = tag >> 3
|
|
83
|
+
wire_type = tag & 0x7
|
|
84
|
+
if field_num == 1 and wire_type == 5: # min (float)
|
|
85
|
+
obj.min, pos = _read_float32(data, pos)
|
|
86
|
+
elif field_num == 2 and wire_type == 5: # max (float)
|
|
87
|
+
obj.max, pos = _read_float32(data, pos)
|
|
88
|
+
elif field_num == 3 and wire_type == 0: # bits (uint32)
|
|
89
|
+
obj.bits, pos = _read_varint(data, pos)
|
|
90
|
+
else:
|
|
91
|
+
pos = _skip_field(data, pos, wire_type)
|
|
92
|
+
return obj
|
|
93
|
+
|
|
94
|
+
def __repr__(self):
|
|
95
|
+
return f'QuantizedFloatOptions(min={self.min}, max={self.max}, bits={self.bits})'
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class BitPackedOptions:
|
|
99
|
+
"""Mirrors the BitPackedOptions proto message."""
|
|
100
|
+
|
|
101
|
+
__slots__ = ('bits',)
|
|
102
|
+
|
|
103
|
+
def __init__(self, bits: int = 0):
|
|
104
|
+
self.bits = bits
|
|
105
|
+
|
|
106
|
+
@classmethod
|
|
107
|
+
def from_bytes(cls, data: bytes) -> 'BitPackedOptions':
|
|
108
|
+
obj = cls()
|
|
109
|
+
pos = 0
|
|
110
|
+
while pos < len(data):
|
|
111
|
+
tag, pos = _read_varint(data, pos)
|
|
112
|
+
field_num = tag >> 3
|
|
113
|
+
wire_type = tag & 0x7
|
|
114
|
+
if field_num == 1 and wire_type == 0: # bits (uint32)
|
|
115
|
+
obj.bits, pos = _read_varint(data, pos)
|
|
116
|
+
else:
|
|
117
|
+
pos = _skip_field(data, pos, wire_type)
|
|
118
|
+
return obj
|
|
119
|
+
|
|
120
|
+
def __repr__(self):
|
|
121
|
+
return f'BitPackedOptions(bits={self.bits})'
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# ---------------------------------------------------------------------------
|
|
125
|
+
# Public API
|
|
126
|
+
# ---------------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
def get_field_options(field_options_proto):
|
|
129
|
+
"""
|
|
130
|
+
Extract custom bitwise options from a FieldDescriptorProto.options object.
|
|
131
|
+
|
|
132
|
+
Serialises the options message to bytes and walks the wire-format stream
|
|
133
|
+
looking for extension fields 50001 (quantized) and 50002 (bit_packed).
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
field_options_proto: google.protobuf.descriptor_pb2.FieldOptions instance
|
|
137
|
+
(may be a default/empty instance when no options are set).
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
tuple[QuantizedFloatOptions | None, BitPackedOptions | None]
|
|
141
|
+
"""
|
|
142
|
+
try:
|
|
143
|
+
raw = field_options_proto.SerializeToString()
|
|
144
|
+
except Exception:
|
|
145
|
+
return None, None
|
|
146
|
+
|
|
147
|
+
if not raw:
|
|
148
|
+
return None, None
|
|
149
|
+
|
|
150
|
+
quantized = None
|
|
151
|
+
bit_packed = None
|
|
152
|
+
pos = 0
|
|
153
|
+
|
|
154
|
+
while pos < len(raw):
|
|
155
|
+
tag, pos = _read_varint(raw, pos)
|
|
156
|
+
field_num = tag >> 3
|
|
157
|
+
wire_type = tag & 0x7
|
|
158
|
+
|
|
159
|
+
if wire_type == 2: # length-delimited
|
|
160
|
+
length, pos = _read_varint(raw, pos)
|
|
161
|
+
value_bytes = raw[pos:pos + length]
|
|
162
|
+
pos += length
|
|
163
|
+
if field_num == QUANTIZED_FIELD_NUMBER:
|
|
164
|
+
quantized = QuantizedFloatOptions.from_bytes(value_bytes)
|
|
165
|
+
elif field_num == BIT_PACKED_FIELD_NUMBER:
|
|
166
|
+
bit_packed = BitPackedOptions.from_bytes(value_bytes)
|
|
167
|
+
# else: unknown length-delimited field — already consumed
|
|
168
|
+
else:
|
|
169
|
+
pos = _skip_field(raw, pos, wire_type)
|
|
170
|
+
|
|
171
|
+
return quantized, bit_packed
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
protoc-gen-bitwise — protoc plugin that generates C# bitwise serialization code.
|
|
4
|
+
|
|
5
|
+
Protocol:
|
|
6
|
+
1. protoc writes a serialised CodeGeneratorRequest to this process's stdin.
|
|
7
|
+
2. This plugin reads it, generates C# partial classes with Encode / Decode
|
|
8
|
+
methods for every message that carries [(quantized)] or [(bit_packed)]
|
|
9
|
+
field annotations.
|
|
10
|
+
3. A serialised CodeGeneratorResponse is written to stdout.
|
|
11
|
+
|
|
12
|
+
Usage (from project root):
|
|
13
|
+
protoc \\
|
|
14
|
+
--proto_path=proto \\
|
|
15
|
+
--bitwise_out=generated/ \\
|
|
16
|
+
--plugin=protoc-gen-bitwise \\
|
|
17
|
+
proto/my_messages.proto
|
|
18
|
+
|
|
19
|
+
Windows invocation (plugin not on PATH as executable):
|
|
20
|
+
protoc \\
|
|
21
|
+
--proto_path=proto \\
|
|
22
|
+
--bitwise_out=generated/ \\
|
|
23
|
+
--plugin=protoc-gen-bitwise=python protoc-gen-bitwise/plugin.py \\
|
|
24
|
+
proto/my_messages.proto
|
|
25
|
+
|
|
26
|
+
Dependencies:
|
|
27
|
+
pip install grpcio-tools # or: pip install protobuf
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
import os
|
|
31
|
+
import sys
|
|
32
|
+
|
|
33
|
+
# Ensure sibling modules (generator_csharp, options_pb2) are importable
|
|
34
|
+
# regardless of where protoc invokes this script from.
|
|
35
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
36
|
+
|
|
37
|
+
# On Windows, stdin/stdout are opened in text mode by default which corrupts
|
|
38
|
+
# the binary protobuf payload.
|
|
39
|
+
if sys.platform == 'win32':
|
|
40
|
+
import msvcrt
|
|
41
|
+
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
|
|
42
|
+
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
|
43
|
+
|
|
44
|
+
from google.protobuf.compiler import plugin_pb2
|
|
45
|
+
|
|
46
|
+
from generator_csharp import generate_csharp
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def main() -> None:
|
|
50
|
+
request_bytes = sys.stdin.buffer.read()
|
|
51
|
+
|
|
52
|
+
request = plugin_pb2.CodeGeneratorRequest()
|
|
53
|
+
request.ParseFromString(request_bytes)
|
|
54
|
+
|
|
55
|
+
response = plugin_pb2.CodeGeneratorResponse()
|
|
56
|
+
# Advertise proto3-optional support so protoc does not reject the plugin.
|
|
57
|
+
response.supported_features = (
|
|
58
|
+
plugin_pb2.CodeGeneratorResponse.FEATURE_PROTO3_OPTIONAL
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Build a lookup map for all file descriptors (needed for imports, though
|
|
62
|
+
# the current generator only uses the directly requested files).
|
|
63
|
+
file_by_name = {f.name: f for f in request.proto_file}
|
|
64
|
+
|
|
65
|
+
for file_name in request.file_to_generate:
|
|
66
|
+
# Skip the options definition file itself — it has no messages to generate.
|
|
67
|
+
if file_name == 'decentraland/common/options.proto':
|
|
68
|
+
continue
|
|
69
|
+
|
|
70
|
+
file_proto = file_by_name.get(file_name)
|
|
71
|
+
if file_proto is None:
|
|
72
|
+
continue
|
|
73
|
+
|
|
74
|
+
try:
|
|
75
|
+
generated = generate_csharp(file_proto)
|
|
76
|
+
except Exception as exc: # noqa: BLE001
|
|
77
|
+
error = response.file.add()
|
|
78
|
+
error.name = '' # empty name signals an error to protoc
|
|
79
|
+
# Append error text; protoc will print it and fail.
|
|
80
|
+
response.error = f'protoc-gen-bitwise: error processing {file_name}: {exc}'
|
|
81
|
+
continue
|
|
82
|
+
|
|
83
|
+
if generated is not None:
|
|
84
|
+
out = response.file.add()
|
|
85
|
+
out.name = generated['name']
|
|
86
|
+
out.content = generated['content']
|
|
87
|
+
|
|
88
|
+
sys.stdout.buffer.write(response.SerializeToString())
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == '__main__':
|
|
92
|
+
main()
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Decentraland.Networking.Bitwise — BitReader
|
|
2
|
+
// Copy this file into your Unity project alongside generated *.Bitwise.cs files.
|
|
3
|
+
|
|
4
|
+
using System;
|
|
5
|
+
|
|
6
|
+
namespace Decentraland.Networking.Bitwise
|
|
7
|
+
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// Reads bits from a byte buffer, MSB first within each byte (big-endian bit
|
|
10
|
+
/// order). Symmetric counterpart of <see cref="BitWriter"/>: every
|
|
11
|
+
/// Write… call has a corresponding Read… call with identical arguments that
|
|
12
|
+
/// reproduces the original value.
|
|
13
|
+
/// </summary>
|
|
14
|
+
public sealed class BitReader
|
|
15
|
+
{
|
|
16
|
+
private readonly byte[] _buffer;
|
|
17
|
+
private int _bitPos;
|
|
18
|
+
|
|
19
|
+
/// <param name="buffer">Source buffer filled by a <see cref="BitWriter"/>.</param>
|
|
20
|
+
public BitReader(byte[] buffer)
|
|
21
|
+
{
|
|
22
|
+
_buffer = buffer ?? throw new ArgumentNullException(nameof(buffer));
|
|
23
|
+
_bitPos = 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// <summary>Current read position in bits.</summary>
|
|
27
|
+
public int BitPosition => _bitPos;
|
|
28
|
+
|
|
29
|
+
/// <summary>
|
|
30
|
+
/// Returns <c>true</c> when all written bits have been consumed
|
|
31
|
+
/// (i.e. <see cref="BitPosition"/> has reached the end of the buffer).
|
|
32
|
+
/// </summary>
|
|
33
|
+
public bool IsAtEnd => _bitPos >= _buffer.Length * 8;
|
|
34
|
+
|
|
35
|
+
// -----------------------------------------------------------------
|
|
36
|
+
// Core primitive
|
|
37
|
+
// -----------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
/// <summary>
|
|
40
|
+
/// Reads <paramref name="bits"/> bits and returns them as the
|
|
41
|
+
/// least-significant bits of a <see cref="uint"/>, MSB first.
|
|
42
|
+
/// </summary>
|
|
43
|
+
public uint ReadBits(int bits)
|
|
44
|
+
{
|
|
45
|
+
uint value = 0;
|
|
46
|
+
for (int i = bits - 1; i >= 0; i--)
|
|
47
|
+
{
|
|
48
|
+
int byteIdx = _bitPos / 8;
|
|
49
|
+
int bitIdx = 7 - (_bitPos % 8);
|
|
50
|
+
|
|
51
|
+
if ((_buffer[byteIdx] >> bitIdx & 1) == 1)
|
|
52
|
+
value |= 1u << i;
|
|
53
|
+
|
|
54
|
+
_bitPos++;
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// -----------------------------------------------------------------
|
|
60
|
+
// Quantized float
|
|
61
|
+
// -----------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
/// <summary>
|
|
64
|
+
/// Reads a quantized float encoded with <see cref="BitWriter.WriteQuantizedFloat"/>.
|
|
65
|
+
/// Arguments must match those used during encoding exactly.
|
|
66
|
+
/// </summary>
|
|
67
|
+
public float ReadQuantizedFloat(float min, float max, int bits)
|
|
68
|
+
{
|
|
69
|
+
uint maxQ = (1u << bits) - 1;
|
|
70
|
+
uint quantized = ReadBits(bits);
|
|
71
|
+
float normalized = (float)quantized / maxQ;
|
|
72
|
+
return min + normalized * (max - min);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// -----------------------------------------------------------------
|
|
76
|
+
// Standard IEEE 754 helpers
|
|
77
|
+
// -----------------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
/// <summary>Reads a 32-bit IEEE 754 float written by <see cref="BitWriter.WriteFloat"/>.</summary>
|
|
80
|
+
public float ReadFloat()
|
|
81
|
+
{
|
|
82
|
+
uint bits = ReadBits(32);
|
|
83
|
+
byte[] bytes =
|
|
84
|
+
{
|
|
85
|
+
(byte)(bits & 0xFF),
|
|
86
|
+
(byte)((bits >> 8) & 0xFF),
|
|
87
|
+
(byte)((bits >> 16) & 0xFF),
|
|
88
|
+
(byte)((bits >> 24) & 0xFF),
|
|
89
|
+
};
|
|
90
|
+
return BitConverter.ToSingle(bytes, 0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// <summary>Reads a 64-bit IEEE 754 double written by <see cref="BitWriter.WriteDouble"/>.</summary>
|
|
94
|
+
public double ReadDouble()
|
|
95
|
+
{
|
|
96
|
+
uint hi = ReadBits(32);
|
|
97
|
+
uint lo = ReadBits(32);
|
|
98
|
+
byte[] bytes =
|
|
99
|
+
{
|
|
100
|
+
(byte)(lo & 0xFF),
|
|
101
|
+
(byte)((lo >> 8) & 0xFF),
|
|
102
|
+
(byte)((lo >> 16) & 0xFF),
|
|
103
|
+
(byte)((lo >> 24) & 0xFF),
|
|
104
|
+
(byte)(hi & 0xFF),
|
|
105
|
+
(byte)((hi >> 8) & 0xFF),
|
|
106
|
+
(byte)((hi >> 16) & 0xFF),
|
|
107
|
+
(byte)((hi >> 24) & 0xFF),
|
|
108
|
+
};
|
|
109
|
+
return BitConverter.ToDouble(bytes, 0);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Decentraland.Networking.Bitwise — BitWriter
|
|
2
|
+
// Copy this file into your Unity project alongside generated *.Bitwise.cs files.
|
|
3
|
+
|
|
4
|
+
using System;
|
|
5
|
+
|
|
6
|
+
namespace Decentraland.Networking.Bitwise
|
|
7
|
+
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// Writes bits into a pre-allocated byte buffer, MSB first within each byte
|
|
10
|
+
/// (big-endian bit order). This matches the layout expected by
|
|
11
|
+
/// <see cref="BitReader"/> so that encode → decode is always a round-trip no-op.
|
|
12
|
+
/// </summary>
|
|
13
|
+
public sealed class BitWriter
|
|
14
|
+
{
|
|
15
|
+
private readonly byte[] _buffer;
|
|
16
|
+
private int _bitPos;
|
|
17
|
+
|
|
18
|
+
/// <param name="buffer">Destination buffer (must be large enough for all writes).</param>
|
|
19
|
+
public BitWriter(byte[] buffer)
|
|
20
|
+
{
|
|
21
|
+
_buffer = buffer ?? throw new ArgumentNullException(nameof(buffer));
|
|
22
|
+
_bitPos = 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// <summary>Current write position in bits.</summary>
|
|
26
|
+
public int BitPosition => _bitPos;
|
|
27
|
+
|
|
28
|
+
/// <summary>Number of bytes written (rounded up to the nearest byte).</summary>
|
|
29
|
+
public int ByteLength => (_bitPos + 7) / 8;
|
|
30
|
+
|
|
31
|
+
/// <summary>Returns a copy of the written bytes (trimmed to <see cref="ByteLength"/>).</summary>
|
|
32
|
+
public byte[] ToArray()
|
|
33
|
+
{
|
|
34
|
+
var result = new byte[ByteLength];
|
|
35
|
+
Array.Copy(_buffer, result, ByteLength);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// -----------------------------------------------------------------
|
|
40
|
+
// Core primitive
|
|
41
|
+
// -----------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
/// <summary>
|
|
44
|
+
/// Writes the <paramref name="bits"/> least-significant bits of
|
|
45
|
+
/// <paramref name="value"/>, MSB first.
|
|
46
|
+
/// </summary>
|
|
47
|
+
public void WriteBits(uint value, int bits)
|
|
48
|
+
{
|
|
49
|
+
for (int i = bits - 1; i >= 0; i--)
|
|
50
|
+
{
|
|
51
|
+
int byteIdx = _bitPos / 8;
|
|
52
|
+
int bitIdx = 7 - (_bitPos % 8);
|
|
53
|
+
|
|
54
|
+
if ((value >> i & 1u) == 1u)
|
|
55
|
+
_buffer[byteIdx] |= (byte)(1 << bitIdx);
|
|
56
|
+
else
|
|
57
|
+
_buffer[byteIdx] &= (byte)~(1 << bitIdx);
|
|
58
|
+
|
|
59
|
+
_bitPos++;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// -----------------------------------------------------------------
|
|
64
|
+
// Quantized float
|
|
65
|
+
// -----------------------------------------------------------------
|
|
66
|
+
|
|
67
|
+
/// <summary>
|
|
68
|
+
/// Quantizes <paramref name="value"/> into <paramref name="bits"/> bits
|
|
69
|
+
/// using the range [<paramref name="min"/>, <paramref name="max"/>] and
|
|
70
|
+
/// writes it to the buffer.
|
|
71
|
+
///
|
|
72
|
+
/// Uses <c>Math.Round</c> (banker's rounding → ties-to-even) to guarantee
|
|
73
|
+
/// that encode → decode is a round-trip no-op.
|
|
74
|
+
/// </summary>
|
|
75
|
+
public void WriteQuantizedFloat(float value, float min, float max, int bits)
|
|
76
|
+
{
|
|
77
|
+
uint maxQ = (1u << bits) - 1;
|
|
78
|
+
float clamped = Math.Clamp(value, min, max);
|
|
79
|
+
float normalized = (clamped - min) / (max - min);
|
|
80
|
+
uint quantized = (uint)Math.Round(normalized * maxQ);
|
|
81
|
+
WriteBits(quantized, bits);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// -----------------------------------------------------------------
|
|
85
|
+
// Standard IEEE 754 helpers (used for un-annotated float/double fields)
|
|
86
|
+
// -----------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
/// <summary>Writes a 32-bit IEEE 754 float (4 bytes).</summary>
|
|
89
|
+
public void WriteFloat(float value)
|
|
90
|
+
{
|
|
91
|
+
byte[] bytes = BitConverter.GetBytes(value);
|
|
92
|
+
// GetBytes is little-endian on all platforms; write MSB first.
|
|
93
|
+
uint bits = (uint)bytes[0]
|
|
94
|
+
| ((uint)bytes[1] << 8)
|
|
95
|
+
| ((uint)bytes[2] << 16)
|
|
96
|
+
| ((uint)bytes[3] << 24);
|
|
97
|
+
WriteBits(bits, 32);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// <summary>Writes a 64-bit IEEE 754 double (8 bytes).</summary>
|
|
101
|
+
public void WriteDouble(double value)
|
|
102
|
+
{
|
|
103
|
+
byte[] bytes = BitConverter.GetBytes(value);
|
|
104
|
+
uint lo = (uint)bytes[0]
|
|
105
|
+
| ((uint)bytes[1] << 8)
|
|
106
|
+
| ((uint)bytes[2] << 16)
|
|
107
|
+
| ((uint)bytes[3] << 24);
|
|
108
|
+
uint hi = (uint)bytes[4]
|
|
109
|
+
| ((uint)bytes[5] << 8)
|
|
110
|
+
| ((uint)bytes[6] << 16)
|
|
111
|
+
| ((uint)bytes[7] << 24);
|
|
112
|
+
// Write high 32 bits first so the bit stream is big-endian at word level too.
|
|
113
|
+
WriteBits(hi, 32);
|
|
114
|
+
WriteBits(lo, 32);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|