Insality
Insality/defold-proto/proto
Protocol-buffer style message encoding for compact Defold network payloads.
- GitHub: Insality/defold-proto — pinned to
1- This repo publishes no stable release. Pick a tag from Insality/defold-proto tags and add its Source code (zip) URL — for the pinned tag,
https://github.com/Insality/defold-proto/archive/refs/tags/1.zip— togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as proto from "proto"
- This repo publishes no stable release. Pick a tag from Insality/defold-proto tags and add its Source code (zip) URL — for the pinned tag,
Functions
init(proto_config_or_path: LuaTable | string)set_logger(logger_instance?:proto_logger| undefined)get(proto_type: string): LuaTableencode(proto_type: string, data: LuaTable): stringdecode(proto_type: string, bytes?: string | undefined): LuaTableverify(proto_type: string, data: LuaTable): LuaTableupdate_with_default_messages(proto_type: string, data: LuaTable)
init(proto_config_or_path: LuaTable | string)
Loads proto files from the specified paths in the game.project Under the "proto.proto_paths" key in the game.project
Parameters
proto_config_or_path:LuaTable | string— Lua table or path to proto list config. Example: "/resources/proto.json"
set_logger(logger_instance?: proto_logger | undefined)
Set the logger instance
Parameters
logger_instance?:proto_logger | undefined
get(proto_type: string): LuaTable
Create a new instance of the proto message
Parameters
proto_type:string— @The full proto message name (e.g. "game.data", where game is package and data is message name)
Returns
LuaTable
encode(proto_type: string, data: LuaTable): string
Encode data to bytes
Parameters
proto_type:string— @The full proto message name (e.g. "game.data", where game is package and data is message name)data:LuaTable— @The data to encode
Returns
string
decode(proto_type: string, bytes?: string | undefined): LuaTable
Decode bytes to lua table
Parameters
proto_type:string— @The full proto message name (e.g. "game.data", where game is package and data is message name)bytes?:string | undefined— @The bytes to decode
Returns
LuaTable
verify(proto_type: string, data: LuaTable): LuaTable
Verify data to match the proto_type. Return data with all default values according to proto_type, remove extra fields
Parameters
proto_type:string— @The full proto message name (e.g. "game.data", where game is package and data is message name)data:LuaTable— @The data to verify
Returns
LuaTable
update_with_default_messages(proto_type: string, data: LuaTable)
Update data to match the proto_type.
- All default values will be added to the data if they are not present
- All extra fields will be removed from the data
Parameters
proto_type:string— @The full proto message name (e.g. "game.data", where game is package and data is message name)data:LuaTable— @The data to update