diff --git a/README.md b/README.md index 6039014..4948d42 100644 --- a/README.md +++ b/README.md @@ -337,57 +337,8 @@ console.log(JSON.stringify(Person.read(reader).address)); // { "city": "New York # Recursive types If you want an object type to be able to contain one of itself (recursion), then you have to apply the following pattern: -```ts -import { INT, STRING, object, Parsed, ParsedConcrete, typedGeneric, typedObject, TypeToken } from 'typed-binary'; - -interface ExpressionBase {} - -interface MultiplyExpression extends ExpressionBase { - type: 'multiply'; - a: Expression; - b: Expression; -} - -interface NegateExpression extends ExpressionBase { - type: 'negate'; - inner: Expression; -} - -type IntLiteralExpression = ParsedConcrete; -const IntLiteralExpression = object({ - value: INT, -}); - -type Expression = MultiplyExpression|NegateExpression|IntLiteralExpression; -const Expression = typedGeneric(new TypeToken(), { - name: STRING, -}, { - 'multiply': typedObject(() => ({ - a: Expression, - b: Expression, - })), - 'negate': typedObject(() => ({ - inner: Expression, - })), - 'int_literal': IntLiteralExpression -}); - -const expr: Parsed = { - type: 'multiply', - a: { - type: 'negate', - inner: { - type: 'int_literal', - value: 15, - } - }, - b: { - type: 'int_literal', - value: 2, - }, -}; - -``` +> CURRENTLY WORKING ON A NEW PATTERN. +> THIS IS A WORK IN PROGRESS. # Serialization and Deserialization Each schema has the following methods: @@ -415,4 +366,4 @@ const buffer = Buffer.alloc(64); // Or new ArrayBuffer(64); on browsers. const reader = new BufferReader(buffer); // Implements ISerialInput const writer = new BufferWriter(buffer); // Implements ISerialOutput -``` \ No newline at end of file +```