fix:参考金值,研听,研值工程通用通用工程公共能力,重点对比网络请求、登录认证、状态管理、本地存储、WebView、推送、版本更新、一键登录、主题/UI 等模块,确定后续统一整改方案
This commit is contained in:
1 parent
6997a65c96
commit
d364c6d908
46 files changed
+2060
-395
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Minimal reader retained only for endpoints that do not have an
|
||||
/// authoritative generated protobuf model yet.
|
||||
class ProtobufWireMessage {
|
||||
ProtobufWireMessage(this.bytes);
|
||||
|
||||
final List<int> bytes;
|
||||
Map<int, List<Object>>? _cache;
|
||||
|
||||
Map<int, List<Object>> get _fields => _cache ??= _read();
|
||||
int integer(int tag) => (_fields[tag]?.lastOrNull as int?) ?? 0;
|
||||
|
||||
String string(int tag) {
|
||||
final value = _fields[tag]?.lastOrNull;
|
||||
return value is List<int> ? utf8.decode(value, allowMalformed: true) : '';
|
||||
}
|
||||
|
||||
Map<int, List<Object>> _read() {
|
||||
final result = <int, List<Object>>{};
|
||||
var index = 0;
|
||||
|
||||
int varint() {
|
||||
var value = 0;
|
||||
var shift = 0;
|
||||
while (index < bytes.length) {
|
||||
final byte = bytes[index++];
|
||||
value |= (byte & 127) << shift;
|
||||
if (byte < 128) return value;
|
||||
shift += 7;
|
||||
}
|
||||
throw const FormatException('Invalid protobuf');
|
||||
}
|
||||
|
||||
while (index < bytes.length) {
|
||||
final key = varint();
|
||||
final tag = key >> 3;
|
||||
final Object field;
|
||||
if ((key & 7) == 0) {
|
||||
field = varint();
|
||||
} else if ((key & 7) == 2) {
|
||||
final length = varint();
|
||||
final end = index + length;
|
||||
if (end > bytes.length) throw const FormatException('Invalid protobuf');
|
||||
field = bytes.sublist(index, end);
|
||||
index = end;
|
||||
} else {
|
||||
throw const FormatException('Unsupported protobuf');
|
||||
}
|
||||
(result[tag] ??= []).add(field);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
extension on List<Object> {
|
||||
Object? get lastOrNull => isEmpty ? null : last;
|
||||
}
|
||||
Reference in new issue
Block a user