wrap-cli icon indicating copy to clipboard operation
wrap-cli copied to clipboard

Add bindings for de/serializing base types in wasm wrap modules

Open Niraj-Kamdar opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. Currently, we only generate bindings for de/serializing custom types defined in the GraphQL schema but we should also generate bindings for base-types to allow easy and consistent de/serializing experience for msgpack

Describe the solution you'd like EX: String type in GraphQL generates following bindings in wasm-as

export class String {
  result: string;

  static toBuffer(type: string): ArrayBuffer {
    const sizerContext: Context = new Context(
      "Serializing (sizing) base-type: String"
    );
    const sizer = new WriteSizer(sizerContext);
    sizer.writeString(type);
    const buffer = new ArrayBuffer(sizer.length);
    const encoderContext: Context = new Context(
      "Serializing (encoding) base-type: String"
    );
    const encoder = new WriteEncoder(buffer, sizer, encoderContext);
    encoder.writeString(type);
    return buffer;
  }

  static fromBuffer(buffer: ArrayBuffer): string {
    const context: Context = new Context("Deserializing base-type String");
    const reader = new ReadDecoder(buffer, context);
    return reader.readString();
  }
}

Describe alternatives you've considered If we don't support this user needs to manually do all this and it can be annoying.

Additional context This is essential if we want Msgpack to be the first-class de/serialization standard for the wrap. This will allow us to use msgpack encoded bytes as universal type for plugins like cache, concurrent, etc

tasks

  • [ ] Implement support for msgpack de/serialization for base types.
  • [ ] Write docs about how to de/serialize using msgpack
    - [ ] explain that we only generate bindings for base types and custom type for de/serializing, Array, Map, BigNumber, etc aren't generated by default but you can still use it with low-level API or wrap it under a custom type and use it to get around the current limitation.
  • [ ] Wrap 0.2 should support every types.

Niraj-Kamdar avatar Apr 28 '23 14:04 Niraj-Kamdar