Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import pbjs from 'protobufjs/light'
import jsonDescriptor from './service.pb.json'
// create daemon service
const root = pbjs.Root.fromJSON(jsonDescriptor)
export const ServiceName = 'berty.node.Service'
export const service = root.lookup(ServiceName)
const genPayloadPb = (payload, type) => {
const root = protobuf.Root.fromJSON(jsonDescriptor);
const PayloadTarget = root.lookupType(type);
const message = PayloadTarget.create(payload);
return PayloadTarget.encode(message).finish().toString('hex');
};
const exportPbJson = (jsonDescriptor, ServiceName) => {
const pbFromJson = pbjs.Root.fromJSON(jsonDescriptor)
return pbFromJson.lookup(ServiceName)
}
const recoverFromPayload = (payload, type, jsonDescriptor) => {
const payloadBuf = binary.from(payload, 'hex');
const root = protobuf.Root.fromJSON(jsonDescriptor);
const PayloadTarget = root.lookupType(type.charAt(0).toUpperCase() + type.slice(1));
const payloadMessage = PayloadTarget.decode(payloadBuf);
return PayloadTarget.toObject(payloadMessage, {
enums: String,
longs: Number,
});
};
import pbjs from 'protobufjs/light'
import jsonDescriptor from './message.pb.json'
const root = pbjs.Root.fromJSON(jsonDescriptor)
export const Message = root.lookup('berty.entity.Message')
export default Message
import pbjs from 'protobufjs/light'
import jsonDescriptor from './kind.pb.json'
const root = pbjs.Root.fromJSON(jsonDescriptor)
export const Kind = root.lookup('berty.entity.Kind')
export default Kind
import pbjs from 'protobufjs/light'
import jsonDescriptor from './event.pb.json'
const root = pbjs.Root.fromJSON(jsonDescriptor)
export const Event = root.lookup('berty.entity.Event')
export default Event