@dcl/ecs 7.0.6-4106539347.commit-b417eb5 → 7.0.6-4106696113.commit-cda3cfd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/serialization/crdt/crdtMessageProtocol.d.ts +1 -0
- package/dist/serialization/crdt/crdtMessageProtocol.js +68 -0
- package/dist/serialization/crdt/deleteComponent.js +4 -10
- package/dist/serialization/crdt/deleteEntity.js +2 -2
- package/dist/serialization/crdt/index.d.ts +3 -2
- package/dist/serialization/crdt/index.js +3 -70
- package/dist/serialization/crdt/message.js +4 -1
- package/dist/serialization/crdt/putComponent.js +5 -5
- package/dist/serialization/crdt/types.d.ts +7 -4
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export var CrdtMessageProtocol;
|
|
6
|
+
(function (CrdtMessageProtocol) {
|
|
7
|
+
/**
|
|
8
|
+
* Validate if the message incoming is completed
|
|
9
|
+
* @param buf - ByteBuffer
|
|
10
|
+
*/
|
|
11
|
+
function validate(buf) {
|
|
12
|
+
const rem = buf.remainingBytes();
|
|
13
|
+
if (rem < CRDT_MESSAGE_HEADER_LENGTH) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const messageLength = buf.getUint32(buf.currentReadOffset());
|
|
17
|
+
if (rem < messageLength) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
CrdtMessageProtocol.validate = validate;
|
|
23
|
+
/**
|
|
24
|
+
* Get the current header, consuming the bytes involved.
|
|
25
|
+
* @param buf - ByteBuffer
|
|
26
|
+
* @returns header or null if there is no validated message
|
|
27
|
+
*/
|
|
28
|
+
function readHeader(buf) {
|
|
29
|
+
if (!validate(buf)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
length: buf.readUint32(),
|
|
34
|
+
type: buf.readUint32()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
CrdtMessageProtocol.readHeader = readHeader;
|
|
38
|
+
/**
|
|
39
|
+
* Get the current header, without consuming the bytes involved.
|
|
40
|
+
* @param buf - ByteBuffer
|
|
41
|
+
* @returns header or null if there is no validated message
|
|
42
|
+
*/
|
|
43
|
+
function getHeader(buf) {
|
|
44
|
+
if (!validate(buf)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const currentOffset = buf.currentReadOffset();
|
|
48
|
+
return {
|
|
49
|
+
length: buf.getUint32(currentOffset),
|
|
50
|
+
type: buf.getUint32(currentOffset + 4)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
CrdtMessageProtocol.getHeader = getHeader;
|
|
54
|
+
/**
|
|
55
|
+
* Consume the incoming message without processing it.
|
|
56
|
+
* @param buf - ByteBuffer
|
|
57
|
+
* @returns true in case of success or false if there is no valid message.
|
|
58
|
+
*/
|
|
59
|
+
function consumeMessage(buf) {
|
|
60
|
+
const header = getHeader(buf);
|
|
61
|
+
if (!header) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
buf.incrementReadOffset(header.length);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
CrdtMessageProtocol.consumeMessage = consumeMessage;
|
|
68
|
+
})(CrdtMessageProtocol || (CrdtMessageProtocol = {}));
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { CrdtMessageProtocol } from '
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
2
|
import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export var DeleteComponent;
|
|
7
7
|
(function (DeleteComponent) {
|
|
8
|
-
|
|
9
|
-
DeleteComponent.MESSAGE_HEADER_LENGTH = 20;
|
|
8
|
+
DeleteComponent.MESSAGE_HEADER_LENGTH = 12;
|
|
10
9
|
/**
|
|
11
10
|
* Write DeleteComponent message
|
|
12
11
|
*/
|
|
@@ -20,10 +19,7 @@ export var DeleteComponent;
|
|
|
20
19
|
// Write ComponentOperation header
|
|
21
20
|
buf.setUint32(startMessageOffset + 8, entity);
|
|
22
21
|
buf.setUint32(startMessageOffset + 12, componentId);
|
|
23
|
-
|
|
24
|
-
buf.setUint64(startMessageOffset + 16, BigInt(timestamp));
|
|
25
|
-
// TODO: remove buffer length (-4 bytes)
|
|
26
|
-
buf.setUint32(startMessageOffset + 24, 0);
|
|
22
|
+
buf.setUint32(startMessageOffset + 16, timestamp);
|
|
27
23
|
}
|
|
28
24
|
DeleteComponent.write = write;
|
|
29
25
|
function read(buf) {
|
|
@@ -38,10 +34,8 @@ export var DeleteComponent;
|
|
|
38
34
|
...header,
|
|
39
35
|
entityId: buf.readUint32(),
|
|
40
36
|
componentId: buf.readUint32(),
|
|
41
|
-
timestamp:
|
|
37
|
+
timestamp: buf.readUint32()
|
|
42
38
|
};
|
|
43
|
-
// TODO: remove buffer length
|
|
44
|
-
buf.incrementReadOffset(4);
|
|
45
39
|
return msg;
|
|
46
40
|
}
|
|
47
41
|
DeleteComponent.read = read;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CrdtMessageProtocol } from '
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
2
|
import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
@@ -20,7 +20,7 @@ export var DeleteEntity;
|
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
22
|
if (header.type !== CrdtMessageType.DELETE_ENTITY) {
|
|
23
|
-
throw new Error('
|
|
23
|
+
throw new Error('DeleteEntity tried to read another message type.');
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
26
|
...header,
|
|
@@ -1,72 +1,5 @@
|
|
|
1
|
-
import { CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
2
|
-
export * from './types';
|
|
3
1
|
export * from './deleteComponent';
|
|
4
|
-
export * from './putComponent';
|
|
5
2
|
export * from './deleteEntity';
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
export var CrdtMessageProtocol;
|
|
10
|
-
(function (CrdtMessageProtocol) {
|
|
11
|
-
/**
|
|
12
|
-
* Validate if the message incoming is completed
|
|
13
|
-
* @param buf - ByteBuffer
|
|
14
|
-
*/
|
|
15
|
-
function validate(buf) {
|
|
16
|
-
const rem = buf.remainingBytes();
|
|
17
|
-
if (rem < CRDT_MESSAGE_HEADER_LENGTH) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const messageLength = buf.getUint32(buf.currentReadOffset());
|
|
21
|
-
if (rem < messageLength) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
CrdtMessageProtocol.validate = validate;
|
|
27
|
-
/**
|
|
28
|
-
* Get the current header, consuming the bytes involved.
|
|
29
|
-
* @param buf - ByteBuffer
|
|
30
|
-
* @returns header or null if there is no validated message
|
|
31
|
-
*/
|
|
32
|
-
function readHeader(buf) {
|
|
33
|
-
if (!validate(buf)) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
length: buf.readUint32(),
|
|
38
|
-
type: buf.readUint32()
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
CrdtMessageProtocol.readHeader = readHeader;
|
|
42
|
-
/**
|
|
43
|
-
* Get the current header, without consuming the bytes involved.
|
|
44
|
-
* @param buf - ByteBuffer
|
|
45
|
-
* @returns header or null if there is no validated message
|
|
46
|
-
*/
|
|
47
|
-
function getHeader(buf) {
|
|
48
|
-
if (!validate(buf)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
const currentOffset = buf.currentReadOffset();
|
|
52
|
-
return {
|
|
53
|
-
length: buf.getUint32(currentOffset),
|
|
54
|
-
type: buf.getUint32(currentOffset + 4)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
CrdtMessageProtocol.getHeader = getHeader;
|
|
58
|
-
/**
|
|
59
|
-
* Consume the incoming message without processing it.
|
|
60
|
-
* @param buf - ByteBuffer
|
|
61
|
-
* @returns true in case of success or false if there is no valid message.
|
|
62
|
-
*/
|
|
63
|
-
function consumeMessage(buf) {
|
|
64
|
-
const header = getHeader(buf);
|
|
65
|
-
if (!header) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
buf.incrementReadOffset(header.length);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
CrdtMessageProtocol.consumeMessage = consumeMessage;
|
|
72
|
-
})(CrdtMessageProtocol || (CrdtMessageProtocol = {}));
|
|
3
|
+
export * from './putComponent';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './crdtMessageProtocol';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { CrdtMessageProtocol
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
2
|
import { CrdtMessageType } from './types';
|
|
3
|
+
import { PutComponentOperation } from './putComponent';
|
|
4
|
+
import { DeleteComponent } from './deleteComponent';
|
|
5
|
+
import { DeleteEntity } from './deleteEntity';
|
|
3
6
|
export function readMessage(buf) {
|
|
4
7
|
const header = CrdtMessageProtocol.getHeader(buf);
|
|
5
8
|
if (!header)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CrdtMessageProtocol } from '
|
|
1
|
+
import { CrdtMessageProtocol } from './crdtMessageProtocol';
|
|
2
2
|
import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export var PutComponentOperation;
|
|
7
7
|
(function (PutComponentOperation) {
|
|
8
|
-
PutComponentOperation.MESSAGE_HEADER_LENGTH =
|
|
8
|
+
PutComponentOperation.MESSAGE_HEADER_LENGTH = 16;
|
|
9
9
|
/**
|
|
10
10
|
* Call this function for an optimal writing data passing the ByteBuffer
|
|
11
11
|
* already allocated
|
|
@@ -22,9 +22,9 @@ export var PutComponentOperation;
|
|
|
22
22
|
// Write ComponentOperation header
|
|
23
23
|
buf.setUint32(startMessageOffset + 8, entity);
|
|
24
24
|
buf.setUint32(startMessageOffset + 12, componentDefinition.componentId);
|
|
25
|
-
buf.
|
|
25
|
+
buf.setUint32(startMessageOffset + 16, timestamp);
|
|
26
26
|
const newLocal = messageLength - PutComponentOperation.MESSAGE_HEADER_LENGTH - CRDT_MESSAGE_HEADER_LENGTH;
|
|
27
|
-
buf.setUint32(startMessageOffset +
|
|
27
|
+
buf.setUint32(startMessageOffset + 20, newLocal);
|
|
28
28
|
}
|
|
29
29
|
PutComponentOperation.write = write;
|
|
30
30
|
function read(buf) {
|
|
@@ -39,7 +39,7 @@ export var PutComponentOperation;
|
|
|
39
39
|
...header,
|
|
40
40
|
entityId: buf.readUint32(),
|
|
41
41
|
componentId: buf.readUint32(),
|
|
42
|
-
timestamp:
|
|
42
|
+
timestamp: buf.readUint32(),
|
|
43
43
|
data: buf.readBuffer()
|
|
44
44
|
};
|
|
45
45
|
}
|
|
@@ -10,11 +10,11 @@ export declare enum CrdtMessageType {
|
|
|
10
10
|
MAX_MESSAGE_TYPE = 4
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* Min. length = header (8 bytes) +
|
|
13
|
+
* Min. length = header (8 bytes) + 16 bytes = 24 bytes
|
|
14
14
|
*
|
|
15
|
-
* @param entity -
|
|
16
|
-
* @param componentId -
|
|
17
|
-
* @param timestamp -
|
|
15
|
+
* @param entity - Uint32 number of the entity
|
|
16
|
+
* @param componentId - Uint32 number of id
|
|
17
|
+
* @param timestamp - Uint32 Lamport timestamp
|
|
18
18
|
* @param data - Uint8[] data of component => length(4 bytes) + block of bytes[0..length-1]
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
@@ -26,6 +26,9 @@ export type PutComponentMessageBody = {
|
|
|
26
26
|
data: Uint8Array;
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
|
+
* @param entity - Uint32 number of the entity
|
|
30
|
+
* @param componentId - Uint32 number of id
|
|
31
|
+
* @param timestamp - Uint32 Lamport timestamp
|
|
29
32
|
* @public
|
|
30
33
|
*/
|
|
31
34
|
export type DeleteComponentMessageBody = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
|
-
"version": "7.0.6-
|
|
3
|
+
"version": "7.0.6-4106696113.commit-cda3cfd",
|
|
4
4
|
"description": "Decentraland ECS",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"ts-proto": "^1.112.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@dcl/crdt": "7.0.6-
|
|
30
|
+
"@dcl/crdt": "7.0.6-4106696113.commit-cda3cfd",
|
|
31
31
|
"@dcl/js-runtime": "file:../js-runtime",
|
|
32
32
|
"@dcl/protocol": "1.0.0-4085628047.commit-0f6384e"
|
|
33
33
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"displayName": "ECS",
|
|
42
42
|
"tsconfig": "./tsconfig.json"
|
|
43
43
|
},
|
|
44
|
-
"commit": "
|
|
44
|
+
"commit": "cda3cfd5ce0ddeb287ff28c1e4f1ad3329c017c0"
|
|
45
45
|
}
|