92
92
///
93
93
/// The higher-level APIs will automatically ensure that `BitstreamWriter.data`
94
94
/// is valid. Once serialization has completed, simply emit this data to a file.
95
- public final class BitstreamWriter {
95
+ internal final class BitstreamWriter {
96
96
/// The buffer of data being written to.
97
97
private( set) public var data : [ UInt8 ]
98
98
@@ -161,7 +161,7 @@ public final class BitstreamWriter {
161
161
162
162
extension BitstreamWriter {
163
163
/// Writes the provided UInt32 to the data stream directly.
164
- public func write( _ int: UInt32 ) {
164
+ internal func write( _ int: UInt32 ) {
165
165
let index = data. count
166
166
167
167
// Add 4 bytes of zeroes to be overwritten.
@@ -179,7 +179,7 @@ extension BitstreamWriter {
179
179
/// - int: The integer containing the bits you'd like to write
180
180
/// - width: The number of low-bits of the integer you're writing to the
181
181
/// buffer
182
- public func writeVBR< IntType> ( _ int: IntType , width: UInt8 )
182
+ internal func writeVBR< IntType> ( _ int: IntType , width: UInt8 )
183
183
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
184
184
{
185
185
let threshold = UInt64 ( 1 ) << ( UInt64 ( width) - 1 )
@@ -201,7 +201,7 @@ extension BitstreamWriter {
201
201
/// - int: The integer containing the bits you'd like to write
202
202
/// - width: The number of low-bits of the integer you're writing to the
203
203
/// buffer
204
- public func write< IntType> ( _ int: IntType , width: UInt8 )
204
+ internal func write< IntType> ( _ int: IntType , width: UInt8 )
205
205
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
206
206
{
207
207
precondition ( width > 0 , " cannot emit 0 bits " )
@@ -247,7 +247,7 @@ extension BitstreamWriter {
247
247
currentBit = ( currentBit + width) & 31
248
248
}
249
249
250
- public func alignIfNeeded( ) {
250
+ internal func alignIfNeeded( ) {
251
251
guard currentBit > 0 else { return }
252
252
write ( currentValue)
253
253
assert ( bufferOffset % 4 == 0 , " buffer must be 32-bit aligned " )
@@ -256,12 +256,12 @@ extension BitstreamWriter {
256
256
}
257
257
258
258
/// Writes a Bool as a 1-bit integer value.
259
- public func write( _ bool: Bool ) {
259
+ internal func write( _ bool: Bool ) {
260
260
write ( bool ? 1 as UInt : 0 , width: 1 )
261
261
}
262
262
263
263
/// Writes the provided BitCode Abbrev operand to the stream.
264
- public func write( _ abbrevOp: Bitstream . Abbreviation . Operand ) {
264
+ internal func write( _ abbrevOp: Bitstream . Abbreviation . Operand ) {
265
265
write ( abbrevOp. isLiteral) // the Literal bit.
266
266
switch abbrevOp {
267
267
case . literal( let value) :
@@ -290,19 +290,19 @@ extension BitstreamWriter {
290
290
}
291
291
292
292
/// Writes the specified abbreviaion value to the stream, as a 32-bit quantity.
293
- public func writeCode( _ code: Bitstream . AbbreviationID ) {
293
+ internal func writeCode( _ code: Bitstream . AbbreviationID ) {
294
294
writeCode ( code. rawValue)
295
295
}
296
296
297
297
/// Writes the specified Code value to the stream, as a 32-bit quantity.
298
- public func writeCode< IntType> ( _ code: IntType )
298
+ internal func writeCode< IntType> ( _ code: IntType )
299
299
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
300
300
{
301
301
write ( code, width: codeBitWidth)
302
302
}
303
303
304
304
/// Writes an ASCII character to the stream, as an 8-bit ascii value.
305
- public func writeASCII( _ character: Character ) {
305
+ internal func writeASCII( _ character: Character ) {
306
306
precondition ( character. unicodeScalars. count == 1 , " character is not ASCII " )
307
307
let c = UInt8 ( ascii: character. unicodeScalars. first!)
308
308
write ( c, width: 8 )
@@ -314,7 +314,7 @@ extension BitstreamWriter {
314
314
extension BitstreamWriter {
315
315
/// Defines an abbreviation and returns the unique identifier for that
316
316
/// abbreviation.
317
- public func defineAbbreviation( _ abbrev: Bitstream . Abbreviation ) -> Bitstream . AbbreviationID {
317
+ internal func defineAbbreviation( _ abbrev: Bitstream . Abbreviation ) -> Bitstream . AbbreviationID {
318
318
encodeAbbreviation ( abbrev)
319
319
currentAbbreviations. append ( abbrev)
320
320
let rawValue = UInt64 ( currentAbbreviations. count - 1 ) +
@@ -335,7 +335,7 @@ extension BitstreamWriter {
335
335
// MARK: Writing Records
336
336
337
337
extension BitstreamWriter {
338
- public struct RecordBuffer {
338
+ internal struct RecordBuffer {
339
339
private( set) var values = [ UInt32] ( )
340
340
341
341
fileprivate init ( ) {
@@ -378,7 +378,7 @@ extension BitstreamWriter {
378
378
}
379
379
380
380
/// Writes an unabbreviated record to the stream.
381
- public func writeRecord< CodeType> ( _ code: CodeType , _ composeRecord: ( inout RecordBuffer ) -> Void )
381
+ internal func writeRecord< CodeType> ( _ code: CodeType , _ composeRecord: ( inout RecordBuffer ) -> Void )
382
382
where CodeType: RawRepresentable , CodeType. RawValue == UInt8
383
383
{
384
384
writeCode ( . unabbreviatedRecord)
@@ -394,7 +394,7 @@ extension BitstreamWriter {
394
394
/// Writes a record with the provided abbreviation ID and record contents.
395
395
/// Optionally, emits the provided blob if the abbreviation referenced
396
396
/// by that ID requires it.
397
- public func writeRecord(
397
+ internal func writeRecord(
398
398
_ abbrevID: Bitstream . AbbreviationID ,
399
399
_ composeRecord: ( inout RecordBuffer ) -> Void ,
400
400
blob: String ? = nil
@@ -463,7 +463,7 @@ extension BitstreamWriter {
463
463
" 0123456789._ " , ( 0 as UInt ) ... ) )
464
464
465
465
/// Writes a char6-encoded value.
466
- public func writeChar6< IntType> ( _ value: IntType )
466
+ internal func writeChar6< IntType> ( _ value: IntType )
467
467
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
468
468
{
469
469
guard ( 0 ..< 64 ) . contains ( value) else {
@@ -474,7 +474,7 @@ extension BitstreamWriter {
474
474
}
475
475
476
476
/// Writes a value with the provided abbreviation encoding.
477
- public func writeAbbrevField( _ op: Bitstream . Abbreviation . Operand , value: UInt32 ) {
477
+ internal func writeAbbrevField( _ op: Bitstream . Abbreviation . Operand , value: UInt32 ) {
478
478
switch op {
479
479
case . literal( let literalValue) :
480
480
// Do not write anything
@@ -494,7 +494,7 @@ extension BitstreamWriter {
494
494
495
495
/// Writes a block, beginning with the provided block code and the
496
496
/// abbreviation width
497
- public func writeBlock(
497
+ internal func writeBlock(
498
498
_ blockID: Bitstream . BlockID ,
499
499
newAbbrevWidth: UInt8 ? = nil ,
500
500
emitRecords: ( ) -> Void
@@ -504,7 +504,7 @@ extension BitstreamWriter {
504
504
endBlock ( )
505
505
}
506
506
507
- public func writeBlob< S> ( _ bytes: S , includeSize: Bool = true )
507
+ internal func writeBlob< S> ( _ bytes: S , includeSize: Bool = true )
508
508
where S: Collection , S. Element == UInt8
509
509
{
510
510
if includeSize {
@@ -529,7 +529,7 @@ extension BitstreamWriter {
529
529
530
530
/// Writes the blockinfo block and allows emitting abbreviations
531
531
/// and records in it.
532
- public func writeBlockInfoBlock( emitRecords: ( ) -> Void ) {
532
+ internal func writeBlockInfoBlock( emitRecords: ( ) -> Void ) {
533
533
writeBlock ( . blockInfo, newAbbrevWidth: 2 ) {
534
534
currentBlockID = nil
535
535
blockInfoRecords = [ : ]
@@ -547,7 +547,7 @@ extension BitstreamWriter {
547
547
/// - blockID: The ID of the block to emit.
548
548
/// - abbreviationBitWidth: The width of the largest abbreviation ID in this block.
549
549
/// - defineSubBlock: A closure that is called to define the contents of the new block.
550
- public func withSubBlock(
550
+ internal func withSubBlock(
551
551
_ blockID: Bitstream . BlockID ,
552
552
abbreviationBitWidth: UInt8 ? = nil ,
553
553
defineSubBlock: ( ) -> Void
@@ -568,7 +568,7 @@ extension BitstreamWriter {
568
568
/// - Parameters:
569
569
/// - blockID: The ID of the block to emit.
570
570
/// - abbreviationBitWidth: The width of the largest abbreviation ID in this block.
571
- public func enterSubblock(
571
+ internal func enterSubblock(
572
572
_ blockID: Bitstream . BlockID ,
573
573
abbreviationBitWidth: UInt8 ? = nil
574
574
) {
@@ -601,7 +601,7 @@ extension BitstreamWriter {
601
601
}
602
602
603
603
/// Marks the end of a new block record.
604
- public func endBlock( ) {
604
+ internal func endBlock( ) {
605
605
guard let block = blockScope. popLast ( ) else {
606
606
fatalError ( " endBlock() called with no block registered " )
607
607
}
@@ -623,7 +623,7 @@ extension BitstreamWriter {
623
623
624
624
/// Defines an abbreviation within the blockinfo block for the provided
625
625
/// block ID.
626
- public func defineBlockInfoAbbreviation(
626
+ internal func defineBlockInfoAbbreviation(
627
627
_ blockID: Bitstream . BlockID ,
628
628
_ abbrev: Bitstream . Abbreviation
629
629
) -> Bitstream . AbbreviationID {
0 commit comments