protons-runtime
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -12,2 +12,3 @@ import type { Writer, Reader } from './index.js'; | ||
lengthDelimited?: boolean; | ||
writeDefaults?: boolean; | ||
} | ||
@@ -14,0 +15,0 @@ export interface EncodeFunction<T> { |
@@ -16,3 +16,3 @@ import { createCodec, CODEC_TYPES } from '../codec.js'; | ||
const decode = function enumDecode(reader) { | ||
const val = reader.uint32(); | ||
const val = reader.int32(); | ||
return findValue(val); | ||
@@ -19,0 +19,0 @@ }; |
@@ -1,20 +0,6 @@ | ||
import pb from 'protobufjs'; | ||
const Reader = pb.Reader; | ||
// monkey patch the reader to add native bigint support | ||
const methods = [ | ||
'uint64', 'int64', 'sint64', 'fixed64', 'sfixed64' | ||
]; | ||
methods.forEach(method => { | ||
// @ts-expect-error | ||
const original = Reader.prototype[method]; | ||
// @ts-expect-error | ||
Reader.prototype[method] = function () { | ||
return BigInt(original.call(this).toString()); | ||
}; | ||
}); | ||
import { reader } from './reader.js'; | ||
export function decodeMessage(buf, codec) { | ||
const reader = Reader.create(buf instanceof Uint8Array ? buf : buf.subarray()); | ||
// @ts-expect-error | ||
return codec.decode(reader); | ||
const r = reader(buf instanceof Uint8Array ? buf : buf.subarray()); | ||
return codec.decode(r); | ||
} | ||
//# sourceMappingURL=decode.js.map |
@@ -1,18 +0,4 @@ | ||
import pb from 'protobufjs'; | ||
const Writer = pb.Writer; | ||
// monkey patch the writer to add native bigint support | ||
const methods = [ | ||
'uint64', 'int64', 'sint64', 'fixed64', 'sfixed64' | ||
]; | ||
methods.forEach(method => { | ||
// @ts-expect-error | ||
const original = Writer.prototype[method]; | ||
// @ts-expect-error | ||
Writer.prototype[method] = function (val) { | ||
return original.call(this, val.toString()); | ||
}; | ||
}); | ||
import { writer } from './writer.js'; | ||
export function encodeMessage(message, codec) { | ||
const w = Writer.create(); | ||
// @ts-expect-error | ||
const w = writer(); | ||
codec.encode(message, w, { | ||
@@ -19,0 +5,0 @@ lengthDelimited: false |
@@ -13,2 +13,4 @@ import type { Codec } from './codec.js'; | ||
export { message } from './codecs/message.js'; | ||
export { reader } from './reader.js'; | ||
export { writer } from './writer.js'; | ||
export type { Codec, EncodeOptions } from './codec.js'; | ||
@@ -15,0 +17,0 @@ export interface Writer { |
@@ -5,2 +5,4 @@ export { decodeMessage } from './decode.js'; | ||
export { message } from './codecs/message.js'; | ||
export { reader } from './reader.js'; | ||
export { writer } from './writer.js'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "protons-runtime", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Shared code to make your bundle smaller when running protons in your app", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -15,2 +15,3 @@ import type { Writer, Reader } from './index.js' | ||
lengthDelimited?: boolean | ||
writeDefaults?: boolean | ||
} | ||
@@ -17,0 +18,0 @@ |
@@ -23,3 +23,3 @@ | ||
const decode: DecodeFunction<number | string> = function enumDecode (reader) { | ||
const val = reader.uint32() | ||
const val = reader.int32() | ||
@@ -26,0 +26,0 @@ return findValue(val) |
import type { Uint8ArrayList } from 'uint8arraylist' | ||
import type { Codec } from './codec.js' | ||
import pb from 'protobufjs' | ||
import { reader } from './reader.js' | ||
const Reader = pb.Reader | ||
// monkey patch the reader to add native bigint support | ||
const methods = [ | ||
'uint64', 'int64', 'sint64', 'fixed64', 'sfixed64' | ||
] | ||
methods.forEach(method => { | ||
// @ts-expect-error | ||
const original = Reader.prototype[method] | ||
// @ts-expect-error | ||
Reader.prototype[method] = function (): bigint { | ||
return BigInt(original.call(this).toString()) | ||
} | ||
}) | ||
export function decodeMessage <T> (buf: Uint8Array | Uint8ArrayList, codec: Codec<T>): T { | ||
const reader = Reader.create(buf instanceof Uint8Array ? buf : buf.subarray()) | ||
const r = reader(buf instanceof Uint8Array ? buf : buf.subarray()) | ||
// @ts-expect-error | ||
return codec.decode(reader) | ||
return codec.decode(r) | ||
} |
import type { Codec } from './codec.js' | ||
import pb from 'protobufjs' | ||
import { writer } from './writer.js' | ||
const Writer = pb.Writer | ||
// monkey patch the writer to add native bigint support | ||
const methods = [ | ||
'uint64', 'int64', 'sint64', 'fixed64', 'sfixed64' | ||
] | ||
methods.forEach(method => { | ||
// @ts-expect-error | ||
const original = Writer.prototype[method] | ||
// @ts-expect-error | ||
Writer.prototype[method] = function (val: bigint): pb.Writer { | ||
return original.call(this, val.toString()) | ||
} | ||
}) | ||
export function encodeMessage <T> (message: T, codec: Codec<T>): Uint8Array { | ||
const w = Writer.create() | ||
const w = writer() | ||
// @ts-expect-error | ||
codec.encode(message, w, { | ||
@@ -24,0 +8,0 @@ lengthDelimited: false |
@@ -21,2 +21,4 @@ import type { Codec } from './codec.js' | ||
export { message } from './codecs/message.js' | ||
export { reader } from './reader.js' | ||
export { writer } from './writer.js' | ||
export type { Codec, EncodeOptions } from './codec.js' | ||
@@ -23,0 +25,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33212
43
625