From b5f48afadfcb4a5b48b468db9669a44122856c47 Mon Sep 17 00:00:00 2001 From: Idan Date: Sun, 19 Feb 2023 11:01:56 +0200 Subject: [PATCH 1/7] version 2.1.2-SNAPSHOT --- README.md | 2 +- project.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b00117c..8f2e346 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ ignored completely. ## Installation Add a dependency to your `project.clj` file: - [com.appsflyer/pronto "2.1.0"] + [com.appsflyer/pronto "2.1.1"] Note that the library comes with no Java protobuf dependencies of its own and they are expected to be provided by consumers of the library, with a minimal version of `3.9.0`. diff --git a/project.clj b/project.clj index 96dbfba..2035481 100644 --- a/project.clj +++ b/project.clj @@ -1,7 +1,7 @@ (def protobuf-version "3.9.0") -(defproject com.appsflyer/pronto "2.1.1" +(defproject com.appsflyer/pronto "2.1.2-SNAPSHOT" :description "clojure support for protocol buffers" :url "https://github.com/AppsFlyer/pronto" :license {:name "Eclipse Public License" From b6f68287e19fbe5458ff28714d1a410279b3aa89 Mon Sep 17 00:00:00 2001 From: Matthew Molloy Date: Tue, 11 Apr 2023 06:58:13 +0900 Subject: [PATCH 2/7] bump lein-protodeps --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 2035481..c2d3408 100644 --- a/project.clj +++ b/project.clj @@ -16,7 +16,7 @@ :username :env/clojars_username :password :env/clojars_password}]] - :plugins [[com.appsflyer/lein-protodeps "1.0.1"] + :plugins [[com.appsflyer/lein-protodeps "1.0.5"] [lein-codox "0.10.7"]] :dependencies [[org.clojure/clojure "1.10.1"] From eeed7fc34a5765d6b9d2a6826da954c27181a603 Mon Sep 17 00:00:00 2001 From: "ran.solash" Date: Fri, 9 Jun 2023 13:47:19 +0300 Subject: [PATCH 3/7] unrecognized-kw --- project.clj | 2 +- src/clj/pronto/wrapper.clj | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/project.clj b/project.clj index 2035481..45d0869 100644 --- a/project.clj +++ b/project.clj @@ -1,7 +1,7 @@ (def protobuf-version "3.9.0") -(defproject com.appsflyer/pronto "2.1.2-SNAPSHOT" +(defproject com.appsflyer/pronto "2.1.3-SNAPSHOT" :description "clojure support for protocol buffers" :url "https://github.com/AppsFlyer/pronto" :license {:name "Eclipse Public License" diff --git a/src/clj/pronto/wrapper.clj b/src/clj/pronto/wrapper.clj index d105b63..e59e341 100644 --- a/src/clj/pronto/wrapper.clj +++ b/src/clj/pronto/wrapper.clj @@ -84,20 +84,21 @@ (defmethod gen-wrapper :enum [^Class clazz ctx] - (let [values (reflect/enum-values clazz) - enum-value-fn (or (:enum-value-fn ctx) identity) - enum->kw (map-indexed #(vector %1 (keyword (enum-value-fn (.getName ^Descriptors$EnumValueDescriptor %2)))) - values) - kw->enum (map #(vector (keyword (enum-value-fn (.getName ^Descriptors$EnumValueDescriptor %1))) - (symbol (str (.getName clazz) "/" (.getName ^Descriptors$EnumValueDescriptor %1)))) - values)] + (let [values (reflect/enum-values clazz) + enum-value-fn (or (:enum-value-fn ctx) identity) + enum->kw (map-indexed #(vector %1 (keyword (enum-value-fn (.getName ^Descriptors$EnumValueDescriptor %2)))) + values) + kw->enum (map #(vector (keyword (enum-value-fn (.getName ^Descriptors$EnumValueDescriptor %1))) + (symbol (str (.getName clazz) "/" (.getName ^Descriptors$EnumValueDescriptor %1)))) + values) + unrecognized-kw (-> "UNRECOGNIZED" enum-value-fn keyword)] (reify Wrapper (wrap [_ v] `(case (.ordinal ~(u/with-type-hint v clazz)) ~@(interleave (map first enum->kw) (map second enum->kw)) - (throw (IllegalArgumentException. (str "can't wrap " ~v))))) + ~unrecognized-kw)) (unwrap [_ v] (let [v2 (gensym 'v)] From c7a196704da0c434ee3fe86b651b4b1d29c727d5 Mon Sep 17 00:00:00 2001 From: "ran.solash" Date: Sun, 25 Jun 2023 17:18:12 +0300 Subject: [PATCH 4/7] testing --- resources/proto/versioning.proto | 56 +++++++++++++++++++++++++++++++ test/pronto/versioning_test.clj | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 resources/proto/versioning.proto create mode 100644 test/pronto/versioning_test.clj diff --git a/resources/proto/versioning.proto b/resources/proto/versioning.proto new file mode 100644 index 0000000..c671f93 --- /dev/null +++ b/resources/proto/versioning.proto @@ -0,0 +1,56 @@ +syntax = "proto3"; + +package protogen.generated; + +import "google/protobuf/wrappers.proto"; + +enum E1 { + E1_VAL1 = 0; + E1_VAL2 = 1; +} + +message V1 { + string a1 = 1; + int32 a2 = 2; + E1 a3 = 3; + oneof thing { + uint32 num = 23; + string str = 24; + Inner person = 25; + } +} + +enum E2 { + E2_VAL1 = 0; + E2_VAL2 = 1; + E2_VAL3 = 2; +} + +message Inner { + uint64 c = 1; +} + +message V2 { + string a1 = 1; + int32 a2 = 2; + E2 a3 = 3; + + string b1 = 9; + int32 b2 = 10; + Inner b3 = 11; + repeated Inner b4 = 12; + map b5 = 13; + google.protobuf.StringValue b6 = 14; + UUID b7 = 15; + + oneof thing { + uint32 num = 16; + string str = 17; + Inner person = 18; + float bb = 19; + } +} + +message UUID { + string value = 1; +} diff --git a/test/pronto/versioning_test.clj b/test/pronto/versioning_test.clj new file mode 100644 index 0000000..c9f5f0a --- /dev/null +++ b/test/pronto/versioning_test.clj @@ -0,0 +1,57 @@ +(ns pronto.versioning-test + (:require [clojure.test :refer :all] + [pronto.core :refer [defmapper] :as p] + [pronto.utils :as u]) + (:import (clojure.lang ExceptionInfo) + (java.util UUID) + [protogen.generated Versioning$V1 Versioning$V2 Versioning$UUID])) + +(defmapper mapper [Versioning$V1 Versioning$V2] + :key-name-fn u/->kebab-case + :enum-value-fn u/->kebab-case + :encoders {Versioning$UUID + {:from-proto #(try + (UUID/fromString (.getValue ^Versioning$UUID %)) + (catch Exception _)) + :to-proto #(let [b (Versioning$UUID/newBuilder)] + (.setValue b (str %)) + (.build b))}}) + +(deftest types-evolving-test + (let [v2 (p/proto-map mapper Versioning$V2 + :a1 "a1" + :a2 5 + :a3 :e2-val3 + :b1 "b1" + :b2 6 + :b3 {:c 7} + :b4 [{:c 8} {:c 9}] + :b5 {"q" {:c 10}} + :b6 "b6" + :b7 #uuid "61be663a-ff40-4199-8489-18da7546cb81" + :bb 11.11) + v1 (p/bytes->proto-map mapper Versioning$V1 (p/proto-map->bytes v2))] + (testing "get fields" + (is (= (:a1 v1) "a1")) + (is (= (:a2 v1) 5)) + (is (= (:a3 v1) :unrecognized)) + (is (nil? (p/which-one-of v1 :thing))) + (is (nil? (p/one-of v1 :thing)))) + + (testing "set fields with legal value" + (is (= (assoc v1 + :a1 "a11" + :a2 55 + :a3 :e1-val2 + :num 777) + {:a1 "a11" :a2 55 :a3 :e1-val2 :num 777 :str "" :person nil}))) + + (testing "set fields with illegal value" + (is (thrown? ExceptionInfo + (assoc v1 :a3 :unrecognized)))) + + (testing "new->old->new unknown fields are preserved") + (is (= (->> (assoc v1 :a1 "a22") + p/proto-map->bytes + (p/bytes->proto-map mapper Versioning$V2)) + (assoc v2 :a1 "a22"))))) From 4fcd7fdc2f09f1498470cdcf1fc54b5bbbae5ed9 Mon Sep 17 00:00:00 2001 From: "ran.solash" Date: Mon, 26 Jun 2023 05:15:42 +0300 Subject: [PATCH 5/7] testing --- test/pronto/versioning_test.clj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/pronto/versioning_test.clj b/test/pronto/versioning_test.clj index c9f5f0a..a3434b9 100644 --- a/test/pronto/versioning_test.clj +++ b/test/pronto/versioning_test.clj @@ -50,8 +50,8 @@ (is (thrown? ExceptionInfo (assoc v1 :a3 :unrecognized)))) - (testing "new->old->new unknown fields are preserved") - (is (= (->> (assoc v1 :a1 "a22") - p/proto-map->bytes - (p/bytes->proto-map mapper Versioning$V2)) - (assoc v2 :a1 "a22"))))) + (testing "new->old->new unknown fields are preserved" + (is (= (->> (assoc v1 :a1 "a22") + p/proto-map->bytes + (p/bytes->proto-map mapper Versioning$V2)) + (assoc v2 :a1 "a22")))))) From ef8e599f274dd28767d456b6f41864fb382ba49e Mon Sep 17 00:00:00 2001 From: Idan Date: Mon, 26 Jun 2023 21:53:42 +0300 Subject: [PATCH 6/7] release version 2.1.2 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 3dd7b4b..9365dfb 100644 --- a/project.clj +++ b/project.clj @@ -1,7 +1,7 @@ (def protobuf-version "3.9.0") -(defproject com.appsflyer/pronto "2.1.3-SNAPSHOT" +(defproject com.appsflyer/pronto "2.1.2" :description "clojure support for protocol buffers" :url "https://github.com/AppsFlyer/pronto" :license {:name "Eclipse Public License" From 0974bc161dd67a5ea75b9c0384b7a2c3ec1a98b8 Mon Sep 17 00:00:00 2001 From: Idan Date: Mon, 26 Jun 2023 22:14:23 +0300 Subject: [PATCH 7/7] adding changelog and updating readme --- CHANGELOG.md | 9 +++++++++ README.md | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f33d1f2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +## This library follows [Semantic Versioning](https://semver.org). +## This CHANGELOG follows [keepachangelog](https://keepachangelog.com/en/1.0.0/). + +### VERSION [2.1.2]: +#### Changed +* return `:unrecognized` for unknown enum values in order to support forward compatibility. + +#### Added +* CHANGELOG.md file diff --git a/README.md b/README.md index 8f2e346..22b71be 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ ignored completely. ## Installation Add a dependency to your `project.clj` file: - [com.appsflyer/pronto "2.1.1"] + [com.appsflyer/pronto "2.1.2"] Note that the library comes with no Java protobuf dependencies of its own and they are expected to be provided by consumers of the library, with a minimal version of `3.9.0`.