4.0.1 • Published 5 years ago

gd-com v4.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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()

buff.putVar(wanted)

const recieved = buff.getVar()

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

// buffer is empty !

- get

MethodReturn
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

MethodReturn
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

MethodReturn
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'

let encoded = gdCom.putVar(wanted)
let decoded = gdCom.getVar(encoded)
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', (data) => {
    const packet = new GdBuffer(data)

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

    const packetToSend = new GdBuffer()
    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

4.0.1

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.0.8

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.1

5 years ago