@@ -28,23 +28,26 @@ export function isProbablyProtobuf(input: Uint8Array) {
2828
2929export const parseRawProtobuf = parseRawProto ;
3030
31+ // GRPC message structure:
3132// The repeated sequence of Length-Prefixed-Message items is delivered in DATA frames
32-
3333// Length-Prefixed-Message → Compressed-Flag Message-Length Message
3434// Compressed-Flag → 0 / 1 ; encoded as 1 byte unsigned integer
3535// Message-Length → {length of Message} ; encoded as 4 byte unsigned integer (big endian)
3636// Message → *{binary octet}
37- export const parseGrpcProtobuf = ( input : Buffer ) => {
38- if ( input . readInt8 ( ) != 0 ) {
39- // TODO support compressed gRPC messages?
40- throw new Error ( "compressed gRPC messages not yet supported" )
37+ export const extractProtobufFromGrpc = ( input : Buffer ) => {
38+ const protobufMessasges : Buffer [ ] = [ ] ;
39+
40+ while ( input . length > 0 ) {
41+ if ( input . readInt8 ( ) != 0 ) {
42+ throw new Error ( "Compressed gRPC messages not yet supported" )
43+ }
44+
45+ const length = input . readInt32BE ( 1 ) ;
46+ protobufMessasges . push ( input . slice ( 5 , 5 + length ) ) ;
47+ input = input . subarray ( 5 + length ) ;
4148 }
42- const length = input . readInt32BE ( 1 ) ;
43- input = input . slice ( 5 , 5 + length ) ;
4449
45- return parseRawProtobuf ( input , {
46- prefix : ''
47- } ) ;
50+ return protobufMessasges ;
4851}
4952
5053export const isValidProtobuf = ( input : Uint8Array ) => {
0 commit comments