@moqtap/codec 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/{chunk-5XZKO2U5.js → chunk-2XH6PHXR.js} +62 -51
  2. package/dist/{chunk-APTV6F72.js → chunk-3YAR3I3S.js} +67 -51
  3. package/dist/{chunk-BQHLUT37.cjs → chunk-7ENEWAMZ.cjs} +2 -6
  4. package/dist/{chunk-MD2OA7SE.js → chunk-BV6MITLO.js} +15 -8
  5. package/dist/{chunk-B56AG5HU.cjs → chunk-EVCPBFSR.cjs} +6 -4
  6. package/dist/{chunk-KNLPX3YA.js → chunk-H6DTAIWM.js} +6 -4
  7. package/dist/{chunk-J3ASFPCX.cjs → chunk-IADVBKEJ.cjs} +15 -8
  8. package/dist/{chunk-I55J3KXD.js → chunk-NH4L6NIY.js} +48 -33
  9. package/dist/{chunk-EQAYMCXO.cjs → chunk-PU2KV7VP.cjs} +48 -33
  10. package/dist/{chunk-HEO2JG6C.js → chunk-TMXRYOBS.js} +100 -92
  11. package/dist/{chunk-IEJULBKB.cjs → chunk-UA5XFP4O.cjs} +100 -92
  12. package/dist/{chunk-KTVN4P6J.cjs → chunk-UZO5Z2XT.cjs} +62 -51
  13. package/dist/{chunk-MH7537FB.cjs → chunk-VWXUT5R2.cjs} +67 -51
  14. package/dist/{chunk-JJEN2VG5.js → chunk-XQGEOFGE.js} +2 -6
  15. package/dist/{codec-BnamSx7L.d.cts → codec-N3g1lxQQ.d.cts} +1 -1
  16. package/dist/{codec-CFhUGTu2.d.ts → codec-v6Vloc7H.d.ts} +1 -1
  17. package/dist/draft12.cjs +2 -2
  18. package/dist/draft12.js +1 -1
  19. package/dist/draft14-session.d.cts +1 -1
  20. package/dist/draft14-session.d.ts +1 -1
  21. package/dist/draft14.cjs +2 -2
  22. package/dist/draft14.d.cts +3 -3
  23. package/dist/draft14.d.ts +3 -3
  24. package/dist/draft14.js +1 -1
  25. package/dist/draft15.cjs +2 -2
  26. package/dist/draft15.js +1 -1
  27. package/dist/draft16.cjs +2 -2
  28. package/dist/draft16.js +1 -1
  29. package/dist/draft17.cjs +2 -2
  30. package/dist/draft17.js +1 -1
  31. package/dist/draft18.cjs +2 -2
  32. package/dist/draft18.js +1 -1
  33. package/dist/draft19.cjs +2 -2
  34. package/dist/draft19.js +1 -1
  35. package/dist/index.cjs +14 -14
  36. package/dist/index.d.cts +2 -2
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +7 -7
  39. package/dist/session.d.cts +1 -1
  40. package/dist/session.d.ts +1 -1
  41. package/dist/{types-CVeKIk7A.d.cts → types-HI_bbXka.d.cts} +0 -2
  42. package/dist/{types-CVeKIk7A.d.ts → types-HI_bbXka.d.ts} +0 -2
  43. package/package.json +2 -2
  44. package/src/drafts/draft12/data-streams.ts +13 -4
  45. package/src/drafts/draft14/codec.ts +2 -6
  46. package/src/drafts/draft14/types.ts +0 -2
  47. package/src/drafts/draft15/data-streams.ts +30 -16
  48. package/src/drafts/draft16/codec.ts +116 -93
  49. package/src/drafts/draft17/codec.ts +72 -35
  50. package/src/drafts/draft18/codec.ts +89 -53
  51. package/src/drafts/draft19/codec.ts +94 -53
@@ -987,112 +987,135 @@ function decodeTrackExtensions(reader) {
987
987
  return result;
988
988
  }
989
989
  function encodeParams(params, writer) {
990
- let count = params.unknown ? params.unknown.length : 0;
991
- if (params.delivery_timeout !== void 0) count++;
992
- if (params.authorization_token !== void 0) count++;
993
- if (params.max_cache_duration !== void 0) count++;
994
- if (params.expires !== void 0) count++;
995
- if (params.largest_object !== void 0) count++;
996
- if (params.publisher_priority !== void 0) count++;
997
- if (params.forward !== void 0) count++;
998
- if (params.subscriber_priority !== void 0) count++;
999
- if (params.subscription_filter !== void 0) count++;
1000
- if (params.group_order !== void 0) count++;
1001
- if (params.dynamic_groups !== void 0) count++;
1002
- if (params.new_group_request !== void 0) count++;
1003
- writer.writeVarInt(count);
990
+ const entries = [];
1004
991
  if (params.delivery_timeout !== void 0) {
1005
- writer.writeVarInt(PARAM_DELIVERY_TIMEOUT);
1006
- writer.writeVarInt(params.delivery_timeout);
992
+ entries.push({
993
+ type: PARAM_DELIVERY_TIMEOUT,
994
+ encode: (w) => w.writeVarInt(params.delivery_timeout)
995
+ });
1007
996
  }
1008
997
  if (params.authorization_token !== void 0) {
1009
- writer.writeVarInt(PARAM_AUTHORIZATION_TOKEN);
1010
- const tmpW = new BufferWriter(64);
1011
- encodeAuthorizationToken(params.authorization_token, tmpW);
1012
- const raw = tmpW.finish();
1013
- writer.writeVarInt(raw.byteLength);
1014
- writer.writeBytes(raw);
998
+ entries.push({
999
+ type: PARAM_AUTHORIZATION_TOKEN,
1000
+ encode: (w) => {
1001
+ const tmpW = new BufferWriter(64);
1002
+ encodeAuthorizationToken(params.authorization_token, tmpW);
1003
+ const raw = tmpW.finish();
1004
+ w.writeVarInt(raw.byteLength);
1005
+ w.writeBytes(raw);
1006
+ }
1007
+ });
1015
1008
  }
1016
1009
  if (params.max_cache_duration !== void 0) {
1017
- writer.writeVarInt(PARAM_MAX_CACHE_DURATION);
1018
- writer.writeVarInt(params.max_cache_duration);
1010
+ entries.push({
1011
+ type: PARAM_MAX_CACHE_DURATION,
1012
+ encode: (w) => w.writeVarInt(params.max_cache_duration)
1013
+ });
1019
1014
  }
1020
1015
  if (params.expires !== void 0) {
1021
- writer.writeVarInt(PARAM_EXPIRES);
1022
- writer.writeVarInt(params.expires);
1016
+ entries.push({ type: PARAM_EXPIRES, encode: (w) => w.writeVarInt(params.expires) });
1023
1017
  }
1024
1018
  if (params.largest_object !== void 0) {
1025
- writer.writeVarInt(PARAM_LARGEST_OBJECT);
1026
- const tmpW = new BufferWriter(16);
1027
- tmpW.writeVarInt(params.largest_object.group);
1028
- tmpW.writeVarInt(params.largest_object.object);
1029
- const raw = tmpW.finish();
1030
- writer.writeVarInt(raw.byteLength);
1031
- writer.writeBytes(raw);
1019
+ entries.push({
1020
+ type: PARAM_LARGEST_OBJECT,
1021
+ // Draft-16 has no per-parameter value encoding: a Key-Value-Pair whose
1022
+ // Type is odd carries a Length, and 0x09 is odd. Drafts 17 and later
1023
+ // replaced that with "the encoding is specified by each parameter
1024
+ // definition", which is where the same field loses its length.
1025
+ encode: (w) => {
1026
+ const tmpW = new BufferWriter(16);
1027
+ tmpW.writeVarInt(params.largest_object.group);
1028
+ tmpW.writeVarInt(params.largest_object.object);
1029
+ const raw = tmpW.finish();
1030
+ w.writeVarInt(raw.byteLength);
1031
+ w.writeBytes(raw);
1032
+ }
1033
+ });
1032
1034
  }
1033
1035
  if (params.publisher_priority !== void 0) {
1034
- writer.writeVarInt(PARAM_PUBLISHER_PRIORITY);
1035
- writer.writeVarInt(params.publisher_priority);
1036
+ entries.push({
1037
+ type: PARAM_PUBLISHER_PRIORITY,
1038
+ encode: (w) => w.writeVarInt(params.publisher_priority)
1039
+ });
1036
1040
  }
1037
1041
  if (params.forward !== void 0) {
1038
- writer.writeVarInt(PARAM_FORWARD);
1039
- writer.writeVarInt(params.forward);
1042
+ entries.push({ type: PARAM_FORWARD, encode: (w) => w.writeVarInt(params.forward) });
1040
1043
  }
1041
1044
  if (params.subscriber_priority !== void 0) {
1042
- writer.writeVarInt(PARAM_SUBSCRIBER_PRIORITY);
1043
- writer.writeVarInt(params.subscriber_priority);
1045
+ entries.push({
1046
+ type: PARAM_SUBSCRIBER_PRIORITY,
1047
+ encode: (w) => w.writeVarInt(params.subscriber_priority)
1048
+ });
1044
1049
  }
1045
1050
  if (params.subscription_filter !== void 0) {
1046
- writer.writeVarInt(PARAM_SUBSCRIPTION_FILTER);
1047
- const tmpW = new BufferWriter(32);
1048
- const f = params.subscription_filter;
1049
- tmpW.writeVarInt(f.filter_type);
1050
- if (f.filter_type === 3n || f.filter_type === 4n) {
1051
- tmpW.writeVarInt(f.start_group);
1052
- tmpW.writeVarInt(f.start_object);
1053
- }
1054
- if (f.filter_type === 4n) {
1055
- tmpW.writeVarInt(f.end_group);
1056
- }
1057
- const raw = tmpW.finish();
1058
- writer.writeVarInt(raw.byteLength);
1059
- writer.writeBytes(raw);
1051
+ entries.push({
1052
+ type: PARAM_SUBSCRIPTION_FILTER,
1053
+ encode: (w) => {
1054
+ const tmpW = new BufferWriter(32);
1055
+ const f = params.subscription_filter;
1056
+ tmpW.writeVarInt(f.filter_type);
1057
+ if (f.filter_type === 3n || f.filter_type === 4n) {
1058
+ tmpW.writeVarInt(f.start_group);
1059
+ tmpW.writeVarInt(f.start_object);
1060
+ }
1061
+ if (f.filter_type === 4n) {
1062
+ tmpW.writeVarInt(f.end_group);
1063
+ }
1064
+ const raw = tmpW.finish();
1065
+ w.writeVarInt(raw.byteLength);
1066
+ w.writeBytes(raw);
1067
+ }
1068
+ });
1060
1069
  }
1061
1070
  if (params.group_order !== void 0) {
1062
- writer.writeVarInt(PARAM_GROUP_ORDER);
1063
- writer.writeVarInt(params.group_order);
1071
+ entries.push({ type: PARAM_GROUP_ORDER, encode: (w) => w.writeVarInt(params.group_order) });
1064
1072
  }
1065
1073
  if (params.dynamic_groups !== void 0) {
1066
- writer.writeVarInt(PARAM_DYNAMIC_GROUPS);
1067
- writer.writeVarInt(params.dynamic_groups);
1074
+ entries.push({
1075
+ type: PARAM_DYNAMIC_GROUPS,
1076
+ encode: (w) => w.writeVarInt(params.dynamic_groups)
1077
+ });
1068
1078
  }
1069
1079
  if (params.new_group_request !== void 0) {
1070
- writer.writeVarInt(PARAM_NEW_GROUP_REQUEST);
1071
- writer.writeVarInt(params.new_group_request);
1080
+ entries.push({
1081
+ type: PARAM_NEW_GROUP_REQUEST,
1082
+ encode: (w) => w.writeVarInt(params.new_group_request)
1083
+ });
1072
1084
  }
1073
1085
  if (params.unknown) {
1074
1086
  for (const u of params.unknown) {
1075
1087
  const id = BigInt(u.id);
1076
- writer.writeVarInt(id);
1077
- if (id % 2n === 0n) {
1078
- const raw = hexToBytes(u.raw_hex);
1079
- const tmpReader = new BufferReader(raw);
1080
- const value = tmpReader.readVarInt();
1081
- writer.writeVarInt(value);
1082
- } else {
1083
- const raw = hexToBytes(u.raw_hex);
1084
- writer.writeVarInt(raw.byteLength);
1085
- writer.writeBytes(raw);
1086
- }
1088
+ entries.push({
1089
+ type: id,
1090
+ encode: (w) => {
1091
+ const raw = hexToBytes(u.raw_hex);
1092
+ if (id % 2n === 0n) {
1093
+ w.writeVarInt(new BufferReader(raw).readVarInt());
1094
+ } else {
1095
+ w.writeVarInt(raw.byteLength);
1096
+ w.writeBytes(raw);
1097
+ }
1098
+ }
1099
+ });
1087
1100
  }
1088
1101
  }
1102
+ entries.sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
1103
+ writer.writeVarInt(entries.length);
1104
+ let prevType = 0n;
1105
+ for (const entry of entries) {
1106
+ writer.writeVarInt(entry.type - prevType);
1107
+ entry.encode(writer);
1108
+ prevType = entry.type;
1109
+ }
1089
1110
  }
1090
1111
  function decodeParams(reader) {
1091
1112
  const count = Number(reader.readVarInt());
1092
1113
  const result = {};
1093
- const unknown = [];
1114
+ let prevType = 0n;
1094
1115
  for (let i = 0; i < count; i++) {
1095
- const paramType = reader.readVarInt();
1116
+ const delta = reader.readVarInt();
1117
+ const paramType = prevType + delta;
1118
+ prevType = paramType;
1096
1119
  if (paramType === PARAM_DELIVERY_TIMEOUT) {
1097
1120
  result.delivery_timeout = reader.readVarInt();
1098
1121
  } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
@@ -1138,29 +1161,14 @@ function decodeParams(reader) {
1138
1161
  const consumed = reader.offset - startOff;
1139
1162
  if (consumed < length) reader.readBytes(length - consumed);
1140
1163
  result.subscription_filter = filter;
1141
- } else if (paramType % 2n === 0n) {
1142
- const value = reader.readVarInt();
1143
- const tmpWriter = new BufferWriter(16);
1144
- tmpWriter.writeVarInt(value);
1145
- const raw = tmpWriter.finish();
1146
- unknown.push({
1147
- id: `0x${paramType.toString(16)}`,
1148
- length: raw.byteLength,
1149
- raw_hex: bytesToHex(raw)
1150
- });
1151
1164
  } else {
1152
- const length = Number(reader.readVarInt());
1153
- const bytes = reader.readBytes(length);
1154
- unknown.push({
1155
- id: `0x${paramType.toString(16)}`,
1156
- length,
1157
- raw_hex: bytesToHex(bytes)
1158
- });
1165
+ throw new DecodeError(
1166
+ "INVALID_PARAMETER",
1167
+ `Unknown Message Parameter type 0x${paramType.toString(16)}`,
1168
+ reader.offset
1169
+ );
1159
1170
  }
1160
1171
  }
1161
- if (unknown.length > 0) {
1162
- result.unknown = unknown;
1163
- }
1164
1172
  return result;
1165
1173
  }
1166
1174
  function encodeClientSetupPayload(msg, w) {
@@ -987,112 +987,135 @@ function decodeTrackExtensions(reader) {
987
987
  return result;
988
988
  }
989
989
  function encodeParams(params, writer) {
990
- let count = params.unknown ? params.unknown.length : 0;
991
- if (params.delivery_timeout !== void 0) count++;
992
- if (params.authorization_token !== void 0) count++;
993
- if (params.max_cache_duration !== void 0) count++;
994
- if (params.expires !== void 0) count++;
995
- if (params.largest_object !== void 0) count++;
996
- if (params.publisher_priority !== void 0) count++;
997
- if (params.forward !== void 0) count++;
998
- if (params.subscriber_priority !== void 0) count++;
999
- if (params.subscription_filter !== void 0) count++;
1000
- if (params.group_order !== void 0) count++;
1001
- if (params.dynamic_groups !== void 0) count++;
1002
- if (params.new_group_request !== void 0) count++;
1003
- writer.writeVarInt(count);
990
+ const entries = [];
1004
991
  if (params.delivery_timeout !== void 0) {
1005
- writer.writeVarInt(PARAM_DELIVERY_TIMEOUT);
1006
- writer.writeVarInt(params.delivery_timeout);
992
+ entries.push({
993
+ type: PARAM_DELIVERY_TIMEOUT,
994
+ encode: (w) => w.writeVarInt(params.delivery_timeout)
995
+ });
1007
996
  }
1008
997
  if (params.authorization_token !== void 0) {
1009
- writer.writeVarInt(PARAM_AUTHORIZATION_TOKEN);
1010
- const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(64);
1011
- encodeAuthorizationToken(params.authorization_token, tmpW);
1012
- const raw = tmpW.finish();
1013
- writer.writeVarInt(raw.byteLength);
1014
- writer.writeBytes(raw);
998
+ entries.push({
999
+ type: PARAM_AUTHORIZATION_TOKEN,
1000
+ encode: (w) => {
1001
+ const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(64);
1002
+ encodeAuthorizationToken(params.authorization_token, tmpW);
1003
+ const raw = tmpW.finish();
1004
+ w.writeVarInt(raw.byteLength);
1005
+ w.writeBytes(raw);
1006
+ }
1007
+ });
1015
1008
  }
1016
1009
  if (params.max_cache_duration !== void 0) {
1017
- writer.writeVarInt(PARAM_MAX_CACHE_DURATION);
1018
- writer.writeVarInt(params.max_cache_duration);
1010
+ entries.push({
1011
+ type: PARAM_MAX_CACHE_DURATION,
1012
+ encode: (w) => w.writeVarInt(params.max_cache_duration)
1013
+ });
1019
1014
  }
1020
1015
  if (params.expires !== void 0) {
1021
- writer.writeVarInt(PARAM_EXPIRES);
1022
- writer.writeVarInt(params.expires);
1016
+ entries.push({ type: PARAM_EXPIRES, encode: (w) => w.writeVarInt(params.expires) });
1023
1017
  }
1024
1018
  if (params.largest_object !== void 0) {
1025
- writer.writeVarInt(PARAM_LARGEST_OBJECT);
1026
- const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(16);
1027
- tmpW.writeVarInt(params.largest_object.group);
1028
- tmpW.writeVarInt(params.largest_object.object);
1029
- const raw = tmpW.finish();
1030
- writer.writeVarInt(raw.byteLength);
1031
- writer.writeBytes(raw);
1019
+ entries.push({
1020
+ type: PARAM_LARGEST_OBJECT,
1021
+ // Draft-16 has no per-parameter value encoding: a Key-Value-Pair whose
1022
+ // Type is odd carries a Length, and 0x09 is odd. Drafts 17 and later
1023
+ // replaced that with "the encoding is specified by each parameter
1024
+ // definition", which is where the same field loses its length.
1025
+ encode: (w) => {
1026
+ const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(16);
1027
+ tmpW.writeVarInt(params.largest_object.group);
1028
+ tmpW.writeVarInt(params.largest_object.object);
1029
+ const raw = tmpW.finish();
1030
+ w.writeVarInt(raw.byteLength);
1031
+ w.writeBytes(raw);
1032
+ }
1033
+ });
1032
1034
  }
1033
1035
  if (params.publisher_priority !== void 0) {
1034
- writer.writeVarInt(PARAM_PUBLISHER_PRIORITY);
1035
- writer.writeVarInt(params.publisher_priority);
1036
+ entries.push({
1037
+ type: PARAM_PUBLISHER_PRIORITY,
1038
+ encode: (w) => w.writeVarInt(params.publisher_priority)
1039
+ });
1036
1040
  }
1037
1041
  if (params.forward !== void 0) {
1038
- writer.writeVarInt(PARAM_FORWARD);
1039
- writer.writeVarInt(params.forward);
1042
+ entries.push({ type: PARAM_FORWARD, encode: (w) => w.writeVarInt(params.forward) });
1040
1043
  }
1041
1044
  if (params.subscriber_priority !== void 0) {
1042
- writer.writeVarInt(PARAM_SUBSCRIBER_PRIORITY);
1043
- writer.writeVarInt(params.subscriber_priority);
1045
+ entries.push({
1046
+ type: PARAM_SUBSCRIBER_PRIORITY,
1047
+ encode: (w) => w.writeVarInt(params.subscriber_priority)
1048
+ });
1044
1049
  }
1045
1050
  if (params.subscription_filter !== void 0) {
1046
- writer.writeVarInt(PARAM_SUBSCRIPTION_FILTER);
1047
- const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(32);
1048
- const f = params.subscription_filter;
1049
- tmpW.writeVarInt(f.filter_type);
1050
- if (f.filter_type === 3n || f.filter_type === 4n) {
1051
- tmpW.writeVarInt(f.start_group);
1052
- tmpW.writeVarInt(f.start_object);
1053
- }
1054
- if (f.filter_type === 4n) {
1055
- tmpW.writeVarInt(f.end_group);
1056
- }
1057
- const raw = tmpW.finish();
1058
- writer.writeVarInt(raw.byteLength);
1059
- writer.writeBytes(raw);
1051
+ entries.push({
1052
+ type: PARAM_SUBSCRIPTION_FILTER,
1053
+ encode: (w) => {
1054
+ const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(32);
1055
+ const f = params.subscription_filter;
1056
+ tmpW.writeVarInt(f.filter_type);
1057
+ if (f.filter_type === 3n || f.filter_type === 4n) {
1058
+ tmpW.writeVarInt(f.start_group);
1059
+ tmpW.writeVarInt(f.start_object);
1060
+ }
1061
+ if (f.filter_type === 4n) {
1062
+ tmpW.writeVarInt(f.end_group);
1063
+ }
1064
+ const raw = tmpW.finish();
1065
+ w.writeVarInt(raw.byteLength);
1066
+ w.writeBytes(raw);
1067
+ }
1068
+ });
1060
1069
  }
1061
1070
  if (params.group_order !== void 0) {
1062
- writer.writeVarInt(PARAM_GROUP_ORDER);
1063
- writer.writeVarInt(params.group_order);
1071
+ entries.push({ type: PARAM_GROUP_ORDER, encode: (w) => w.writeVarInt(params.group_order) });
1064
1072
  }
1065
1073
  if (params.dynamic_groups !== void 0) {
1066
- writer.writeVarInt(PARAM_DYNAMIC_GROUPS);
1067
- writer.writeVarInt(params.dynamic_groups);
1074
+ entries.push({
1075
+ type: PARAM_DYNAMIC_GROUPS,
1076
+ encode: (w) => w.writeVarInt(params.dynamic_groups)
1077
+ });
1068
1078
  }
1069
1079
  if (params.new_group_request !== void 0) {
1070
- writer.writeVarInt(PARAM_NEW_GROUP_REQUEST);
1071
- writer.writeVarInt(params.new_group_request);
1080
+ entries.push({
1081
+ type: PARAM_NEW_GROUP_REQUEST,
1082
+ encode: (w) => w.writeVarInt(params.new_group_request)
1083
+ });
1072
1084
  }
1073
1085
  if (params.unknown) {
1074
1086
  for (const u of params.unknown) {
1075
1087
  const id = BigInt(u.id);
1076
- writer.writeVarInt(id);
1077
- if (id % 2n === 0n) {
1078
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1079
- const tmpReader = new (0, _chunk4XLYCT5Qcjs.BufferReader)(raw);
1080
- const value = tmpReader.readVarInt();
1081
- writer.writeVarInt(value);
1082
- } else {
1083
- const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1084
- writer.writeVarInt(raw.byteLength);
1085
- writer.writeBytes(raw);
1086
- }
1088
+ entries.push({
1089
+ type: id,
1090
+ encode: (w) => {
1091
+ const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
1092
+ if (id % 2n === 0n) {
1093
+ w.writeVarInt(new (0, _chunk4XLYCT5Qcjs.BufferReader)(raw).readVarInt());
1094
+ } else {
1095
+ w.writeVarInt(raw.byteLength);
1096
+ w.writeBytes(raw);
1097
+ }
1098
+ }
1099
+ });
1087
1100
  }
1088
1101
  }
1102
+ entries.sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
1103
+ writer.writeVarInt(entries.length);
1104
+ let prevType = 0n;
1105
+ for (const entry of entries) {
1106
+ writer.writeVarInt(entry.type - prevType);
1107
+ entry.encode(writer);
1108
+ prevType = entry.type;
1109
+ }
1089
1110
  }
1090
1111
  function decodeParams(reader) {
1091
1112
  const count = Number(reader.readVarInt());
1092
1113
  const result = {};
1093
- const unknown = [];
1114
+ let prevType = 0n;
1094
1115
  for (let i = 0; i < count; i++) {
1095
- const paramType = reader.readVarInt();
1116
+ const delta = reader.readVarInt();
1117
+ const paramType = prevType + delta;
1118
+ prevType = paramType;
1096
1119
  if (paramType === PARAM_DELIVERY_TIMEOUT) {
1097
1120
  result.delivery_timeout = reader.readVarInt();
1098
1121
  } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
@@ -1138,29 +1161,14 @@ function decodeParams(reader) {
1138
1161
  const consumed = reader.offset - startOff;
1139
1162
  if (consumed < length) reader.readBytes(length - consumed);
1140
1163
  result.subscription_filter = filter;
1141
- } else if (paramType % 2n === 0n) {
1142
- const value = reader.readVarInt();
1143
- const tmpWriter = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(16);
1144
- tmpWriter.writeVarInt(value);
1145
- const raw = tmpWriter.finish();
1146
- unknown.push({
1147
- id: `0x${paramType.toString(16)}`,
1148
- length: raw.byteLength,
1149
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, raw)
1150
- });
1151
1164
  } else {
1152
- const length = Number(reader.readVarInt());
1153
- const bytes = reader.readBytes(length);
1154
- unknown.push({
1155
- id: `0x${paramType.toString(16)}`,
1156
- length,
1157
- raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, bytes)
1158
- });
1165
+ throw new (0, _chunk4XLYCT5Qcjs.DecodeError)(
1166
+ "INVALID_PARAMETER",
1167
+ `Unknown Message Parameter type 0x${paramType.toString(16)}`,
1168
+ reader.offset
1169
+ );
1159
1170
  }
1160
1171
  }
1161
- if (unknown.length > 0) {
1162
- result.unknown = unknown;
1163
- }
1164
1172
  return result;
1165
1173
  }
1166
1174
  function encodeClientSetupPayload(msg, w) {