Skip to content

Instantly share code, notes, and snippets.

@vividsnow
Created May 28, 2019 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vividsnow/2141f9a099b978e4710c3d01a823c4db to your computer and use it in GitHub Desktop.
Save vividsnow/2141f9a099b978e4710c3d01a823c4db to your computer and use it in GitHub Desktop.
use strict; use warnings;
use Google::ProtocolBuffers::Dynamic;
use FindBin qw($Bin); use File::Find; use File::Spec;
my $pb = Google::ProtocolBuffers::Dynamic->new(my $path = "$Bin/proto");
find({ wanted => sub { $pb->load_file(File::Spec->abs2rel($_, $path)) if /\.proto$/ }, no_chdir => 1 }, $path);
$pb->map({qw'pb_prefix Diadoc.Api.Proto prefix Diadoc'});
# test
my $test = '{"OrgId": "test", "Inn": "123", "FullName":"Test", "Sociability":"AllOrganizations", "Address":{ "AddressCode":"RU" }}';
my $org = Diadoc::Organization->decode_json($test);
my $bytes = $org->encode;
my $org2 = Diadoc::Organization->decode($bytes);
print $org2->encode_json, "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment