Source: Core/Packet.js

var Stormancer;
(function (Stormancer) {
    var Packet = (function () {
        /**
        A packet sent by a remote peer to the running peer.
        @class Packet
        @classdesc A packet sent by a remote peer to the running peer.
        @memberof Stormancer
        */
        function Packet(source, data, metadata) {
            /**
            A byte representing the index of the scene for this peer.
            @member Stormancer.Packet#connection
            @type {Object}
            */
            this.connection = null;
            /**
            Data contained in the packet.
            @member Stormancer.Packet#data
            @type {Uint8Array}
            */
            this.data = null;
            this.metadata = null;
            this.connection = source;
            this.data = data;
            this.metadata = metadata;
        }
        /**
        Get a DataView on the internal data buffer
        @method Stormancer.Packet#getDataView
        @return {DataView}
        */
        Packet.prototype.getDataView = function () {
            return new DataView(this.data.buffer, this.data.byteOffset, this.data.byteLength);
        };
        /**
        Deserialize the internal data to an object by using MsgPack and return this object.
        @method Stormancer.Packet#readObject
        @return {Object}
        */
        Packet.prototype.readObject = function () {
            var msgpackSerializer = new Stormancer.MsgPackSerializer();
            return msgpackSerializer.deserialize(this.data);
        };
        /**
        Set the metadatas of the packet. This action will overwrite the existing metadatas.
        @method Stormancer.Packet#setMetadata
        @param {Object} metadata
        */
        Packet.prototype.setMetadata = function (metadata) {
            this.metadata = metadata;
        };
        /**
        Get the metadatas from the packet.
        @method Stormancer.Packet#getMetadata
        @return {Object.<string, Object>}
        */
        Packet.prototype.getMetadata = function () {
            if (!this.metadata) {
                this.metadata = {};
            }
            return this.metadata;
        };
        /**
        Set a metadata in the packet
        @method Stormancer.Packet#setMetadataValue
        @param {string} key
        @param {Object} value
        */
        Packet.prototype.setMetadataValue = function (key, value) {
            if (!this.metadata) {
                this.metadata = {};
            }
            this.metadata[key] = value;
        };
        /**
        Returns metadata
        @method Stormancer.Packet#getMetadataValue
        @param {string} key
        @return {string} Key associated object
        */
        Packet.prototype.getMetadataValue = function (key) {
            if (!this.metadata) {
                this.metadata = {};
            }
            return this.metadata[key];
        };
        return Packet;
    })();
    Stormancer.Packet = Packet;
})(Stormancer || (Stormancer = {}));
//# sourceMappingURL=Packet.js.map