From fb32c09253ee7aa38d676dbd75daeb41a4525dff Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 26 Oct 2019 13:53:51 -0400 Subject: [PATCH 01/11] Add cast for Protodec::Any --- src/protodec/utils.cr | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/protodec/utils.cr b/src/protodec/utils.cr index df9faf3..23bcb49 100644 --- a/src/protodec/utils.cr +++ b/src/protodec/utils.cr @@ -200,7 +200,7 @@ module Protodec from_json(value, buffer) buffer.rewind - buffer = Base64.urlsafe_encode(buffer, padding: false) + buffer = Base64.urlsafe_encode(buffer) VarLong.to_io(io, buffer.bytesize.to_i64) buffer.to_s(io) when "embedded" @@ -472,6 +472,17 @@ module Protodec case value when .is_a?(Hash) cast_json(value) + when .is_a?(Protodec::Any) + case raw = value.raw + when Array(UInt8) + JSON::Any.new(raw.map { |i| JSON::Any.new(i.to_i64) }) + when Int32 + JSON::Any.new(raw.to_i64) + when Hash(String, Protodec::Any) + cast_json(raw) + else + JSON::Any.new(raw) + end else JSON::Any.new(value) end From 88d3395b1e8a62d3a6b59e334a6303f732d51078 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 26 Oct 2019 13:57:32 -0400 Subject: [PATCH 02/11] Update specs --- spec/protodec_spec.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/protodec_spec.cr b/spec/protodec_spec.cr index 8575d4b..875161a 100644 --- a/spec/protodec_spec.cr +++ b/spec/protodec_spec.cr @@ -2,7 +2,7 @@ require "./spec_helper" describe Protodec do it "decodes Base64 data" do - input = "4qmFsgIrEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaD0VnbGpiMjF0ZFc1cGRIaw" + input = "4qmFsgIsEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaEEVnbGpiMjF0ZFc1cGRIaz0" output = input.strip .try { |i| URI.decode_www_form(i) } .try { |i| URI.decode_www_form(i) } @@ -24,6 +24,6 @@ describe Protodec do }, }) - Base64.urlsafe_encode(Protodec::Any.from_json(object), padding: false).should eq("4qmFsgIrEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaD0VnbGpiMjF0ZFc1cGRIaw") + Base64.urlsafe_encode(Protodec::Any.from_json(object), padding: false).should eq("4qmFsgIsEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaEEVnbGpiMjF0ZFc1cGRIaz0") end end From 041d0000b70b5b9e9870233fac8b220e938554af Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 27 Oct 2019 13:49:04 -0400 Subject: [PATCH 03/11] Bump version --- shard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shard.yml b/shard.yml index 67f01b8..52f911d 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: protodec -version: 0.1.1 +version: 0.1.2 authors: - Omar Roth From e9df06c26287ebfe9f84b529ca2ebe1af44ed112 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 9 Apr 2020 12:17:42 -0500 Subject: [PATCH 04/11] Update dependencies --- shard.yml | 2 +- src/protodec/utils.cr | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/shard.yml b/shard.yml index 52f911d..8f5ffcc 100644 --- a/shard.yml +++ b/shard.yml @@ -8,6 +8,6 @@ targets: protodec: main: src/protodec.cr -crystal: 0.31.1 +crystal: 0.34.0 license: GPLv3 diff --git a/src/protodec/utils.cr b/src/protodec/utils.cr index 23bcb49..b65a43c 100644 --- a/src/protodec/utils.cr +++ b/src/protodec/utils.cr @@ -213,6 +213,9 @@ module Protodec when "bytes" VarLong.to_io(io, value.size.to_i64) value.as_a.each { |byte| io.write_byte byte.as_i.to_u8 } + else # "string" + VarLong.to_io(io, value.to_s.bytesize.to_i64) + io.print value.to_s end end else From aace6fbbbd32bec7254f0db5299c523d384fd2f6 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 9 Apr 2020 12:19:32 -0500 Subject: [PATCH 05/11] Bump version --- shard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shard.yml b/shard.yml index 8f5ffcc..1c18324 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: protodec -version: 0.1.2 +version: 0.1.3 authors: - Omar Roth From f30f2abfde4a277b6a3ede892e6ef80c779e5587 Mon Sep 17 00:00:00 2001 From: syeopite <70992037+syeopite@users.noreply.github.com> Date: Mon, 24 May 2021 06:36:14 -0700 Subject: [PATCH 06/11] Bump version --- shard.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shard.yml b/shard.yml index 1c18324..d881c30 100644 --- a/shard.yml +++ b/shard.yml @@ -1,13 +1,14 @@ name: protodec -version: 0.1.3 +version: 0.1.4 authors: - Omar Roth + - Invidous team targets: protodec: main: src/protodec.cr -crystal: 0.34.0 +crystal: ">= 0.34.0, < 2.0.0" license: GPLv3 From 7de78da0f87f9a111a7fd5f1c894d5409879596c Mon Sep 17 00:00:00 2001 From: TheFrenchGhosty <47571719+TheFrenchGhosty@users.noreply.github.com> Date: Wed, 11 Aug 2021 17:39:38 +0200 Subject: [PATCH 07/11] Add a section about windows --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a2e74c9..0f752df 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,10 @@ $ echo 'CkEKCeOCj+OBn+OBlxDSCSIQWmQ730+N8z8tsp3vp8YJQCoSCAESBzA4MDAwMDAaBQ26sSZE } ``` +## Windows + +Windows users can run the binaries in a linux-on-windows tool (like Git bash or WSL) or use the official [protobuf binaries](https://github.com/protocolbuffers/protobuf/releases) to encode/decode protobuf data. + ## Contributing 1. Fork it () From 618a336060268a6cfeeba679cad52a394ede5a3f Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Mon, 29 Nov 2021 22:52:01 +0100 Subject: [PATCH 08/11] Update README.md --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f752df..8c55536 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,30 @@ Command-line tool to encode and decode arbitrary protobuf data. + +## Installation + +This pragram requires Crystal. See: https://crystal-lang.org/install/ + +### Standalone + +1. Clone: `git clone https://github.com/iv-org/protodec && cd protodec` +2. Build: `crystal build src/protodec.cr` +3. See [Usage](#Usage) below + + +### As a Crystal library + +Add this to your application's `shard.yml`: + +```yaml +dependencies: + protodec: + github: iv-org/protodec + version: ~> 0.1.4 +``` + + ## Usage ``` @@ -63,7 +87,7 @@ Windows users can run the binaries in a linux-on-windows tool (like Git bash or ## Contributing -1. Fork it () +1. Fork it () 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) From 11813ae3634fead724c7b484466ff350b770867a Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Mon, 29 Nov 2021 22:52:47 +0100 Subject: [PATCH 09/11] Fix typo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c55536..87cbd58 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Command-line tool to encode and decode arbitrary protobuf data. ## Installation -This pragram requires Crystal. See: https://crystal-lang.org/install/ +This program requires Crystal. See: https://crystal-lang.org/install/ ### Standalone From c6cede69e680c83a405573c500142605c27d21b0 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 1 Dec 2022 00:07:22 +0100 Subject: [PATCH 10/11] cast_json: enforce param type at compile time --- src/protodec/utils.cr | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/protodec/utils.cr b/src/protodec/utils.cr index b65a43c..6c7c509 100644 --- a/src/protodec/utils.cr +++ b/src/protodec/utils.cr @@ -468,9 +468,7 @@ module Protodec Any.new(raw.clone) end - def self.cast_json(object) - raise "Invalid type" if !object.is_a?(Hash) - + def self.cast_json(object : Hash) JSON::Any.new(object.transform_values do |value| case value when .is_a?(Hash) From 9e02d88a19f7b948877f0650297dad4949188e52 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 1 Dec 2022 00:08:30 +0100 Subject: [PATCH 11/11] Release v0.1.5 --- README.md | 2 +- shard.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87cbd58..9f39ba7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Add this to your application's `shard.yml`: dependencies: protodec: github: iv-org/protodec - version: ~> 0.1.4 + version: ~> 0.1.5 ``` diff --git a/shard.yml b/shard.yml index d881c30..33c49db 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: protodec -version: 0.1.4 +version: 0.1.5 authors: - Omar Roth