Skip to content

Commit

Permalink
Add support for stripping header structs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-greene-ck committed Aug 9, 2019
1 parent c0f929d commit 60e84c7
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 103 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions packages/thrift-client-context-filter/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions packages/thrift-client-timing-filter/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/thrift-client-ttwitter-filter/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -161,34 +161,25 @@ export function ThriftClientTTwitterFilter<T>({

const requestHeader: TTwitter.IRequestHeader = {
trace_id: new Int64(
`0x${
(normalHeaders as any)[
ZipkinHeaders.TraceId
]
}`,
`0x${normalHeaders[ZipkinHeaders.TraceId]}`,
),
span_id: new Int64(
`0x${
(normalHeaders as any)[
ZipkinHeaders.SpanId
]
}`,
`0x${normalHeaders[ZipkinHeaders.SpanId]}`,
),
parent_span_id:
normalHeaders[ZipkinHeaders.ParentId] !==
undefined
? new Int64(
`0x${
(normalHeaders as any)[
normalHeaders[
ZipkinHeaders.ParentId
]
}`,
)
: undefined,
sampled:
(normalHeaders as any)[
ZipkinHeaders.Sampled
] === '1',
normalHeaders[ZipkinHeaders.Sampled] ===
'1',
client_id:
clientId !== undefined
? new TTwitter.ClientId(clientId)
Expand Down
8 changes: 4 additions & 4 deletions packages/thrift-client-zipkin-filter/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions packages/thrift-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions packages/thrift-integration/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions packages/thrift-server-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions packages/thrift-server-core/src/main/utils/readThriftObject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
IProtocolConstructor,
IStructCodec,
IThriftField,
ITransportConstructor,
ProtocolType,
TransportType,
TType,
} from '../types'

import { getProtocol, TProtocol } from '../protocols'
Expand All @@ -26,3 +28,35 @@ export function readThriftObject<StrictType>(
resolve([decoded, receiver.remaining()])
})
}

export function stripStruct(
data: Buffer,
transportType: TransportType = 'buffered',
protocolType: ProtocolType = 'binary',
): Buffer {
try {
const Transport: ITransportConstructor = getTransport(transportType)
const Protocol: IProtocolConstructor = getProtocol(protocolType)
const receiver: TTransport = new Transport(data)
const input: TProtocol = new Protocol(receiver)

input.readStructBegin()

while (true) {
const ret: IThriftField = input.readFieldBegin()
const fieldType: TType = ret.fieldType
if (fieldType === TType.STOP) {
break
} else {
input.skip(fieldType)
}
input.readFieldEnd()
}

input.readStructEnd()

return receiver.remaining()
} catch (err) {
return data
}
}
Loading

0 comments on commit 60e84c7

Please sign in to comment.