protobuf_nested_struct 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bae6c6d57359ec2a06c717c132da705bec0f569e
4
+ data.tar.gz: 0d11b7bc9dc5ef4a4a10808c33bfc56ba7405e91
5
+ SHA512:
6
+ metadata.gz: 9d506d70254b800a612076f2f5bfd12b12980bd58f479963fe51315e321b1e6e31177a372fe358ea291339900b85f8147f5dc76d46eb75e5bcf9141b9f4eabaf
7
+ data.tar.gz: 817930eb2167b5d9f37c1e205b59292cc18b199383ecd0006aa1135ac064b56db27229fec5c33ca8264931ed86b813cf0ae3bc18b1301d8279a4e6327a54f7fb
@@ -0,0 +1,12 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ macos:
5
+ xcode: "9.3.0"
6
+ steps:
7
+ - checkout
8
+ - run:
9
+ name: install+mutate
10
+ command: bundle install && bundle exec mutant --include lib --require protobuf_nested_struct --use rspec ProtobufNestedStruct*
11
+ environment:
12
+ ARCHFLAGS: "-arch x86_64"
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ - 2.4.3
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in protobuf-nested-struct.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # ProtobufNestedStruct
2
+
3
+ Serialize your primitives, arrays and hashes using protobuf. Supports nested arrays and hashes.
4
+
5
+ Supported types:
6
+
7
+ * nil
8
+ * integer
9
+ * float
10
+ * boolean
11
+ * string
12
+ * date
13
+ * time
14
+ * hash (keys must be strings, values' types must be on this list)
15
+ * array (elements' types must be on this list)
16
+
17
+ Inspired by `google/protobuf/struct.proto` but it can additionally handle Date, Time and Integer values.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'protobuf_nested_struct'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install protobuf_nested_struct
34
+
35
+ ## Usage
36
+
37
+ ```ruby
38
+ # store the serialized binary string in DB or send over network
39
+ serialized = ProtobufNestedStruct.dump(v)
40
+
41
+
42
+ # receive de-serialized binary string from DB or network
43
+ copy = ProtobufNestedStruct.load(serialized)
44
+
45
+ expect(copy).to eql(obj)
46
+ ```
47
+
48
+ where `obj` can be an instance of one of the supported types.
49
+
50
+ ## Development
51
+
52
+ * `bundle install`
53
+ * `bundle exec rspec`
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/arkency/protobuf-nested-struct
58
+
59
+ ## Credits
60
+
61
+ * https://github.com/google/protobuf/blob/07b9238a1c03ef0351bcb4ca57d773eb7b7c5824/src/google/protobuf/struct.proto
62
+ * https://github.com/google/protobuf/blob/9497a657d577ebda0272711651c3dcdda3a4ac35/ruby/lib/google/protobuf/well_known_types.rb#L149
63
+ * https://github.com/google/protobuf/blob/9497a657d577ebda0272711651c3dcdda3a4ac35/ruby/tests/well_known_types_test.rb#L35
64
+
65
+ ## About
66
+
67
+ <img src="https://arkency.com/images/arkency.png" alt="Arkency" width="60px" align="left" />
68
+
69
+ This repository is funded and maintained by [Arkency](https://arkency.com). Check out our other [open-source projects](https://github.com/arkency), especially [Rails Event Store](https://github.com/RailsEventStore).
70
+
71
+ Consider [hiring us](https://arkency.com/hire-us) to grow your Ruby/Rails apps and business. Make sure to check out [our blog](https://blog.arkency.com).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "protobuf_nested_struct"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,45 @@
1
+ // Copyright 2016 Google Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ syntax = "proto3";
16
+
17
+ package google.type;
18
+
19
+ option cc_enable_arenas = true;
20
+ option go_package = "google.golang.org/genproto/googleapis/type/date;date";
21
+ option java_multiple_files = true;
22
+ option java_outer_classname = "DateProto";
23
+ option java_package = "com.google.type";
24
+ option objc_class_prefix = "GTP";
25
+
26
+
27
+ // Represents a whole calendar date, e.g. date of birth. The time of day and
28
+ // time zone are either specified elsewhere or are not significant. The date
29
+ // is relative to the Proleptic Gregorian Calendar. The day may be 0 to
30
+ // represent a year and month where the day is not significant, e.g. credit card
31
+ // expiration date. The year may be 0 to represent a month and day independent
32
+ // of year, e.g. anniversary date. Related types are [google.type.TimeOfDay][google.type.TimeOfDay]
33
+ // and `google.protobuf.Timestamp`.
34
+ message Date {
35
+ // Year of date. Must be from 1 to 9999, or 0 if specifying a date without
36
+ // a year.
37
+ int32 year = 1;
38
+
39
+ // Month of year. Must be from 1 to 12.
40
+ int32 month = 2;
41
+
42
+ // Day of month. Must be from 1 to 31 and valid for the year and month, or 0
43
+ // if specifying a year/month where the day is not significant.
44
+ int32 day = 3;
45
+ }
@@ -0,0 +1,18 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: date.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "google.type.Date" do
8
+ optional :year, :int32, 1
9
+ optional :month, :int32, 2
10
+ optional :day, :int32, 3
11
+ end
12
+ end
13
+
14
+ module Google
15
+ module Type
16
+ Date = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.type.Date").msgclass
17
+ end
18
+ end
@@ -0,0 +1,102 @@
1
+ require 'date'
2
+ require 'google/protobuf'
3
+ require 'google/protobuf/well_known_types'
4
+
5
+ require 'protobuf_nested_struct/version'
6
+ require 'protobuf_nested_struct/struct_pb'
7
+
8
+ module ProtobufNestedStruct
9
+ class Value
10
+ def from_ruby(obj)
11
+ case obj
12
+ when nil
13
+ self.null_value = 0
14
+ when Integer
15
+ self.int_value = obj
16
+ when Float
17
+ self.double_value = obj
18
+ when String
19
+ self.string_value = obj
20
+ when TrueClass, FalseClass
21
+ self.bool_value = obj
22
+ when Date
23
+ self.date_value = Google::Type::Date.new(day: obj.day, month: obj.month, year: obj.year)
24
+ when Time
25
+ self.timestamp_value = Google::Protobuf::Timestamp.new.tap{|gpt| gpt.from_time(obj) }
26
+ when Hash
27
+ self.string_map_value = HashMapStringValue.new.tap{|ps| ps.from_ruby(obj) }
28
+ when Array
29
+ self.list_value = ListValue.new.tap{|ps| ps.from_ruby(obj) }
30
+ else
31
+ raise ArgumentError, "not allowed: #{obj.inspect}"
32
+ end
33
+ end
34
+
35
+ def to_ruby
36
+ case kind
37
+ when :null_value
38
+ nil
39
+ when :int_value
40
+ int_value
41
+ when :double_value
42
+ double_value
43
+ when :string_value
44
+ string_value
45
+ when :bool_value
46
+ bool_value
47
+ when :date_value
48
+ Date.new(date_value.year, date_value.month, date_value.day)
49
+ when :timestamp_value
50
+ timestamp_value.to_time
51
+ when :string_map_value
52
+ string_map_value.to_ruby
53
+ when :list_value
54
+ list_value.to_ruby
55
+ else
56
+ raise ArgumentError
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ class HashMapStringValue
63
+ def from_ruby(obj)
64
+ Hash === obj or raise ArgumentError
65
+ obj.each do |key, value|
66
+ fields[key] ||= Value.new
67
+ fields[key].from_ruby(value)
68
+ end
69
+ end
70
+
71
+ def to_ruby
72
+ fields.each_with_object({}) do |(key, value), hash|
73
+ hash[key] = value.to_ruby
74
+ end
75
+ end
76
+ end
77
+
78
+ class ListValue
79
+ def from_ruby(obj)
80
+ Array === obj or raise ArgumentError
81
+ values.clear
82
+ obj.each do |value|
83
+ values << Value.new.tap{|v| v.from_ruby(value) }
84
+ end
85
+ end
86
+
87
+ def to_ruby
88
+ values.map{|v| v.to_ruby }
89
+ end
90
+ end
91
+
92
+ def self.dump(obj)
93
+ v = Value.new
94
+ v.from_ruby(obj)
95
+ Value.encode(v)
96
+ end
97
+
98
+ def self.load(string)
99
+ v = Value.decode(string)
100
+ v.to_ruby
101
+ end
102
+ end
@@ -0,0 +1,32 @@
1
+ syntax = "proto3";
2
+ import "google/protobuf/timestamp.proto";
3
+ import "google/type/date.proto";
4
+ package protobuf_nested_struct;
5
+
6
+ message HashMapStringValue {
7
+ map<string, Value> fields = 1;
8
+ }
9
+
10
+ message Value {
11
+ oneof kind {
12
+ NullValue null_value = 1;
13
+ double double_value = 2;
14
+ int64 int_value = 3;
15
+ string string_value = 4;
16
+ bool bool_value = 5;
17
+
18
+ google.type.Date date_value = 6;
19
+ google.protobuf.Timestamp timestamp_value = 7;
20
+
21
+ HashMapStringValue string_map_value = 20;
22
+ ListValue list_value = 21;
23
+ }
24
+ }
25
+
26
+ enum NullValue {
27
+ NULL_VALUE = 0;
28
+ }
29
+
30
+ message ListValue {
31
+ repeated Value values = 1;
32
+ }
@@ -0,0 +1,38 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: struct.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/timestamp_pb'
7
+ require 'google/type/date_pb'
8
+ Google::Protobuf::DescriptorPool.generated_pool.build do
9
+ add_message "protobuf_nested_struct.HashMapStringValue" do
10
+ map :fields, :string, :message, 1, "protobuf_nested_struct.Value"
11
+ end
12
+ add_message "protobuf_nested_struct.Value" do
13
+ oneof :kind do
14
+ optional :null_value, :enum, 1, "protobuf_nested_struct.NullValue"
15
+ optional :double_value, :double, 2
16
+ optional :int_value, :int64, 3
17
+ optional :string_value, :string, 4
18
+ optional :bool_value, :bool, 5
19
+ optional :date_value, :message, 6, "google.type.Date"
20
+ optional :timestamp_value, :message, 7, "google.protobuf.Timestamp"
21
+ optional :string_map_value, :message, 20, "protobuf_nested_struct.HashMapStringValue"
22
+ optional :list_value, :message, 21, "protobuf_nested_struct.ListValue"
23
+ end
24
+ end
25
+ add_message "protobuf_nested_struct.ListValue" do
26
+ repeated :values, :message, 1, "protobuf_nested_struct.Value"
27
+ end
28
+ add_enum "protobuf_nested_struct.NullValue" do
29
+ value :NULL_VALUE, 0
30
+ end
31
+ end
32
+
33
+ module ProtobufNestedStruct
34
+ HashMapStringValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.HashMapStringValue").msgclass
35
+ Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.Value").msgclass
36
+ ListValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.ListValue").msgclass
37
+ NullValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("protobuf_nested_struct.NullValue").enummodule
38
+ end
@@ -0,0 +1,3 @@
1
+ module ProtobufNestedStruct
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "protobuf_nested_struct/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "protobuf_nested_struct"
8
+ spec.version = ProtobufNestedStruct::VERSION
9
+ spec.authors = ["Robert Pankowecki", "Arkency"]
10
+ spec.email = ["dev@arkency.com"]
11
+
12
+ spec.summary = %q{Serialize primitives and deep structures (array, hash) to protobuf}
13
+ spec.description = %q{Serialize primitives and deep structures (array, hash) to protobuf}
14
+ spec.homepage = "https://github.com/arkency/protobuf-nested-struct"
15
+ spec.metadata = {
16
+ "homepage_uri" => "https://github.com/arkency/protobuf-nested-struct",
17
+ "changelog_uri" => "https://github.com/arkency/protobuf-nested-struct/releases",
18
+ "source_code_uri" => "https://github.com/arkency/protobuf-nested-struct",
19
+ "bug_tracker_uri" => "https://github.com/arkency/protobuf-nested-struct/issues",
20
+ }
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{^(test|spec|features)/})
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ spec.add_dependency "google-protobuf"
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.16"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "mutant-rspec"
35
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: protobuf_nested_struct
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Pankowecki
8
+ - Arkency
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2018-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: google-protobuf
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.16'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.16'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: mutant-rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Serialize primitives and deep structures (array, hash) to protobuf
99
+ email:
100
+ - dev@arkency.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".circleci/config.yml"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/google/type/date.proto
115
+ - lib/google/type/date_pb.rb
116
+ - lib/protobuf_nested_struct.rb
117
+ - lib/protobuf_nested_struct/struct.proto
118
+ - lib/protobuf_nested_struct/struct_pb.rb
119
+ - lib/protobuf_nested_struct/version.rb
120
+ - protobuf_nested_struct.gemspec
121
+ homepage: https://github.com/arkency/protobuf-nested-struct
122
+ licenses: []
123
+ metadata:
124
+ homepage_uri: https://github.com/arkency/protobuf-nested-struct
125
+ changelog_uri: https://github.com/arkency/protobuf-nested-struct/releases
126
+ source_code_uri: https://github.com/arkency/protobuf-nested-struct
127
+ bug_tracker_uri: https://github.com/arkency/protobuf-nested-struct/issues
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.6.13
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Serialize primitives and deep structures (array, hash) to protobuf
148
+ test_files: []