"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringTextMapGetter = exports.bufferTextMapGetter = void 0;
const api_1 = require("@opentelemetry/api");
exports.bufferTextMapGetter = {
    get(carrier, key) {
        if (!carrier) {
            return undefined;
        }
        const keys = Object.keys(carrier);
        for (const carrierKey of keys) {
            if (carrierKey === key || carrierKey.toLowerCase() === key.toLowerCase()) {
                const value = carrier[carrierKey];
                if (Buffer.isBuffer(value)) {
                    return value.toString("utf8");
                }
                if (typeof value === "string") {
                    return value;
                }
                if (value !== undefined && value !== null) {
                    return String(value);
                }
                return undefined;
            }
        }
        return undefined;
    },
    keys(carrier) {
        if (!carrier) {
            return [];
        }
        return Object.keys(carrier);
    },
};
exports.stringTextMapGetter = {
    get(carrier, key) {
        if (!carrier) {
            return undefined;
        }
        return api_1.defaultTextMapGetter.get(carrier, key);
    },
    keys(carrier) {
        if (!carrier) {
            return [];
        }
        return api_1.defaultTextMapGetter.keys(carrier);
    },
};
//# sourceMappingURL=propagator.js.map