mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-23 06:25:45 +00:00
ref[es]: rename get set method
This commit is contained in:
+2
-2
@@ -34,14 +34,14 @@ public class EsBoolSerializer implements IEsSerializer {
|
||||
@Override
|
||||
public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("buffer.writeBoolean({});", objectStr)).append(LS);
|
||||
builder.append(StringUtils.format("buffer.writeBool({});", objectStr)).append(LS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) {
|
||||
String result = "result" + GenerateProtocolFile.localVariableId++;
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
builder.append(StringUtils.format("const {} = buffer.readBoolean(); ", result)).append(LS);
|
||||
builder.append(StringUtils.format("const {} = buffer.readBool(); ", result)).append(LS);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ class ByteBuffer {
|
||||
return length !== -1 && this.getReadOffset() < length + beforeReadIndex;
|
||||
}
|
||||
|
||||
getBuffer() {
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
getWriteOffset() {
|
||||
return this.writeOffset;
|
||||
}
|
||||
@@ -120,7 +124,7 @@ class ByteBuffer {
|
||||
return this.writeOffset > this.readOffset;
|
||||
}
|
||||
|
||||
writeBoolean(value) {
|
||||
writeBool(value) {
|
||||
if (!(value === true || value === false)) {
|
||||
throw new Error('value must be true of false');
|
||||
}
|
||||
@@ -133,7 +137,7 @@ class ByteBuffer {
|
||||
this.writeOffset++;
|
||||
}
|
||||
|
||||
readBoolean() {
|
||||
readBool() {
|
||||
const value = this.bufferView.getInt8(this.readOffset);
|
||||
this.readOffset++;
|
||||
return (value === 1);
|
||||
@@ -386,7 +390,7 @@ class ByteBuffer {
|
||||
|
||||
writePacketFlag(value) {
|
||||
const flag = (value === null) || (value === undefined);
|
||||
this.writeBoolean(!flag);
|
||||
this.writeBool(!flag);
|
||||
return flag;
|
||||
}
|
||||
|
||||
@@ -400,23 +404,23 @@ class ByteBuffer {
|
||||
return protocolRegistration.read(this);
|
||||
}
|
||||
|
||||
writeBooleanArray(array) {
|
||||
writeBoolArray(array) {
|
||||
if (array === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
this.writeInt(array.length);
|
||||
array.forEach(element => {
|
||||
this.writeBoolean(element);
|
||||
this.writeBool(element);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
readBooleanArray() {
|
||||
readBoolArray() {
|
||||
const array = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
array.push(this.readBoolean());
|
||||
array.push(this.readBool());
|
||||
}
|
||||
}
|
||||
return array;
|
||||
@@ -601,12 +605,12 @@ class ByteBuffer {
|
||||
}
|
||||
|
||||
// ---------------------------------------------list-------------------------------------------
|
||||
writeBooleanList(list) {
|
||||
this.writeBooleanArray(list);
|
||||
writeBoolList(list) {
|
||||
this.writeBoolArray(list);
|
||||
}
|
||||
|
||||
readBooleanList() {
|
||||
return this.readBooleanArray();
|
||||
readBoolList() {
|
||||
return this.readBoolArray();
|
||||
}
|
||||
|
||||
writeByteList(list) {
|
||||
@@ -674,19 +678,19 @@ class ByteBuffer {
|
||||
}
|
||||
|
||||
// ---------------------------------------------set-------------------------------------------
|
||||
writeBooleanSet(set) {
|
||||
writeBoolSet(set) {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
this.writeInt(set.size);
|
||||
set.forEach(element => {
|
||||
this.writeBoolean(element);
|
||||
this.writeBool(element);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
readBooleanSet() {
|
||||
return new Set(this.readBooleanArray());
|
||||
readBoolSet() {
|
||||
return new Set(this.readBoolArray());
|
||||
}
|
||||
|
||||
writeByteSet(set) {
|
||||
|
||||
@@ -8,11 +8,11 @@ function assert(flag) {
|
||||
}
|
||||
}
|
||||
|
||||
const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-no-compatible.bytes');
|
||||
// const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-compatible.bytes');
|
||||
// const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-inner-compatible.bytes');
|
||||
// const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-compatible.bytes');
|
||||
// const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-inner-compatible.bytes');
|
||||
const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-no-compatible.bytes');
|
||||
// const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-compatible.bytes');
|
||||
// const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-inner-compatible.bytes');
|
||||
// const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-compatible.bytes');
|
||||
// const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-inner-compatible.bytes');
|
||||
|
||||
const arrayBytes = new Uint8Array(data.length);
|
||||
data.copy(arrayBytes, 0, 0, data.length);
|
||||
@@ -43,8 +43,8 @@ function byteBufferTest() {
|
||||
// boolean
|
||||
const testBoolean = [false, true];
|
||||
testBoolean.forEach((value) => {
|
||||
buffer.writeBoolean(value);
|
||||
assert(buffer.readBoolean() == value);
|
||||
buffer.writeBool(value);
|
||||
assert(buffer.readBool() == value);
|
||||
});
|
||||
|
||||
assert(buffer.writeOffset == testBoolean.length);
|
||||
|
||||
@@ -75,6 +75,10 @@ class ByteBuffer {
|
||||
return length !== -1 && this.getReadOffset() < length + beforeReadIndex;
|
||||
}
|
||||
|
||||
getBuffer() {
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
getWriteOffset() {
|
||||
return this.writeOffset;
|
||||
}
|
||||
@@ -120,7 +124,7 @@ class ByteBuffer {
|
||||
return this.writeOffset > this.readOffset;
|
||||
}
|
||||
|
||||
writeBoolean(value) {
|
||||
writeBool(value) {
|
||||
if (!(value === true || value === false)) {
|
||||
throw new Error('value must be true of false');
|
||||
}
|
||||
@@ -133,7 +137,7 @@ class ByteBuffer {
|
||||
this.writeOffset++;
|
||||
}
|
||||
|
||||
readBoolean() {
|
||||
readBool() {
|
||||
const value = this.bufferView.getInt8(this.readOffset);
|
||||
this.readOffset++;
|
||||
return (value === 1);
|
||||
@@ -386,7 +390,7 @@ class ByteBuffer {
|
||||
|
||||
writePacketFlag(value) {
|
||||
const flag = (value === null) || (value === undefined);
|
||||
this.writeBoolean(!flag);
|
||||
this.writeBool(!flag);
|
||||
return flag;
|
||||
}
|
||||
|
||||
@@ -400,23 +404,23 @@ class ByteBuffer {
|
||||
return protocolRegistration.read(this);
|
||||
}
|
||||
|
||||
writeBooleanArray(array) {
|
||||
writeBoolArray(array) {
|
||||
if (array === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
this.writeInt(array.length);
|
||||
array.forEach(element => {
|
||||
this.writeBoolean(element);
|
||||
this.writeBool(element);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
readBooleanArray() {
|
||||
readBoolArray() {
|
||||
const array = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
array.push(this.readBoolean());
|
||||
array.push(this.readBool());
|
||||
}
|
||||
}
|
||||
return array;
|
||||
@@ -601,12 +605,12 @@ class ByteBuffer {
|
||||
}
|
||||
|
||||
// ---------------------------------------------list-------------------------------------------
|
||||
writeBooleanList(list) {
|
||||
this.writeBooleanArray(list);
|
||||
writeBoolList(list) {
|
||||
this.writeBoolArray(list);
|
||||
}
|
||||
|
||||
readBooleanList() {
|
||||
return this.readBooleanArray();
|
||||
readBoolList() {
|
||||
return this.readBoolArray();
|
||||
}
|
||||
|
||||
writeByteList(list) {
|
||||
@@ -674,19 +678,19 @@ class ByteBuffer {
|
||||
}
|
||||
|
||||
// ---------------------------------------------set-------------------------------------------
|
||||
writeBooleanSet(set) {
|
||||
writeBoolSet(set) {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
this.writeInt(set.size);
|
||||
set.forEach(element => {
|
||||
this.writeBoolean(element);
|
||||
this.writeBool(element);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
readBooleanSet() {
|
||||
return new Set(this.readBooleanArray());
|
||||
readBoolSet() {
|
||||
return new Set(this.readBoolArray());
|
||||
}
|
||||
|
||||
writeByteSet(set) {
|
||||
|
||||
@@ -91,10 +91,10 @@ export class ComplexObjectRegistration {
|
||||
buffer.writeDouble(packet.ff);
|
||||
buffer.writeDoubleArray(packet.fff);
|
||||
buffer.writeDoubleArray(packet.ffff);
|
||||
buffer.writeBoolean(packet.g);
|
||||
buffer.writeBoolean(packet.gg);
|
||||
buffer.writeBooleanArray(packet.ggg);
|
||||
buffer.writeBooleanArray(packet.gggg);
|
||||
buffer.writeBool(packet.g);
|
||||
buffer.writeBool(packet.gg);
|
||||
buffer.writeBoolArray(packet.ggg);
|
||||
buffer.writeBoolArray(packet.gggg);
|
||||
buffer.writeString(packet.jj);
|
||||
buffer.writeStringArray(packet.jjj);
|
||||
buffer.writePacket(packet.kk, 102);
|
||||
@@ -289,13 +289,13 @@ export class ComplexObjectRegistration {
|
||||
packet.fff = array22;
|
||||
const array23 = buffer.readDoubleArray();
|
||||
packet.ffff = array23;
|
||||
const result24 = buffer.readBoolean();
|
||||
const result24 = buffer.readBool();
|
||||
packet.g = result24;
|
||||
const result25 = buffer.readBoolean();
|
||||
const result25 = buffer.readBool();
|
||||
packet.gg = result25;
|
||||
const array26 = buffer.readBooleanArray();
|
||||
const array26 = buffer.readBoolArray();
|
||||
packet.ggg = array26;
|
||||
const array27 = buffer.readBooleanArray();
|
||||
const array27 = buffer.readBoolArray();
|
||||
packet.gggg = array27;
|
||||
const result28 = buffer.readString();
|
||||
packet.jj = result28;
|
||||
|
||||
@@ -42,7 +42,7 @@ export class NormalObjectRegistration {
|
||||
buffer.writeLong(packet.d);
|
||||
buffer.writeFloat(packet.e);
|
||||
buffer.writeDouble(packet.f);
|
||||
buffer.writeBoolean(packet.g);
|
||||
buffer.writeBool(packet.g);
|
||||
buffer.writeString(packet.jj);
|
||||
buffer.writePacket(packet.kk, 102);
|
||||
buffer.writeIntList(packet.l);
|
||||
@@ -79,7 +79,7 @@ export class NormalObjectRegistration {
|
||||
packet.e = result5;
|
||||
const result6 = buffer.readDouble();
|
||||
packet.f = result6;
|
||||
const result7 = buffer.readBoolean();
|
||||
const result7 = buffer.readBool();
|
||||
packet.g = result7;
|
||||
const result8 = buffer.readString();
|
||||
packet.jj = result8;
|
||||
|
||||
@@ -16,7 +16,7 @@ export class ObjectBRegistration {
|
||||
}
|
||||
const beforeWriteIndex = buffer.getWriteOffset();
|
||||
buffer.writeInt(4);
|
||||
buffer.writeBoolean(packet.flag);
|
||||
buffer.writeBool(packet.flag);
|
||||
buffer.writeInt(packet.innerCompatibleValue);
|
||||
buffer.adjustPadding(4, beforeWriteIndex);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export class ObjectBRegistration {
|
||||
}
|
||||
const beforeReadIndex = buffer.getReadOffset();
|
||||
const packet = new ObjectB();
|
||||
const result0 = buffer.readBoolean();
|
||||
const result0 = buffer.readBool();
|
||||
packet.flag = result0;
|
||||
if (buffer.compatibleRead(beforeReadIndex, length)) {
|
||||
const result1 = buffer.readInt();
|
||||
|
||||
@@ -16,7 +16,7 @@ export class SimpleObjectRegistration {
|
||||
}
|
||||
buffer.writeInt(-1);
|
||||
buffer.writeInt(packet.c);
|
||||
buffer.writeBoolean(packet.g);
|
||||
buffer.writeBool(packet.g);
|
||||
}
|
||||
|
||||
read(buffer) {
|
||||
@@ -28,7 +28,7 @@ export class SimpleObjectRegistration {
|
||||
const packet = new SimpleObject();
|
||||
const result0 = buffer.readInt();
|
||||
packet.c = result0;
|
||||
const result1 = buffer.readBoolean();
|
||||
const result1 = buffer.readBool();
|
||||
packet.g = result1;
|
||||
if (length > 0) {
|
||||
buffer.setReadOffset(beforeReadIndex + length);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user