This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove protobuf-ts and split code into two folders (#162)
This module uses both protobuf-ts and protons for protobuf operations. To reduce the bundle size, just use protons for both. Splits the two transports into `private-to-private` and `private-to-public` folders to better tell what code is used by what. Module exports are unaffected so this is a non-breaking change.
- Loading branch information
1 parent
2f5c524
commit 64723a7
Showing
23 changed files
with
162 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* eslint-disable import/export */ | ||
/* eslint-disable complexity */ | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
|
||
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' | ||
import type { Codec } from 'protons-runtime' | ||
import type { Uint8ArrayList } from 'uint8arraylist' | ||
|
||
export interface Message { | ||
flag?: Message.Flag | ||
message?: Uint8Array | ||
} | ||
|
||
export namespace Message { | ||
export enum Flag { | ||
FIN = 'FIN', | ||
STOP_SENDING = 'STOP_SENDING', | ||
RESET = 'RESET' | ||
} | ||
|
||
enum __FlagValues { | ||
FIN = 0, | ||
STOP_SENDING = 1, | ||
RESET = 2 | ||
} | ||
|
||
export namespace Flag { | ||
export const codec = (): Codec<Flag> => { | ||
return enumeration<Flag>(__FlagValues) | ||
} | ||
} | ||
|
||
let _codec: Codec<Message> | ||
|
||
export const codec = (): Codec<Message> => { | ||
if (_codec == null) { | ||
_codec = message<Message>((obj, w, opts = {}) => { | ||
if (opts.lengthDelimited !== false) { | ||
w.fork() | ||
} | ||
|
||
if (obj.flag != null) { | ||
w.uint32(8) | ||
Message.Flag.codec().encode(obj.flag, w) | ||
} | ||
|
||
if (obj.message != null) { | ||
w.uint32(18) | ||
w.bytes(obj.message) | ||
} | ||
|
||
if (opts.lengthDelimited !== false) { | ||
w.ldelim() | ||
} | ||
}, (reader, length) => { | ||
const obj: any = {} | ||
|
||
const end = length == null ? reader.len : reader.pos + length | ||
|
||
while (reader.pos < end) { | ||
const tag = reader.uint32() | ||
|
||
switch (tag >>> 3) { | ||
case 1: | ||
obj.flag = Message.Flag.codec().decode(reader) | ||
break | ||
case 2: | ||
obj.message = reader.bytes() | ||
break | ||
default: | ||
reader.skipType(tag & 7) | ||
break | ||
} | ||
} | ||
|
||
return obj | ||
}) | ||
} | ||
|
||
return _codec | ||
} | ||
|
||
export const encode = (obj: Partial<Message>): Uint8Array => { | ||
return encodeMessage(obj, Message.codec()) | ||
} | ||
|
||
export const decode = (buf: Uint8Array | Uint8ArrayList): Message => { | ||
return decodeMessage(buf, Message.codec()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.