mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-20 00:25:09 +00:00
Change-Id: Ia61aae9b83c3297dfe28fd475c585e021186a4aa Signed-off-by: Anthony O'Dowd <a_o-dowd@uk.ibm.com>
34 lines
806 B
JavaScript
34 lines
806 B
JavaScript
/*
|
|
SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* Utility class for data, object mapulation, e.g. serialization
|
|
*/
|
|
|
|
class Utils {
|
|
|
|
/**
|
|
* Convert object to buffer containing JSON data serialization
|
|
* Typically used before putState() ledger API
|
|
* @param {Object} object object to serialize
|
|
* @return {buffer} buffer with the data to store
|
|
*/
|
|
static serialize(object){
|
|
return Buffer.from(JSON.stringify(object));
|
|
}
|
|
|
|
/**
|
|
* Deserialize object, i.e. Covert serialized data to JSON object
|
|
* Typically used after getState() ledger API
|
|
* @param {Object} data object to deserialize
|
|
* @return {json} json with the data to store
|
|
*/
|
|
static deserialize(data){
|
|
return JSON.parse(data);
|
|
}
|
|
}
|
|
|
|
module.exports = Utils;
|