@@ -14,60 +14,65 @@ import { SerializationWriterFactoryRegistry } from "./serializationWriterFactory
14
14
15
15
/**
16
16
* Serializes a parsable object into a buffer
17
+ * @param serializationWriterFactoryRegistry the serialization writer factory registry
17
18
* @param contentType the content type to serialize to
18
19
* @param value the value to serialize
19
20
* @param serializationFunction the serialization function for the model type
20
21
* @returns a buffer containing the serialized value
21
22
*/
22
- export function serialize < T extends Parsable > ( contentType : string , value : T , serializationFunction : ModelSerializerFunction < T > ) : ArrayBuffer {
23
- const writer = getSerializationWriter ( contentType , value , serializationFunction ) ;
23
+ export function serialize < T extends Parsable > ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , value : T , serializationFunction : ModelSerializerFunction < T > ) : ArrayBuffer {
24
+ const writer = getSerializationWriter ( serializationWriterFactoryRegistry , contentType , value , serializationFunction ) ;
24
25
writer . writeObjectValue ( undefined , value , serializationFunction ) ;
25
26
return writer . getSerializedContent ( ) ;
26
27
}
27
28
/**
28
29
* Serializes a parsable object into a string representation
30
+ * @param serializationWriterFactoryRegistry the serialization writer factory registry
29
31
* @param contentType the content type to serialize to
30
32
* @param value the value to serialize
31
33
* @param serializationFunction the serialization function for the model type
32
34
* @returns a string representing the serialized value
33
35
*/
34
- export function serializeToString < T extends Parsable > ( contentType : string , value : T , serializationFunction : ModelSerializerFunction < T > ) : string {
35
- const buffer = serialize ( contentType , value , serializationFunction ) ;
36
+ export function serializeToString < T extends Parsable > ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , value : T , serializationFunction : ModelSerializerFunction < T > ) : string {
37
+ const buffer = serialize ( serializationWriterFactoryRegistry , contentType , value , serializationFunction ) ;
36
38
return getStringValueFromBuffer ( buffer ) ;
37
39
}
38
40
/**
39
41
* Serializes a collection of parsable objects into a buffer
42
+ * @param serializationWriterFactoryRegistry the serialization writer factory registry
40
43
* @param contentType the content type to serialize to
41
44
* @param values the value to serialize
42
45
* @param serializationFunction the serialization function for the model type
43
46
* @returns a string representing the serialized value
44
47
*/
45
- export function serializeCollection < T extends Parsable > ( contentType : string , values : T [ ] , serializationFunction : ModelSerializerFunction < T > ) : ArrayBuffer {
46
- const writer = getSerializationWriter ( contentType , values , serializationFunction ) ;
48
+ export function serializeCollection < T extends Parsable > ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , values : T [ ] , serializationFunction : ModelSerializerFunction < T > ) : ArrayBuffer {
49
+ const writer = getSerializationWriter ( serializationWriterFactoryRegistry , contentType , values , serializationFunction ) ;
47
50
writer . writeCollectionOfObjectValues ( undefined , values , serializationFunction ) ;
48
51
return writer . getSerializedContent ( ) ;
49
52
}
50
53
51
54
/**
52
55
* Serializes a collection of parsable objects into a string representation
56
+ * @param serializationWriterFactoryRegistry the serialization writer factory registry
53
57
* @param contentType the content type to serialize to
54
58
* @param values the value to serialize
55
59
* @param serializationFunction the serialization function for the model type
56
60
* @returns a string representing the serialized value
57
61
*/
58
- export function serializeCollectionToString < T extends Parsable > ( contentType : string , values : T [ ] , serializationFunction : ModelSerializerFunction < T > ) : string {
59
- const buffer = serializeCollection ( contentType , values , serializationFunction ) ;
62
+ export function serializeCollectionToString < T extends Parsable > ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , values : T [ ] , serializationFunction : ModelSerializerFunction < T > ) : string {
63
+ const buffer = serializeCollection ( serializationWriterFactoryRegistry , contentType , values , serializationFunction ) ;
60
64
return getStringValueFromBuffer ( buffer ) ;
61
65
}
62
66
63
67
/**
64
68
* Gets a serialization writer for a given content type
69
+ * @param serializationWriterFactoryRegistry the serialization writer factory registry
65
70
* @param contentType the content type to serialize to
66
71
* @param value the value to serialize
67
72
* @param serializationFunction the serialization function for the model type
68
73
* @returns the serialization writer for the given content type
69
74
*/
70
- function getSerializationWriter ( contentType : string , value : unknown , serializationFunction : unknown ) : SerializationWriter {
75
+ function getSerializationWriter ( serializationWriterFactoryRegistry : SerializationWriterFactoryRegistry , contentType : string , value : unknown , serializationFunction : unknown ) : SerializationWriter {
71
76
if ( ! contentType ) {
72
77
throw new Error ( "content type cannot be undefined or empty" ) ;
73
78
}
@@ -77,7 +82,7 @@ function getSerializationWriter(contentType: string, value: unknown, serializati
77
82
if ( ! serializationFunction ) {
78
83
throw new Error ( "serializationFunction cannot be undefined" ) ;
79
84
}
80
- return SerializationWriterFactoryRegistry . defaultInstance . getSerializationWriter ( contentType ) ;
85
+ return serializationWriterFactoryRegistry . getSerializationWriter ( contentType ) ;
81
86
}
82
87
83
88
/**
@@ -92,26 +97,28 @@ function getStringValueFromBuffer(buffer: ArrayBuffer): string {
92
97
93
98
/**
94
99
* Deserializes a buffer into a parsable object
100
+ * @param parseNodeFactoryRegistry the parse node factory registry
95
101
* @param contentType the content type to serialize to
96
102
* @param bufferOrString the value to serialize
97
103
* @param factory the factory for the model type
98
104
* @returns the deserialized parsable object
99
105
*/
100
- export function deserialize < T extends Parsable > ( contentType : string , bufferOrString : ArrayBuffer | string , factory : ParsableFactory < T > ) : Parsable {
106
+ export function deserialize < T extends Parsable > ( parseNodeFactoryRegistry : ParseNodeFactoryRegistry , contentType : string , bufferOrString : ArrayBuffer | string , factory : ParsableFactory < T > ) : Parsable {
101
107
if ( typeof bufferOrString === "string" ) {
102
108
bufferOrString = getBufferFromString ( bufferOrString ) ;
103
109
}
104
- const reader = getParseNode ( contentType , bufferOrString , factory ) ;
110
+ const reader = getParseNode ( parseNodeFactoryRegistry , contentType , bufferOrString , factory ) ;
105
111
return reader . getObjectValue ( factory ) ;
106
112
}
107
113
/**
108
114
* Deserializes a buffer into a parsable object
115
+ * @param parseNodeFactoryRegistry the parse node factory registry
109
116
* @param contentType the content type to serialize to
110
117
* @param buffer the value to deserialize
111
118
* @param factory the factory for the model type
112
119
* @returns the deserialized parsable object
113
120
*/
114
- function getParseNode ( contentType : string , buffer : ArrayBuffer , factory : unknown ) : ParseNode {
121
+ function getParseNode ( parseNodeFactoryRegistry : ParseNodeFactoryRegistry , contentType : string , buffer : ArrayBuffer , factory : unknown ) : ParseNode {
115
122
if ( ! contentType ) {
116
123
throw new Error ( "content type cannot be undefined or empty" ) ;
117
124
}
@@ -121,20 +128,21 @@ function getParseNode(contentType: string, buffer: ArrayBuffer, factory: unknown
121
128
if ( ! factory ) {
122
129
throw new Error ( "factory cannot be undefined" ) ;
123
130
}
124
- return ParseNodeFactoryRegistry . defaultInstance . getRootParseNode ( contentType , buffer ) ;
131
+ return parseNodeFactoryRegistry . getRootParseNode ( contentType , buffer ) ;
125
132
}
126
133
/**
127
- * Deserializes a buffer into a a collection of parsable object
134
+ * Deserializes a buffer into a collection of parsable object
135
+ * @param parseNodeFactoryRegistry the parse node factory registry
128
136
* @param contentType the content type to serialize to
129
137
* @param bufferOrString the value to serialize
130
138
* @param factory the factory for the model type
131
139
* @returns the deserialized collection of parsable objects
132
140
*/
133
- export function deserializeCollection < T extends Parsable > ( contentType : string , bufferOrString : ArrayBuffer | string , factory : ParsableFactory < T > ) : T [ ] | undefined {
141
+ export function deserializeCollection < T extends Parsable > ( parseNodeFactoryRegistry : ParseNodeFactoryRegistry , contentType : string , bufferOrString : ArrayBuffer | string , factory : ParsableFactory < T > ) : T [ ] | undefined {
134
142
if ( typeof bufferOrString === "string" ) {
135
143
bufferOrString = getBufferFromString ( bufferOrString ) ;
136
144
}
137
- const reader = getParseNode ( contentType , bufferOrString , factory ) ;
145
+ const reader = getParseNode ( parseNodeFactoryRegistry , contentType , bufferOrString , factory ) ;
138
146
return reader . getCollectionOfObjectValues ( factory ) ;
139
147
}
140
148
0 commit comments