thrift-base64 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90c0d60e32a5487e5b62c5b8a3b4444250d1e8a4
4
- data.tar.gz: 5636b4ccb3c931c8ac51f8d230d668df1ab9f92a
3
+ metadata.gz: 353e1b31954aceb268bf108ab4edc268fc6dc20b
4
+ data.tar.gz: fd80998b5498e748e381c207c0118150d1d6340b
5
5
  SHA512:
6
- metadata.gz: 22d6158b32d9a19cdc56fa5399c969fcd6df0fac94478ab3214a2d00af82070834f14beadb380ce3edff8eca4ca6be3b459b32c8dcf781368342979aecb9b51a
7
- data.tar.gz: 871a51715bb4c86d4b2706948c1e01d9b3832de89370cece4b37f1c3dc98eb266d0a5a847fb32e95030fac49b43118f968cb32f4101295abf09e68c9bf41e3ef
6
+ metadata.gz: 5c2795ff3536a4633e110bb1e3a20f7ff42293a4e6acb0d49b0a344115e32a07d5b9183e3683de7e327b33f1358e58c4588dd69f975383187a203925586e6b4f
7
+ data.tar.gz: 0aebced38795b1201bde45b6df48bb5a8dbd479ca70526d0ed659a8b91ea1186cb7693ee395a01519f90ba38b757aa0e7f399a56b873cb136e29be2bc7f9fc6c
data/README.md CHANGED
@@ -58,7 +58,7 @@ protocols. Just check out the benchmarks below.
58
58
  YAML/Binary: 6118.3 i/s - 5.96x slower
59
59
  YAML/YAML String: 3636.5 i/s - 10.03x slower
60
60
 
61
- These benchmarks are included in [benchmark/][benchmark/].
61
+ These benchmarks are included in [benchmark/](benchmark/).
62
62
 
63
63
  ## Installation
64
64
 
@@ -80,8 +80,7 @@ Or install it yourself as:
80
80
 
81
81
  `thrift-base64` adds two classes to the `Thrift` module:
82
82
  `Thrift::Base64Derserializer` & `Thrift::Base64Serializer`. They mimic the
83
- interface of `Thirft::Deserializer` & `Thrift::Serializer` except they
84
- require no arguments to `initialize`. Here's an example:
83
+ interface of `Thirft::Deserializer` & `Thrift::Serializer`.
85
84
 
86
85
  ```ruby
87
86
  require 'thrift-base64'
@@ -49,4 +49,16 @@ module Thrift
49
49
  to_base64 CompactProtocolFactory.new
50
50
  end
51
51
  end
52
+
53
+ class Union
54
+ extend Base64Extension::FromBase64
55
+
56
+ def to_base64(protocol = BinaryProtocolFactory.new)
57
+ Base64Serializer.new(protocol).serialize self
58
+ end
59
+
60
+ def to_compact_base64
61
+ to_base64 CompactProtocolFactory.new
62
+ end
63
+ end
52
64
  end
@@ -1,5 +1,5 @@
1
1
  module Thrift
2
2
  module Base64
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -1,3 +1,8 @@
1
1
  struct SimpleStruct {
2
2
  1: required string message
3
3
  }
4
+
5
+ union SimpleUnion {
6
+ 1: string foo
7
+ 2: string bar
8
+ }
@@ -52,6 +52,16 @@ class AcceptanceTest < MiniTest::Unit::TestCase
52
52
  assert_equal struct.message, deserialized.message
53
53
  end
54
54
 
55
+ def test_works_with_unions
56
+ union = SimpleUnion.new foo: 'set'
57
+
58
+ roundtripped = SimpleUnion.from_base64(union.to_base64)
59
+ assert_equal union.foo, roundtripped.foo
60
+
61
+ roundtripped = SimpleUnion.from_compact_base64(union.to_compact_base64)
62
+ assert_equal union.foo, roundtripped.foo
63
+ end
64
+
55
65
  private
56
66
 
57
67
  def assert_utf8(string)
@@ -23,3 +23,32 @@ class SimpleStruct
23
23
  ::Thrift::Struct.generate_accessors self
24
24
  end
25
25
 
26
+ class SimpleUnion < ::Thrift::Union
27
+ include ::Thrift::Struct_Union
28
+ class << self
29
+ def foo(val)
30
+ SimpleUnion.new(:foo, val)
31
+ end
32
+
33
+ def bar(val)
34
+ SimpleUnion.new(:bar, val)
35
+ end
36
+ end
37
+
38
+ FOO = 1
39
+ BAR = 2
40
+
41
+ FIELDS = {
42
+ FOO => {:type => ::Thrift::Types::STRING, :name => 'foo'},
43
+ BAR => {:type => ::Thrift::Types::STRING, :name => 'bar'}
44
+ }
45
+
46
+ def struct_fields; FIELDS; end
47
+
48
+ def validate
49
+ raise(StandardError, 'Union fields are not set.') if get_set_field.nil? || get_value.nil?
50
+ end
51
+
52
+ ::Thrift::Union.generate_accessors self
53
+ end
54
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrift-base64
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ahawkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thrift