Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

Commit 20c7191

Browse files
authored
feat!: change protocol version encoding from big-endian to little-endian (#337)
BREAKING CHANGES: old binary data is not compatible due to change in endianness
1 parent db974f7 commit 20c7191

File tree

11 files changed

+16
-16
lines changed

11 files changed

+16
-16
lines changed

lib/dataContract/DataContract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class DataContract {
282282
delete serializedData.protocolVersion;
283283

284284
const protocolVersionUInt32 = Buffer.alloc(4);
285-
protocolVersionUInt32.writeUInt32BE(this.getProtocolVersion(), 0);
285+
protocolVersionUInt32.writeUInt32LE(this.getProtocolVersion(), 0);
286286

287287
return Buffer.concat([protocolVersionUInt32, encode(serializedData)]);
288288
}

lib/decodeProtocolEntityFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function decodeProtocolEntityFactory(versionCompatibilityMap) {
1717
// Parse protocol version from the first 4 bytes
1818
let protocolVersion;
1919
try {
20-
protocolVersion = buffer.slice(0, 4).readUInt32BE(0);
20+
protocolVersion = buffer.slice(0, 4).readUInt32LE(0);
2121
} catch (error) {
2222
throw new ProtocolVersionParsingError(
2323
buffer,

lib/document/Document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class Document {
369369
delete serializedData.$protocolVersion;
370370

371371
const protocolVersionUInt32 = Buffer.alloc(4);
372-
protocolVersionUInt32.writeUInt32BE(this.getProtocolVersion(), 0);
372+
protocolVersionUInt32.writeUInt32LE(this.getProtocolVersion(), 0);
373373

374374
return Buffer.concat([protocolVersionUInt32, encode(serializedData)]);
375375
}

lib/identity/Identity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Identity {
112112
delete serializedData.protocolVersion;
113113

114114
const protocolVersionUInt32 = Buffer.alloc(4);
115-
protocolVersionUInt32.writeUInt32BE(this.getProtocolVersion(), 0);
115+
protocolVersionUInt32.writeUInt32LE(this.getProtocolVersion(), 0);
116116

117117
return Buffer.concat([protocolVersionUInt32, encode(serializedData)]);
118118
}

lib/stateTransition/AbstractStateTransition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class AbstractStateTransition {
133133
delete serializedData.protocolVersion;
134134

135135
const protocolVersionUInt32 = Buffer.alloc(4);
136-
protocolVersionUInt32.writeUInt32BE(this.getProtocolVersion(), 0);
136+
protocolVersionUInt32.writeUInt32LE(this.getProtocolVersion(), 0);
137137

138138
return Buffer.concat([protocolVersionUInt32, encode(serializedData)]);
139139
}

test/unit/dataContract/DataContract.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe('DataContract', () => {
294294
delete dataContractToEncode.protocolVersion;
295295

296296
const protocolVersionUInt32 = Buffer.alloc(4);
297-
protocolVersionUInt32.writeUInt32BE(dataContract.getProtocolVersion(), 0);
297+
protocolVersionUInt32.writeUInt32LE(dataContract.getProtocolVersion(), 0);
298298

299299
expect(encodeMock).to.have.been.calledOnceWith(dataContractToEncode);
300300
expect(result).to.deep.equal(Buffer.concat([protocolVersionUInt32, serializedDataContract]));

test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('DataContractCreateTransition', () => {
7474
encodeMock.returns(serializedStateTransition);
7575

7676
const protocolVersionUInt32 = Buffer.alloc(4);
77-
protocolVersionUInt32.writeUInt32BE(stateTransition.protocolVersion, 0);
77+
protocolVersionUInt32.writeUInt32LE(stateTransition.protocolVersion, 0);
7878

7979
const result = stateTransition.toBuffer();
8080

@@ -111,7 +111,7 @@ describe('DataContractCreateTransition', () => {
111111
]);
112112

113113
const protocolVersionUInt32 = Buffer.alloc(4);
114-
protocolVersionUInt32.writeUInt32BE(stateTransition.protocolVersion, 0);
114+
protocolVersionUInt32.writeUInt32LE(stateTransition.protocolVersion, 0);
115115

116116
expect(hashMock).to.have.been.calledOnceWith(
117117
Buffer.concat([protocolVersionUInt32, serializedDocument]),

test/unit/decodeProtocolEntityFactory.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('decodeProtocolEntityFactory', () => {
2222
parsedProtocolVersion = 0;
2323

2424
protocolVersionBuffer = Buffer.alloc(4);
25-
protocolVersionBuffer.writeUInt32BE(parsedProtocolVersion, 0);
25+
protocolVersionBuffer.writeUInt32LE(parsedProtocolVersion, 0);
2626

2727
rawEntity = { test: 'successful' };
2828
entityBuffer = encode(rawEntity);
@@ -56,7 +56,7 @@ describe('decodeProtocolEntityFactory', () => {
5656
parsedProtocolVersion = 2;
5757

5858
protocolVersionBuffer = Buffer.alloc(4);
59-
protocolVersionBuffer.writeUInt32BE(parsedProtocolVersion, 0);
59+
protocolVersionBuffer.writeUInt32LE(parsedProtocolVersion, 0);
6060

6161
buffer = Buffer.concat([protocolVersionBuffer, entityBuffer]);
6262

@@ -91,7 +91,7 @@ describe('decodeProtocolEntityFactory', () => {
9191
versionCompatibilityMap[currentProtocolVersion.toString()] = minimalProtocolVersion;
9292

9393
protocolVersionBuffer = Buffer.alloc(4);
94-
protocolVersionBuffer.writeUInt32BE(parsedProtocolVersion, 0);
94+
protocolVersionBuffer.writeUInt32LE(parsedProtocolVersion, 0);
9595

9696
buffer = Buffer.concat([protocolVersionBuffer, entityBuffer]);
9797

test/unit/document/Document.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ describe('Document', () => {
411411
const result = document.toBuffer();
412412

413413
const protocolVersionUInt32 = Buffer.alloc(4);
414-
protocolVersionUInt32.writeUInt32BE(rawDocument.$protocolVersion, 0);
414+
protocolVersionUInt32.writeUInt32LE(rawDocument.$protocolVersion, 0);
415415

416416
expect(result).to.deep.equal(Buffer.concat([protocolVersionUInt32, serializedDocument]));
417417

test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('DocumentsBatchTransition', () => {
9090
const result = stateTransition.toBuffer();
9191

9292
const protocolVersionUInt32 = Buffer.alloc(4);
93-
protocolVersionUInt32.writeUInt32BE(stateTransition.protocolVersion, 0);
93+
protocolVersionUInt32.writeUInt32LE(stateTransition.protocolVersion, 0);
9494

9595
expect(result).to.deep.equal(
9696
Buffer.concat([protocolVersionUInt32, serializedStateTransition]),
@@ -121,7 +121,7 @@ describe('DocumentsBatchTransition', () => {
121121
expect(encodeMock).to.have.been.calledOnceWith(dataToEncode);
122122

123123
const protocolVersionUInt32 = Buffer.alloc(4);
124-
protocolVersionUInt32.writeUInt32BE(stateTransition.protocolVersion, 0);
124+
protocolVersionUInt32.writeUInt32LE(stateTransition.protocolVersion, 0);
125125

126126
expect(hashMock).to.have.been.calledOnceWith(
127127
Buffer.concat([protocolVersionUInt32, serializedDocument]),

test/unit/identity/Identity.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('Identity', () => {
106106
delete identityDataToEncode.protocolVersion;
107107

108108
const protocolVersionUInt32 = Buffer.alloc(4);
109-
protocolVersionUInt32.writeUInt32BE(identity.getProtocolVersion(), 0);
109+
protocolVersionUInt32.writeUInt32LE(identity.getProtocolVersion(), 0);
110110

111111
expect(encodeMock).to.have.been.calledOnceWith(identityDataToEncode);
112112
expect(result).to.deep.equal(Buffer.concat([protocolVersionUInt32, encodeMockData]));
@@ -126,7 +126,7 @@ describe('Identity', () => {
126126
delete identityDataToEncode.protocolVersion;
127127

128128
const protocolVersionUInt32 = Buffer.alloc(4);
129-
protocolVersionUInt32.writeUInt32BE(identity.getProtocolVersion(), 0);
129+
protocolVersionUInt32.writeUInt32LE(identity.getProtocolVersion(), 0);
130130

131131
expect(encodeMock).to.have.been.calledOnceWith(identityDataToEncode);
132132
expect(hashMock).to.have.been.calledOnceWith(Buffer.concat([protocolVersionUInt32, buffer]));

0 commit comments

Comments
 (0)