Class: SchemaRegistry::Schema::ProtoJsonSchema

Inherits:
Base
  • Object
show all
Defined in:
lib/schema_registry_client/schema/proto_json_schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#dependencies

Class Method Details

.schema_typeObject



9
10
11
# File 'lib/schema_registry_client/schema/proto_json_schema.rb', line 9

def self.schema_type
  "JSON"
end

Instance Method Details

#decode(stream, _schema_text) ⇒ Object



22
23
24
25
# File 'lib/schema_registry_client/schema/proto_json_schema.rb', line 22

def decode(stream, _schema_text)
  json = stream.read
  JSON.parse(json)
end

#encode(message, stream, schema_name: nil) ⇒ Object



17
18
19
20
# File 'lib/schema_registry_client/schema/proto_json_schema.rb', line 17

def encode(message, stream, schema_name: nil)
  json = message.to_h.sort.to_h.to_json
  stream.write(json)
end

#schema_text(message, schema_name: nil) ⇒ Object



13
14
15
# File 'lib/schema_registry_client/schema/proto_json_schema.rb', line 13

def schema_text(message, schema_name: nil)
  SchemaRegistry::Output::JsonSchema.output(message.class.descriptor.to_proto)
end