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 +
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 +
(aggregate, key) => {
const val = map[key];
const keyLen = UTF8Encoder.byteLength(key);
const keyBuf = createBuffer(keyLen);
UTF8Encoder.encode(key, keyBuf, 0, keyLen);
const valLen = UTF8Encoder.byteLength(val);
const valBuf = createBuffer(valLen);
UTF8Encoder.encode(val, valBuf, 0, valLen);
const newEntries = aggregate.entries;
newEntries.push({keyLen, keyBuf, valLen, valBuf});
return {
//4 for the sizes plus the actual key and actual value
totalSize: aggregate.totalSize + 4 + keyLen + valLen,
entries: newEntries,
};
},
(aggregate, key) => {
const val = map[key];
const keyLen = UTF8Encoder.byteLength(key);
const keyBuf = createBuffer(keyLen);
UTF8Encoder.encode(key, keyBuf, 0, keyLen);
const valLen = UTF8Encoder.byteLength(val);
const valBuf = createBuffer(valLen);
UTF8Encoder.encode(val, valBuf, 0, valLen);
const newEntries = aggregate.entries;
newEntries.push({keyLen, keyBuf, valLen, valBuf});
return {
//4 for the sizes plus the actual key and actual value
totalSize: aggregate.totalSize + 4 + keyLen + valLen,
entries: newEntries,
};
},
{totalSize: 0, entries: []},