fromBytes static method
从二进制获取buff内容
Implementation
static IBuffInfo fromBytes(ByteArray bytes) {
int i;
bytes.endian = Endian.little;
int type = bytes.readByte();
late IBuffInfo buff;
if (type == BuffType.byteType) {
buff = BuffByte();
buff.value = bytes.readByte();
} else if (type == BuffType.unsignedByteType) {
buff = BuffUByte();
buff.value = bytes.readUnsignedByte();
} else if (type == BuffType.shortType) {
buff = BuffShort();
buff.value = bytes.readShort();
} else if (type == BuffType.unsignedShortType) {
buff = BuffUShort();
buff.value = bytes.readUnsignedShort();
} else if (type == BuffType.intType) {
buff = BuffInt();
buff.value = bytes.readInt();
} else if (type == BuffType.unsignedIntType) {
buff = BuffUInt();
buff.value = bytes.readUnsignedInt();
} else if (type == BuffType.int64Type) {
buff = BuffInt64();
buff.value = bytes.readInt64();
} else if (type == BuffType.floatType) {
buff = BuffFloat();
buff.value = bytes.readFloat();
} else if (type == BuffType.doubleType) {
buff = BuffDouble();
buff.value = bytes.readDouble();
} else if (type == BuffType.stringType) {
buff = BuffString();
buff.value = bytes.readUTF();
} else if (type == BuffType.longstringType) {
buff = BuffLongString();
int len = bytes.readInt();
buff.value = bytes.readUTFBytes(len);
} else if (type == BuffType.bytesType) {
buff = BuffBytes();
int len = bytes.readInt();
if (len > 0) {
bytes.readBytes(buff.value as ByteArray, 0, len);
}
} else if (type == BuffType.booleanType) {
buff = BuffBoolean();
buff.value = bytes.readBoolean();
} else if (type == BuffType.objectType) {
buff = BuffObject();
int attLen = bytes.readUnsignedShort();
for (i = 0; i < attLen; i++) {
IBuffInfo att = BuffBytesUtil.fromBytes(bytes);
(buff as BuffObject).addAttribute(att);
}
} else if (type == BuffType.listType) {
buff = BuffList();
int itemLen = bytes.readUnsignedShort();
for (i = 0; i < itemLen; i++) {
IBuffInfo item = BuffBytesUtil.fromBytes(bytes);
(buff as BuffList).push(item);
}
}
return buff;
}