

const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
const require_base64 = require('./base64.js');
const require_TypedArrayEncoder = require('./TypedArrayEncoder.js');
let buffer = require("buffer");
buffer = require_rolldown_runtime.__toESM(buffer);

//#region src/utils/JsonEncoder.ts
var JsonEncoder = class JsonEncoder {
	/**
	* Encode json object into base64 string.
	*
	* @param json the json object to encode into base64 string
	*/
	static toBase64(json) {
		return buffer.Buffer.from(JsonEncoder.toString(json)).toString("base64");
	}
	/**
	* Encode json object into base64url string.
	*
	* @param json the json object to encode into base64url string
	*/
	static toBase64URL(json) {
		return require_base64.base64ToBase64URL(JsonEncoder.toBase64(json));
	}
	/**
	* Decode base64 string into json object. Also supports base64url
	*
	* @param base64 the base64 or base64url string to decode into json
	*/
	static fromBase64(base64) {
		return JsonEncoder.fromBuffer(require_TypedArrayEncoder.TypedArrayEncoder.fromBase64(base64));
	}
	/**
	* Encode json object into string
	*
	* @param json the json object to encode into string
	*/
	static toString(json) {
		return JSON.stringify(json);
	}
	/**
	* Decode string into json object
	*
	* @param string the string to decode into json
	*/
	static fromString(string) {
		return JSON.parse(string);
	}
	/**
	* Encode json object into buffer
	*
	* @param json the json object to encode into buffer format
	*/
	static toBuffer(json) {
		return buffer.Buffer.from(JsonEncoder.toString(json));
	}
	/**
	* Decode buffer into json object
	*
	* @param buffer the buffer to decode into json
	*/
	static fromBuffer(buffer$1) {
		return JsonEncoder.fromString(buffer.Buffer.from(buffer$1).toString("utf-8"));
	}
};

//#endregion
exports.JsonEncoder = JsonEncoder;