Export functions to create packet serializer and deserializer.

This commit is contained in:
bedrock-bot 2025-03-18 01:01:35 +02:00
commit abefe2c7bf
3 changed files with 27 additions and 1 deletions

View file

@ -102,6 +102,15 @@ ping({ host: 'play.cubecraft.net', port: 19132 }).then(res => {
})
```
### Serializer/Deserializer
The `createSerializer` and `createDeserializer` functions provide direct access to the packet serialization and deserialization layer of bedrock-protocol. This is particularly useful when you need to:
- Work with packet data without establishing a full client/server connection
- Write unit tests for your packet handling logic
- Analyze or debug packet structures between different Minecraft versions
- Save and replay packet sequences for testing or benchmarking
## Documentation
For documentation on the protocol, and packets/fields see the [protocol documentation](https://prismarinejs.github.io/minecraft-data/protocol).

14
index.d.ts vendored
View file

@ -237,4 +237,18 @@ declare module 'bedrock-protocol' {
host: string
port: number
}): Promise<ServerAdvertisement>
/**
* Creates a packet serializer for the specified Minecraft Bedrock version.
* @param version The Minecraft Bedrock version to create the serializer for.
* @returns A serializer that can convert minecraft bedrock packets to binary packet data.
*/
export function createSerializer(version: Version): any
/**
* Creates a packet deserializer for the specified Minecraft Bedrock version.
* @param version The Minecraft Bedrock version to create the deserializer for.
* @returns A deserializer that can convert binary packet data to JavaScript objects.
*/
export function createDeserializer(version: Version): any
}

View file

@ -11,6 +11,7 @@ const { createClient, ping } = require('./src/createClient')
const { createServer } = require('./src/createServer')
const { Titles } = require('prismarine-auth')
const { ServerAdvertisement } = require('./src/server/advertisement')
const { createSerializer, createDeserializer } = require('./src/transforms/serializer')
module.exports = {
Client,
@ -20,5 +21,7 @@ module.exports = {
ping,
createServer,
title: Titles,
ServerAdvertisement
ServerAdvertisement,
createSerializer,
createDeserializer
}