Class: Bare
- Inherits:
-
Object
- Object
- Bare
- Defined in:
- lib/bare-rb.rb
Class Method Summary collapse
- .Array(*opts) ⇒ Object
- .ArrayFixedLen(*opts) ⇒ Object
- .Bool ⇒ Object
- .Data ⇒ Object
- .DataFixedLen(*opts) ⇒ Object
- .decode(msg, schema, type = nil) ⇒ Object
- .encode(msg, schema, type = nil) ⇒ Object
- .Enum(*opts) ⇒ Object
- .F32 ⇒ Object
- .F64 ⇒ Object
-
.generative_test(schema_path = nil, binary_path = nil) ⇒ Object
Returns a schema and a binary input optionally write these to files.
- .I16 ⇒ Object
- .I32 ⇒ Object
- .I64 ⇒ Object
- .I8 ⇒ Object
-
.Int ⇒ Object
These classes are wrapped in methods for ergonomics.
- .Map(*opts) ⇒ Object
- .Optional(*opts) ⇒ Object
- .parse_schema(path) ⇒ Object
- .Schema(hash) ⇒ Object
- .String ⇒ Object
- .Struct(*opts) ⇒ Object
- .U16 ⇒ Object
- .U32 ⇒ Object
- .U64 ⇒ Object
- .U8 ⇒ Object
- .Uint ⇒ Object
- .Union(*opts) ⇒ Object
- .Void ⇒ Object
Class Method Details
.Array(*opts) ⇒ Object
153 154 155 |
# File 'lib/bare-rb.rb', line 153 def self.Array(*opts) return BareTypes::Array.new(*opts) end |
.ArrayFixedLen(*opts) ⇒ Object
157 158 159 |
# File 'lib/bare-rb.rb', line 157 def self.ArrayFixedLen(*opts) return BareTypes::ArrayFixedLen.new(*opts) end |
.Bool ⇒ Object
145 146 147 |
# File 'lib/bare-rb.rb', line 145 def self.Bool return BareTypes::Bool.new end |
.Data ⇒ Object
137 138 139 |
# File 'lib/bare-rb.rb', line 137 def self.Data return BareTypes::Data.new end |
.DataFixedLen(*opts) ⇒ Object
133 134 135 |
# File 'lib/bare-rb.rb', line 133 def self.DataFixedLen(*opts) return BareTypes::DataFixedLen.new(*opts) end |
.decode(msg, schema, type = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bare-rb.rb', line 24 def self.decode(msg, schema, type = nil) if schema.is_a?(BareTypes::Schema) raise NoTypeProvided.new("To decode with a schema as opposed to a raw type you must specify which type in the same you want to encode as a symbol.\nBare.encode(msg, schema, :Type)") if type.nil? value, _ = schema[type].decode(msg) value else value, _ = schema.decode(msg) value end end |
.encode(msg, schema, type = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bare-rb.rb', line 10 def self.encode(msg, schema, type = nil) buffer = "".b if schema.is_a?(BareTypes::Schema) raise NoTypeProvided.new("To encode with a schema as opposed to a raw type you must specify which type in the schema you want to encode as a symbol.\nBare.encode(msg, schema, :Type)") if type.nil? unless schema.types.include?(type) raise("#{type} is not a type found in this schema. Choose from #{schema.types.keys}") end schema[type].encode(msg, buffer) else schema.encode(msg, buffer) end buffer end |
.Enum(*opts) ⇒ Object
161 162 163 |
# File 'lib/bare-rb.rb', line 161 def self.Enum(*opts) return BareTypes::Enum.new(*opts) end |
.generative_test(schema_path = nil, binary_path = nil) ⇒ Object
Returns a schema and a binary input optionally write these to files
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bare-rb.rb', line 37 def self.generative_test(schema_path=nil, binary_path=nil) schema = BareTypes::Schema.make input = schema.create_input key = schema.types.keys[0] binary = Bare.encode(input[key], schema, key) unless binary_path.nil? file = File.open(binary_path, 'wb+') file.write(binary) file.close end unless schema_path.nil? file = File.open(schema_path, 'w+') file.write(schema.to_s) file.close end return schema, binary, key end |
.I16 ⇒ Object
109 110 111 |
# File 'lib/bare-rb.rb', line 109 def self.I16 return BareTypes::I16.new end |
.I32 ⇒ Object
113 114 115 |
# File 'lib/bare-rb.rb', line 113 def self.I32 return BareTypes::I32.new end |
.I64 ⇒ Object
117 118 119 |
# File 'lib/bare-rb.rb', line 117 def self.I64 return BareTypes::I64.new end |
.Int ⇒ Object
These classes are wrapped in methods for ergonomics. Isn’t Bare.Array(Bare.U8) nicer than Bare::Array.new(Bare::U8.new)?
69 70 71 |
# File 'lib/bare-rb.rb', line 69 def self.Int return BareTypes::Int.new end |
.Map(*opts) ⇒ Object
125 126 127 |
# File 'lib/bare-rb.rb', line 125 def self.Map(*opts) return BareTypes::Map.new(*opts) end |
.Optional(*opts) ⇒ Object
121 122 123 |
# File 'lib/bare-rb.rb', line 121 def self.Optional(*opts) return BareTypes::Optional.new(*opts) end |
.parse_schema(path) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/bare-rb.rb', line 55 def self.parse_schema(path) # Hash of class names to BARE types # Eg. types['Customer'] == Bare.i32 parsed = parser(lexer(path)) Bare.Schema(parsed) end |
.Schema(hash) ⇒ Object
62 63 64 |
# File 'lib/bare-rb.rb', line 62 def self.Schema(hash) BareTypes::Schema.new(hash) end |
.String ⇒ Object
85 86 87 |
# File 'lib/bare-rb.rb', line 85 def self.String return BareTypes::String.new end |
.Struct(*opts) ⇒ Object
149 150 151 |
# File 'lib/bare-rb.rb', line 149 def self.Struct(*opts) return BareTypes::Struct.new(*opts) end |
.U64 ⇒ Object
101 102 103 |
# File 'lib/bare-rb.rb', line 101 def self.U64 return BareTypes::U64.new end |
.Uint ⇒ Object
141 142 143 |
# File 'lib/bare-rb.rb', line 141 def self.Uint return BareTypes::Uint.new end |