@phated/godot-nodejs-utils
Serializer/deserializer utils for godot engine
Last updated 2 years ago by phated .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @phated/godot-nodejs-utils 
SYNC missed versions from official npm registry.

GM-Com @gd-com/utils

Binary serialization helper godot and nodejs !

Written with this api

Requirements

  • Godot 3.X
  • NodeJS 10.14.0 LTS or greater

How to install

npm install --save @gd-com/utils

For an example take a look @gd-com/examples !

GdBuffer

var gdCom = require('@gd-com/utils') // var { GdBuffer } = require('@gd-com/utils')
var wanted = 'test'

const buff = new gdCom.GdBuffer()

await buff.putVar(wanted)

const recieved = await buff.getVar()

console.log(recieved === wanted) // is true

// buffer is empty !

- get

Method Return
new GdBuffer() GdBuffer Object
new GdBuffer(buffer) GdBuffer Object with initial buffer data
------------------------------- ------------------------------
getVar() Object
get8() Object
get16() Object
get32() Object
get64() Object
getU8() Object
getU16() Object
getU32() Object
getU64() Object
getFloat() Object
getDouble() Object
getString() Object
------------------------------- ------------------------------
putVar(value) void
put8(value) void
put16(value) void
put32(value) void
put64(value) void
putU8(value) void
putU16(value) void
putU32(value) void
putU64(value) void
putFloat(value) void
putDouble(value) void
putString(value) void
------------------------------- ------------------------------
getBuffer() Buffer

Encode and Decode

Use GdBuffer is recommanded !

- get

Method Return
getVar(buffer, offset = 0) Object { value, length }
get8(buffer, offset = 0) Object { value, length }
get16(buffer, offset = 0) Object { value, length }
get32(buffer, offset = 0) Object { value, length }
get64(buffer, offset = 0) Object { value, length }
getU8(buffer, offset = 0) Object { value, length }
getU16(buffer, offset = 0) Object { value, length }
getU32(buffer, offset = 0) Object { value, length }
getU64(buffer, offset = 0) Object { value, length }
getFloat(buffer, offset = 0) Object { value, length }
getDouble(buffer, offset = 0) Object { value, length }
getString(buffer, offset = 0) Object { value, length }

- put

Method Return
putVar(value) Buffer
put8(value) Buffer
put16(value) Buffer
put32(value) Buffer
put64(value) Buffer
putU8(value) Buffer
putU16(value) Buffer
putU32(value) Buffer
putU64(value) Buffer
putFloat(value) Buffer
putDouble(value) Buffer
putString(value) Buffer

Usage example :

var gdCom = require('@gd-com/utils') // var { putVar, getVar } = require('@gd-com/utils')
var wanted = 'test'

gdCom.putVar(wanted).then((encoded) => {
  gdCom.getVar(encoded).then((decoded) => {
    console.log(decoded.value)
  })
})

StreamTcp Splitter


const net = require('net')
const { StreamTcp, GdBuffer, addLengthFront } = require('@gd-com/utils')

let server = net.createServer((socket) => {
  const tcpSplit = new StreamTcp()
  socket.pipe(tcpSplit).on('data', async (data) => {
    const packet = new GdBuffer(data)

    const decoded = await packet.getVar()
    console.log('receive :', decoded)

    const packetToSend = new GdBuffer()
    await packetToSend.putVar(Math.random())

    // we need to put the packet length on top cause it's tcp
    let toSend = addLengthFront(packetToSend.getBuffer())
    console.log('send :', toSend)
    socket.write(toSend)
  })

  socket.on('error', () => console.log('Bye :('))
})

server.on('error', (err) => {
  throw err
})

server.listen(8090, '127.0.0.1', () => {
  console.log(`Server launched TCP 127.0.0.1:${8090}`)
})

Test

git clone git@github.com:gd-com/utils.git gd-com-utils
cd gd-com-utils
npm install or yarn install
npm run lint && npm run test

Contributing

Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.

TODO & CHANGELOG

CHANGELOG

TODO

License

This project is licensed under the MIT License - see the LICENSE file for details

Thanks

  • Godot
  • Godot France
  • GDQuest
  • IG-Dev
  • Salsa2k for the initial work

Current Tags

  • 4.0.0                                ...           latest (2 years ago)

1 Versions

  • 4.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 2
Last Day 1
Last Week 1
Last Month 4
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |