For reading Collections
These are implicit serializers/deserializers for common types that do not require the use of a macro to generate.
A ByteArrayOutputStream implementation optimized for writing binary serialized data (e.g.
A ByteArrayOutputStream implementation optimized for writing binary serialized data (e.g. Protocol Buffers).
Tries to avoid excessive memory allocations and array resizing by using an Array of Byte Arrays to represent the data. Supports directly appending Byte Arrays (zero-copy), writing length prefixed data, optimized writing of ASCII and UTF-8 strings without going through a java.io.Writer.
FIELD Input
FIELD Input
This the extra methods for reading FIELD input along with the NestedInput methods
FIELD Output
FIELD Output
See the documentation for Output
A specialized implementation for deserializing ImmutableArrays.
Generic Input trait to be implemented by Serialization Implementations
Generic Input trait to be implemented by Serialization Implementations
See the docs for Output for the distinction between RAW, NESTED, and FIELD Input/Output. The only difference for Input is that there aren't readNestedXXX() methods. Instead the way fields for objects are read is:
A Serializer/FieldSerializer for a Java Iterable
NESTED Input
NESTED Input
See documentation for Input/Output traits
NESTED Output
NESTED Output
See the documentation for Output
A combined Object Serializer/Deserializer that Serializes/Deserializes Objects from/to the same type
A combined Object Serializer/Deserializer that Serializes/Deserializes Objects from/to the same type
For deserializing Option types.
For deserializing Option types. Note: this does NOT allow Some(null)
Generic Output trait to be implemented by Serialization Implementations
Generic Output trait to be implemented by Serialization Implementations
There are 3 classes of outputs:
RAW Raw output is what you get if you serialize something by itself. Depending on the serialization implementation it will probably have an implicit length determined by the length of an Array[Byte], String, InputStream, etc. The starting point for serializing something it usually invoking one of the writeRawXXX(...) methods. The writeRawXXX(...) methods should be implemented by all serialization implementations.
NESTED Nested output is what we use when something is serialized as part of something else and may or may not be different than RAW output depending on the serialization implementation. For example, when serializing a collection each element would be serialized using the writeNestedXXX(...) methods. The nested format might have additional length information compared to the RAW format since there is no implicit length. For example, in protocol buffers a string/object/collection is prefixed with its length. Most serialization implementations can probably write optional length information followed by calling the corresponding writeRawXXX(...) method.
Another way to think about nested output is what we should be able to deserialize a NESTED value that is in the middle of an array of bytes (or a string or whatever). This means we need to know when to stop reading the value. For something like Protocol Buffers we will be prepending the length for string/object/repeated field or have a marker bit for varints to know when to stop. For something like JSON we will hit a double-quote (for strings) for a comma or closing brace (for all other types).
FIELD Field output is used when writing fields of an object. In addition to the value we are serializing it contains the name/number of the field in the object. Most implementations will probably write out the field name/number information followed by a call to the corresponding writeNestedXXX(...) method. Some implementations, such as Protocol Buffers, writes out the type of the field as part of the name/number which is why there isn't just a writeFieldName(...) which the framework would call automatically followed by the appropriate writeNestedXXX(...).
NOTE - Reading field output (via Input) is broken into a readFieldNumber() call to get the name/number of the field followed by calls to readNestedXXX().
Things are broken out this way to mainly support more complex formats (like Protocol Buffers). For something like a JSON implementation the RAW and NESTED formats will probably be the same. The way in which we write out JSON fields as part of an object will also be the same no matter what the type is unlike something like Protocol Buffers which needs to encode the type of field as part of the name/number of the field.
These are the default implicits for primitives
RAW Input
RAW Input
See documentation for Input/Output traits
RAW Output
RAW Output
See the documentation for Output
Usage Pattern:
Usage Pattern:
import fm.serializer.{SerializableCompanion, SerializableInstance, SimpleSerializer}
object Foo extends SerializableCompanion[Foo] { protected val serializer: SimpleSerializer[Foo] = makeSerializer[Foo] }
final case class Foo(bar: String) extends SerializableInstance[Foo] { protected def companion: SerializableCompanion[Foo] = Foo }
Usage Pattern:
Usage Pattern:
import fm.serializer.{SerializableCompanion, SerializableInstance, SimpleSerializer}
object Foo extends SerializableCompanion[Foo] { protected val serializer: SimpleSerializer[Foo] = makeSerializer[Foo] }
final case class Foo(bar: String) extends SerializableInstance[Foo] { protected def companion: SerializableCompanion[Foo] = Foo }
A combined Serializer/Deserializer that works on the same type
A Serializer for a Map[String,V] (or rather TraversableOnce[(String,V)]) that allows us to output a JSON Object for a Map[String,V] instead of an Array[(String,V)].
A Serializer for a Map[String,V] (or rather TraversableOnce[(String,V)]) that allows us to output a JSON Object for a Map[String,V] instead of an Array[(String,V)]. If the underlying Output doesn't support this style (e.g. Protobuf) then the TraversableOnceSerializer is used instead.
A Serializer for a TraversableOnce
A specialized implementation for deserializing Vectors.
A Specialzed Option[Boolean] deserializer that uses the fm-common OptionCache via the Some.cached implicit
A Specialzed Option[Char] deserializer that uses the fm-common OptionCache via the Some.cached implicit
A Specialzed Option[Int] deserializer that uses the fm-common OptionCache via the Some.cached implicit
A Specialzed Option[Long] deserializer that uses the fm-common OptionCache via the Some.cached implicit
These are implicit serializers/deserializers for common types that do not require the use of a macro to generate.
Common types that DO require a macro are embedded into the makeSerializer/makeDeserializer via MacroHelpers.tryCommonType() since we can't call macros from here without creating a separate compilation package.