@@ -125,6 +125,18 @@ impl<E: Encoding, Output: Write> Writer<E, Output> {
125
125
Ok ( self . output )
126
126
}
127
127
128
+ #[ cfg( feature = "experimental-reader-writer" ) ]
129
+ #[ inline]
130
+ pub fn symbol_table ( & self ) -> & SymbolTable {
131
+ & self . context . symbol_table
132
+ }
133
+
134
+ #[ cfg( not( feature = "experimental-reader-writer" ) ) ]
135
+ #[ inline]
136
+ pub ( crate ) fn symbol_table ( & self ) -> & SymbolTable {
137
+ & self . context . symbol_table
138
+ }
139
+
128
140
/// Helper method to encode an LST append containing pending symbols.
129
141
fn write_lst_append ( & mut self ) -> IonResult < ( ) > {
130
142
let Self {
@@ -235,9 +247,21 @@ impl<'a, V: ValueWriter> ApplicationValueWriter<'a, V> {
235
247
}
236
248
}
237
249
238
- fn symbol_table ( & mut self ) -> & mut SymbolTable {
250
+ fn symbol_table_mut ( & mut self ) -> & mut SymbolTable {
239
251
& mut self . encoding . symbol_table
240
252
}
253
+
254
+ #[ cfg( feature = "experimental-reader-writer" ) ]
255
+ #[ inline]
256
+ pub fn symbol_table ( & self ) -> & SymbolTable {
257
+ & self . encoding . symbol_table
258
+ }
259
+
260
+ #[ cfg( not( feature = "experimental-reader-writer" ) ) ]
261
+ #[ inline]
262
+ pub ( crate ) fn symbol_table ( & self ) -> & SymbolTable {
263
+ & self . encoding . symbol_table
264
+ }
241
265
}
242
266
243
267
impl ApplicationValueWriter < ' _ , BinaryValueWriter_1_1 < ' _ , ' _ > > {
@@ -281,15 +305,15 @@ impl<V: ValueWriter> AnnotatableWriter for ApplicationValueWriter<'_, V> {
281
305
{
282
306
let mut annotations = annotations. into_annotations_vec ( ) ;
283
307
match self . value_writer_config . annotations_encoding ( ) {
284
- AnnotationsEncoding :: WriteAsSymbolIds => {
308
+ AnnotationsEncoding :: SymbolIds => {
285
309
// Intern all text so everything we write is a symbol ID
286
310
self . intern_all_annotations ( & mut annotations) ?
287
311
}
288
- AnnotationsEncoding :: WriteAsInlineText => {
312
+ AnnotationsEncoding :: InlineText => {
289
313
// Validate the symbol IDs, write the text as-is
290
314
self . validate_all_symbol_ids ( & mut annotations) ?
291
315
}
292
- AnnotationsEncoding :: WriteNewSymbolsAsInlineText => {
316
+ AnnotationsEncoding :: NewSymbolsAsInlineText => {
293
317
// Map all known strings to symbol IDs, leave new text as is.
294
318
self . map_known_symbols_to_symbol_ids ( & mut annotations) ?
295
319
}
@@ -326,15 +350,15 @@ impl<V: ValueWriter> ApplicationValueWriter<'_, V> {
326
350
}
327
351
// The token is text...
328
352
RawSymbolRef :: Text ( text) => {
329
- let sid = match self . symbol_table ( ) . sid_for ( & text) {
353
+ let sid = match self . symbol_table ( ) . sid_for ( text) {
330
354
Some ( sid) => {
331
355
//...that was already in the symbol table.
332
356
sid
333
357
}
334
358
None => {
335
359
// ...that we need to add to the symbol table.
336
360
self . encoding . num_pending_symbols += 1 ;
337
- self . symbol_table ( ) . add_symbol_for_text ( text)
361
+ self . symbol_table_mut ( ) . add_symbol_for_text ( text)
338
362
}
339
363
} ;
340
364
* annotation = RawSymbolRef :: SymbolId ( sid) ;
@@ -389,7 +413,7 @@ impl<V: ValueWriter> ApplicationValueWriter<'_, V> {
389
413
}
390
414
// The token is text...
391
415
RawSymbolRef :: Text ( text) => {
392
- match self . symbol_table ( ) . sid_for ( & text) {
416
+ match self . symbol_table_mut ( ) . sid_for ( text) {
393
417
Some ( sid) => {
394
418
//...that was already in the symbol table.
395
419
* annotation = RawSymbolRef :: SymbolId ( sid) ;
@@ -452,9 +476,9 @@ impl<'value, V: ValueWriter> ValueWriter for ApplicationValueWriter<'value, V> {
452
476
SystemSymbol_1_1 ( symbol) => SystemSymbol_1_1 ( symbol) ,
453
477
Text ( text) => {
454
478
match value_writer_config. symbol_value_encoding ( ) {
455
- WriteAsSymbolIds => {
479
+ SymbolIds => {
456
480
// Map the text to a symbol ID.
457
- match encoding. symbol_table . sid_for ( & text) {
481
+ match encoding. symbol_table . sid_for ( text) {
458
482
// If it's already in the symbol table, use that SID.
459
483
Some ( symbol_id) => SymbolId ( symbol_id) ,
460
484
// Otherwise, add it to the symbol table.
@@ -464,15 +488,15 @@ impl<'value, V: ValueWriter> ValueWriter for ApplicationValueWriter<'value, V> {
464
488
}
465
489
}
466
490
}
467
- WriteNewSymbolsAsInlineText => {
491
+ NewSymbolsAsInlineText => {
468
492
// If the text is in the symbol table, use the symbol ID. Otherwise, use the text itself.
469
- match encoding. symbol_table . sid_for ( & text) {
493
+ match encoding. symbol_table . sid_for ( text) {
470
494
Some ( symbol_id) => SymbolId ( symbol_id) ,
471
495
None => Text ( text) ,
472
496
}
473
497
}
474
498
// We have text and we want to write text. Nothing to do.
475
- WriteAsInlineText => Text ( text) ,
499
+ InlineText => Text ( text) ,
476
500
}
477
501
}
478
502
} ;
@@ -585,18 +609,18 @@ impl<V: ValueWriter> FieldEncoder for ApplicationStructWriter<'_, V> {
585
609
// From here on, we're dealing with text.
586
610
587
611
// If the struct writer is configured to write field names as text, do that.
588
- if self . value_writer_config . field_name_encoding ( ) == FieldNameEncoding :: WriteAsInlineText {
612
+ if self . value_writer_config . field_name_encoding ( ) == FieldNameEncoding :: InlineText {
589
613
return self . raw_struct_writer . encode_field_name ( text) ;
590
614
}
591
615
592
616
// Otherwise, see if the symbol is already in the symbol table.
593
- let token: RawSymbolRef < ' _ > = match self . encoding . symbol_table . sid_for ( & text) {
617
+ let token: RawSymbolRef < ' _ > = match self . encoding . symbol_table . sid_for ( text) {
594
618
// If so, use the existing ID.
595
619
Some ( sid) => sid. into ( ) ,
596
620
// If it's not but the struct writer is configured to intern new text, add it to the
597
621
// symbol table.
598
622
None if self . value_writer_config . field_name_encoding ( )
599
- == FieldNameEncoding :: WriteAsSymbolIds =>
623
+ == FieldNameEncoding :: SymbolIds =>
600
624
{
601
625
self . encoding . num_pending_symbols += 1 ;
602
626
self . encoding . symbol_table . add_symbol_for_text ( text) . into ( )
@@ -828,7 +852,7 @@ mod tests {
828
852
fn intern_new_symbol_values ( ) -> IonResult < ( ) > {
829
853
use RawSymbolRef :: * ;
830
854
symbol_value_encoding_test (
831
- SymbolValueEncoding :: WriteAsSymbolIds ,
855
+ SymbolValueEncoding :: SymbolIds ,
832
856
[
833
857
( Text ( "$ion_symbol_table" ) , & [ 0xE1 , 0x03 ] ) ,
834
858
( Text ( "name" ) , & [ 0xE1 , 0x04 ] ) ,
@@ -842,7 +866,7 @@ mod tests {
842
866
fn do_not_intern_new_symbol_values ( ) -> IonResult < ( ) > {
843
867
use RawSymbolRef :: * ;
844
868
symbol_value_encoding_test (
845
- SymbolValueEncoding :: WriteNewSymbolsAsInlineText ,
869
+ SymbolValueEncoding :: NewSymbolsAsInlineText ,
846
870
[
847
871
// Known text symbols are written as SIDs
848
872
( Text ( "$ion_symbol_table" ) , & [ 0xE1 , 0x03 ] ) ,
@@ -860,7 +884,7 @@ mod tests {
860
884
fn encode_all_text_as_is ( ) -> IonResult < ( ) > {
861
885
use RawSymbolRef :: * ;
862
886
symbol_value_encoding_test (
863
- SymbolValueEncoding :: WriteAsInlineText ,
887
+ SymbolValueEncoding :: InlineText ,
864
888
[
865
889
// Known text symbols are written as inline text
866
890
( Text ( "name" ) , & [ 0xA4 , 0x6E , 0x61 , 0x6D , 0x65 ] ) ,
@@ -903,7 +927,7 @@ mod tests {
903
927
fn intern_new_annotations ( ) -> IonResult < ( ) > {
904
928
use RawSymbolRef :: * ;
905
929
annotations_sequence_encoding_test (
906
- AnnotationsEncoding :: WriteAsSymbolIds ,
930
+ AnnotationsEncoding :: SymbolIds ,
907
931
& [
908
932
Text ( "$ion_symbol_table" ) ,
909
933
Text ( "name" ) ,
@@ -925,7 +949,7 @@ mod tests {
925
949
fn write_new_annotations_as_text ( ) -> IonResult < ( ) > {
926
950
use RawSymbolRef :: * ;
927
951
annotations_sequence_encoding_test (
928
- AnnotationsEncoding :: WriteNewSymbolsAsInlineText ,
952
+ AnnotationsEncoding :: NewSymbolsAsInlineText ,
929
953
& [
930
954
Text ( "$ion_symbol_table" ) ,
931
955
Text ( "name" ) ,
@@ -950,7 +974,7 @@ mod tests {
950
974
fn write_text_annotations_as_is ( ) -> IonResult < ( ) > {
951
975
use RawSymbolRef :: * ;
952
976
annotations_sequence_encoding_test (
953
- AnnotationsEncoding :: WriteAsInlineText ,
977
+ AnnotationsEncoding :: InlineText ,
954
978
& [ Text ( "name" ) , SymbolId ( 6 ) , Text ( "foo" ) ] ,
955
979
& [
956
980
0xE9 , // Opcode: FlexUInt follows with byte length of sequence
@@ -1007,7 +1031,7 @@ mod tests {
1007
1031
#[ test]
1008
1032
fn intern_all_field_names ( ) -> IonResult < ( ) > {
1009
1033
struct_field_encoding_test (
1010
- FieldNameEncoding :: WriteAsSymbolIds ,
1034
+ FieldNameEncoding :: SymbolIds ,
1011
1035
& [
1012
1036
// New symbols
1013
1037
( RawSymbolRef :: Text ( "foo" ) , & [ 0x81 ] ) , // FlexUInt SID $64,
@@ -1023,7 +1047,7 @@ mod tests {
1023
1047
#[ test]
1024
1048
fn write_all_field_names_as_text ( ) -> IonResult < ( ) > {
1025
1049
struct_field_encoding_test (
1026
- FieldNameEncoding :: WriteAsInlineText ,
1050
+ FieldNameEncoding :: InlineText ,
1027
1051
& [
1028
1052
// New symbols
1029
1053
( RawSymbolRef :: Text ( "foo" ) , & [ 0xFB , 0x66 , 0x6F , 0x6F ] ) , // FlexSym -3, "foo"
@@ -1038,7 +1062,7 @@ mod tests {
1038
1062
#[ test]
1039
1063
fn write_new_field_names_as_text ( ) -> IonResult < ( ) > {
1040
1064
struct_field_encoding_test (
1041
- FieldNameEncoding :: WriteNewSymbolsAsInlineText ,
1065
+ FieldNameEncoding :: NewSymbolsAsInlineText ,
1042
1066
& [
1043
1067
// New symbols
1044
1068
( RawSymbolRef :: Text ( "foo" ) , & [ 0xFB , 0x66 , 0x6F , 0x6F ] ) , // FlexSym -3, "foo"
0 commit comments