Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function encodeMetadata(
service: string,
method: string,
tracing: Encodable,
metadata: Encodable,
): Buffer {
const serviceLength = UTF8Encoder.byteLength(service);
const methodLength = UTF8Encoder.byteLength(method);
const metadataLength = BufferEncoder.byteLength(metadata);
// We can't overload the method call directly and the code generator currently only populates
// the first 3 parameters
if (undefined === tracing) {
tracing = createBuffer(0);
}
const tracingLength = BufferEncoder.byteLength(tracing);
const buffer = createBuffer(
VERSION_SIZE +
SERVICE_LENGTH_SIZE +
serviceLength +
METHOD_LENGTH_SIZE +
methodLength +
TRACING_LENGTH_SIZE +
tracingLength +
metadataLength,
);
let offset = buffer.writeUInt16BE(VERSION, 0);
offset = buffer.writeUInt16BE(serviceLength, offset);
offset = UTF8Encoder.encode(service, buffer, offset, offset + serviceLength);
export function encodeMetadata(
service: string,
method: string,
tracing: Encodable,
metadata: Encodable,
): Buffer {
const serviceLength = UTF8Encoder.byteLength(service);
const methodLength = UTF8Encoder.byteLength(method);
const metadataLength = BufferEncoder.byteLength(metadata);
// We can't overload the method call directly and the code generator currently only populates
// the first 3 parameters
if (undefined === tracing) {
tracing = createBuffer(0);
}
const tracingLength = BufferEncoder.byteLength(tracing);
const buffer = createBuffer(
VERSION_SIZE +
SERVICE_LENGTH_SIZE +
serviceLength +
METHOD_LENGTH_SIZE +
methodLength +
TRACING_LENGTH_SIZE +
tracingLength +
metadataLength,
export function deserializeTraceData(tracer, metadata) {
if (!tracer) {
return null;
}
const tracingData = getTracing(metadata);
if (BufferEncoder.byteLength(tracingData) <= 0) {
return null;
}
return tracer.extract(FORMAT_TEXT_MAP, bufferToMap(tracingData));
}