Sha256: 136296b33be8dc05eec3e063cd11a1d19d81cb1803fc685ccc2f728d93eef171

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

const Command = require("../../utils/Command")
const TypeEncoder = require('./TypeSerializer')
const Runtime = require('../../utils/RuntimeName')

class CommandSerializer {
    buffer = new Int8Array(2)


    serialize(root_command, connectionData, runtimeVersion = 0) {
        this.buffer[0] = root_command.runtimeName
        this.buffer[1] = runtimeVersion
        this.#insertIntoBuffer(connectionData.serializeConnectionData())
        this.#insertIntoBuffer(new Int8Array([Runtime.Nodejs, root_command.commandType]))
        this.#serializeRecursively(root_command)
        return this.buffer
    }

    #serializeRecursively = function(root_command) {
        for (let cmd of root_command.payload) {
            if (cmd instanceof Command) {
                this.#insertIntoBuffer(TypeEncoder.serializeCommand(cmd))
                this.#serializeRecursively(cmd)
            } else {
                let result = TypeEncoder.encodePrimitive(cmd)
                this.#insertIntoBuffer(result)
            }
        }
    }

    #insertIntoBuffer = function(arg) {
        let newArray = new Int8Array(this.buffer.length + arg.length)
        newArray.set(this.buffer, 0)
        newArray.set(arg, this.buffer.length)
        this.buffer = newArray
    }
}

module.exports = CommandSerializer

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Nodejs/core/protocol/CommandSerializer.js
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Nodejs/core/protocol/CommandSerializer.js
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Nodejs/core/protocol/CommandSerializer.js
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Nodejs/core/protocol/CommandSerializer.js
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Nodejs/core/protocol/CommandSerializer.js