Merge remote-tracking branch 'origin/main'

This commit is contained in:
zjy
2023-04-09 11:49:43 +08:00
6 changed files with 1149 additions and 1415 deletions
@@ -88,7 +88,7 @@ public abstract class GenerateTsUtils {
}
public static void createProtocolManager(List<IProtocolRegistration> protocolList) throws IOException {
var list = List.of("typescript/buffer/ByteBuffer.ts", "typescript/buffer/long.js", "typescript/buffer/longbits.js");
var list = List.of("typescript/buffer/ByteBuffer.ts", "typescript/buffer/Long.ts", "typescript/buffer/Longbits.ts");
for (var fileName : list) {
var fileInputStream = ClassUtils.getFileFromClassPath(fileName);
var createFile = new File(StringUtils.format("{}/{}", protocolOutputPath, StringUtils.substringAfterFirst(fileName, "typescript/")));
@@ -1,6 +1,6 @@
import ProtocolManager from "../ProtocolManager";
const Longbits = require('./longbits.js');
import {writeInt64, readInt64} from "./Longbits";
const empty_str = '';
const initSize = 128;
@@ -13,8 +13,8 @@ const maxInt = 2147483647;
const minInt = -2147483648;
// UTF-8编码与解码
const encoder = new TextEncoder('utf-8');
const decoder = new TextDecoder('utf-8');
const encoder = new TextEncoder();
const decoder = new TextDecoder();
// nodejs的测试环境需要用以下方式特殊处理
// const util = require('util');
@@ -238,7 +238,7 @@ class ByteBuffer {
}
this.ensureCapacity(9);
Longbits.writeInt64(this, value);
writeInt64(this, value);
}
readLong(): number {
@@ -280,7 +280,7 @@ class ByteBuffer {
}
}
}
return Longbits.readInt64(new Uint8Array(buffer.slice(0, count))).toString();
return readInt64(new Uint8Array(buffer.slice(0, count))).toNumber();
}
writeFloat(value: number): void {
@@ -378,7 +378,7 @@ class ByteBuffer {
};
readBooleanArray(): any {
const array = [];
const array: boolean[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -400,7 +400,7 @@ class ByteBuffer {
};
readByteArray(): any {
const array = [];
const array: number[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -422,7 +422,7 @@ class ByteBuffer {
};
readShortArray(): any {
const array = [];
const array: number[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -444,7 +444,7 @@ class ByteBuffer {
};
readIntArray(): any {
const array = [];
const array: number[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -466,7 +466,7 @@ class ByteBuffer {
};
readLongArray(): any {
const array = [];
const array: number[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -488,7 +488,7 @@ class ByteBuffer {
};
readFloatArray(): any {
const array = [];
const array: number[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -510,7 +510,7 @@ class ByteBuffer {
};
readDoubleArray(): any {
const array = [];
const array: number[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -532,7 +532,7 @@ class ByteBuffer {
};
readStringArray(): any {
const array = [];
const array: string[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -554,7 +554,7 @@ class ByteBuffer {
};
readCharArray(): any {
const array = [];
const array: string[] = [];
const length = this.readInt();
if (length > 0) {
for (let index = 0; index < length; index++) {
@@ -577,7 +577,7 @@ class ByteBuffer {
};
readPacketArray(protocolId: number): any {
const array = [];
const array: any[] = [];
const length = this.readInt();
if (length > 0) {
const protocolRegistration = ProtocolManager.getProtocol(protocolId);
File diff suppressed because it is too large Load Diff
@@ -1,7 +1,6 @@
// from protobuf
const Long = require('./long.js')
// from https://github.com/hornta/long-ts
import {Long} from "./Long";
module.exports = LongBits;
/**
* Constructs new long bits.
@@ -11,101 +10,92 @@ module.exports = LongBits;
* @param {number} lo Low 32 bits, unsigned
* @param {number} hi High 32 bits, unsigned
*/
function LongBits(lo, hi) {
// note that the casts below are theoretically unnecessary as of today, but older statically
// generated converter code might still call the ctor with signed 32bits. kept for compat.
class Longbits {
lo: number;
hi: number;
/**
* Low bits.
* @type {number}
*/
constructor(lo:number, hi:number) {
this.lo = lo >>> 0;
/**
* High bits.
* @type {number}
*/
this.hi = hi >>> 0;
}
}
/**
* Zig-zag encodes this long bits.
* @returns {util.LongBits} `this`
*/
LongBits.prototype.zzEncode = function zzEncode() {
/**
* Zig-zag encodes this long bits.
*/
zzEncode(): Longbits {
const mask = this.hi >> 31;
this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
this.lo = (this.lo << 1 ^ mask) >>> 0;
return this;
};
};
/**
* Zig-zag decodes this long bits.
* @returns {util.LongBits} `this`
*/
LongBits.prototype.zzDecode = function zzDecode() {
/**
* Zig-zag decodes this long bits.
*/
zzDecode(): Longbits {
const mask = -(this.lo & 1);
this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
this.hi = (this.hi >>> 1 ^ mask) >>> 0;
return this;
};
};
/**
* Converts this long bits to a long.
* @param {boolean} [unsigned=false] Whether unsigned or not
* @returns {Long} Long
*/
LongBits.prototype.toLong = function toLong(unsigned) {
/**
* Converts this long bits to a long.
*/
toLong(unsigned): Long {
return new Long(this.lo | 0, this.hi | 0, Boolean(unsigned));
};
};
/**
* Zero bits.
* @memberof util.LongBits
* @type {util.LongBits}
*/
const zero = LongBits.zero = new LongBits(0, 0);
function from(value) {
/**
* Constructs new long bits from the specified number.
*/
static from(value) {
if (typeof value === 'number') {
return fromNumber(value);
return Longbits.fromNumber(value);
}
if (typeof value === 'string' || value instanceof String) {
value = Long.fromString(value);
value = Long.fromString(value);
}
return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
}
return value.low || value.high ? new Longbits(value.low >>> 0, value.high >>> 0) : zero;
}
/**
* Constructs new long bits from the specified number.
* @param {number} value Value
* @returns {util.LongBits} Instance
*/
function fromNumber(value) {
/**
* Constructs new long bits from the specified number.
*/
static fromNumber(value): Longbits {
if (value === 0) {
return zero;
return zero;
}
const sign = value < 0;
if (sign) {
value = -value;
value = -value;
}
let lo = value >>> 0;
let hi = (value - lo) / 4294967296 >>> 0;
if (sign) {
hi = ~hi >>> 0;
lo = ~lo >>> 0;
if (++lo > 4294967295) {
lo = 0;
if (++hi > 4294967295) {
hi = 0;
}
hi = ~hi >>> 0;
lo = ~lo >>> 0;
if (++lo > 4294967295) {
lo = 0;
if (++hi > 4294967295) {
hi = 0;
}
}
}
return new LongBits(lo, hi);
return new Longbits(lo, hi);
}
}
function writeVarint64(byteBuffer, value) {
/**
* Zero bits.
*/
const zero = new Longbits(0, 0);
function writeVarint64(byteBuffer: any, value: Longbits) {
let count = 0;
while (value.hi) {
byteBuffer.writeByte(value.lo & 127 | 128);
@@ -125,9 +115,9 @@ function writeVarint64(byteBuffer, value) {
byteBuffer.writeByte(value.lo);
}
function readLongVarint(buffer) {
function readLongVarint(buffer: any) {
// tends to deopt with local vars for octet etc.
const bits = new LongBits(0, 0);
const bits = new Longbits(0, 0);
let i = 0;
const len = buffer.length;
let pos = 0;
@@ -175,15 +165,11 @@ function readLongVarint(buffer) {
return bits;
}
function writeInt64(byteBuffer, value) {
const bits = from(value).zzEncode();
export function writeInt64(byteBuffer: any, value: any) {
const bits = Longbits.from(value).zzEncode();
writeVarint64(byteBuffer, bits);
}
function readInt64(buffer) {
export function readInt64(buffer: any): Long {
return readLongVarint(buffer).zzDecode().toLong(false);
}
LongBits.writeInt64 = writeInt64;
LongBits.readInt64 = readInt64;
File diff suppressed because it is too large Load Diff
+6
View File
@@ -0,0 +1,6 @@
A级电报 04/06 21:40
💥【白糖现货价格创五年来新高 业内预计短期易涨难跌】
受国内连续两年减产、加工糖利润倒挂,印度减产落地,以及国内消费恢复预期强劲等因素推动,近期国内白糖现货价格持续走高,基准价直逼6500元/吨,创近五年新高。财联社记者近日多方采访获悉,短期看,白糖价格在巴西尚未开榨前将继续维持高位,缺乏明显利空因素或将易涨难跌。长远来看,现货价格则可能呈现近强远弱,但未来走弱幅度要看消费恢复情况。有业内人士表示,在目前糖价持续高位之下,叠加二季度消费恢复预期较强,行业盈利或会有较大改善。(财联社记者 刘建 王平安)
💧热词:期货市场情报 白糖