Module com.s8.api

Interface S8SerialPrototype<S extends S8Serializable>

Type Parameters:
S - The serializable type
All Known Subinterfaces:
S8ExplicitSerialPrototype<S>

public interface S8SerialPrototype<S extends S8Serializable>

Important explanation on why it's coded that way.

Assume you have a -slightly- complex ByteOutflowable object: it's called ThFluid and it contains all properties of a given fluid. Let's ay that they are limite nb of fluids (air, water, methane, etc.) so that you can simply assign a number to them (CAS number in real life). The trick is that there is multiple types of fluids (like for instance ImcompressibleFluid or PerfetGasThFluid, eah bringing it's own formula, equation of state and so on. So when reading the encoding of the fluid, there is a rot switch that will call sub-factories (on specialized on perfect gas, another one in incompressible fluid, etc.).

That being said, say you are now building a parsing/composing engine for serilization/persistency or whatever. You stumble on a field which has a type that actually implementts the ByteOutflowable interface, but it MUST have a method to indicate the PROPER factory to be used for deserializing this type of field. In the case described in previous paragraph, the factory cannot be a constant of for instance ImcompressibleFluid since type parsing may need to be done at an higher level (for instance ThFluid) to enable the possibility to switch dynamically between differnt types of fluid with a unified encoding (for instance first type gives the type of fluid and allows to switch to a give factory, then each factory will continue to read bytes, each one havong it's own byte pattern). If relying on constant fields, override is extremly painful since we cannot select from a specific class the right factory. For instance tf the type of the fiekd is simply Impcoressible, we might want to restrain encoding to simply the one give by this specific factory.

  • Method Summary

    Modifier and Type
    Method
    Description
    deserialize object from the ByteInflow byte inflow.
    Get serial type
    boolean
    hasDelta(S left, S right)
    Compare two objects to determine if there are deltas.
  • Method Details

    • deserialize

      S deserialize(ByteInflow inflow) throws IOException
      deserialize object from the ByteInflow byte inflow.
      Parameters:
      inflow - the inflow
      Returns:
      The deserialized object
      Throws:
      IOException - the raised exception when deserializing
    • hasDelta

      boolean hasDelta(S left, S right)
      Compare two objects to determine if there are deltas.
      Parameters:
      left - left object for comparison
      right - right object for comparison
      Returns:
      true if there is a delta/difference.
    • getSerialType

      Class<?> getSerialType()
      Get serial type
      Returns:
      the class of the objects represented by this prototype