Skip to Content
defold-typescript libraries
Insality

Insality/defold-proto/proto

Protocol-buffer style message encoding for compact Defold network payloads.

  • GitHub: Insality/defold-proto — pinned to 1
    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 — to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as proto from "proto"

Functions

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

Types

proto_logger

proto_logger.trace: (logger: proto_logger, message: string, data: unknown | undefined) => void

proto_logger.debug: (logger: proto_logger, message: string, data: unknown | undefined) => void

proto_logger.info: (logger: proto_logger, message: string, data: unknown | undefined) => void

proto_logger.warn: (logger: proto_logger, message: string, data: unknown | undefined) => void

proto_logger.error: (logger: proto_logger, message: string, data: unknown | undefined) => void

On this page