diff --git a/README.md b/README.md index cb2dcd4..9b9ee7c 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/index.d.ts b/index.d.ts index 581e87a..5912b4d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -237,4 +237,18 @@ declare module 'bedrock-protocol' { host: string port: number }): Promise + + /** + * 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 } diff --git a/index.js b/index.js index 7018ae3..c617fd3 100644 --- a/index.js +++ b/index.js @@ -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 }