Class: Restate::TypeSerde

Inherits:
Object
  • Object
show all
Defined in:
lib/restate/serde.rb

Overview

Serde wrapper for primitive types and classes with a .json_schema method. Delegates serialize/deserialize to JsonSerde, adds schema.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, schema) ⇒ TypeSerde

Create a TypeSerde for the given type with a precomputed JSON Schema.



154
155
156
157
# File 'lib/restate/serde.rb', line 154

def initialize(type, schema)
  @type_class = type
  @schema = schema
end

Instance Attribute Details

#type_classObject (readonly)

Returns the value of attribute type_class.



151
152
153
# File 'lib/restate/serde.rb', line 151

def type_class
  @type_class
end

Instance Method Details

#deserialize(buf) ⇒ Object

Deserialize JSON bytes to a Ruby object via JsonSerde.



165
166
167
# File 'lib/restate/serde.rb', line 165

def deserialize(buf)
  JsonSerde.deserialize(buf)
end

#json_schemaObject

Return the JSON Schema for this type.



170
171
172
# File 'lib/restate/serde.rb', line 170

def json_schema
  @schema
end

#serialize(obj) ⇒ Object

Serialize a Ruby object to JSON bytes via JsonSerde.



160
161
162
# File 'lib/restate/serde.rb', line 160

def serialize(obj)
  JsonSerde.serialize(obj)
end