9292///
9393/// The higher-level APIs will automatically ensure that `BitstreamWriter.data`
9494/// is valid. Once serialization has completed, simply emit this data to a file.
95- public final class BitstreamWriter {
95+ internal final class BitstreamWriter {
9696 /// The buffer of data being written to.
9797 private( set) public var data : [ UInt8 ]
9898
@@ -161,7 +161,7 @@ public final class BitstreamWriter {
161161
162162extension BitstreamWriter {
163163 /// Writes the provided UInt32 to the data stream directly.
164- public func write( _ int: UInt32 ) {
164+ internal func write( _ int: UInt32 ) {
165165 let index = data. count
166166
167167 // Add 4 bytes of zeroes to be overwritten.
@@ -179,7 +179,7 @@ extension BitstreamWriter {
179179 /// - int: The integer containing the bits you'd like to write
180180 /// - width: The number of low-bits of the integer you're writing to the
181181 /// buffer
182- public func writeVBR< IntType> ( _ int: IntType , width: UInt8 )
182+ internal func writeVBR< IntType> ( _ int: IntType , width: UInt8 )
183183 where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
184184 {
185185 let threshold = UInt64 ( 1 ) << ( UInt64 ( width) - 1 )
@@ -201,7 +201,7 @@ extension BitstreamWriter {
201201 /// - int: The integer containing the bits you'd like to write
202202 /// - width: The number of low-bits of the integer you're writing to the
203203 /// buffer
204- public func write< IntType> ( _ int: IntType , width: UInt8 )
204+ internal func write< IntType> ( _ int: IntType , width: UInt8 )
205205 where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
206206 {
207207 precondition ( width > 0 , " cannot emit 0 bits " )
@@ -247,7 +247,7 @@ extension BitstreamWriter {
247247 currentBit = ( currentBit + width) & 31
248248 }
249249
250- public func alignIfNeeded( ) {
250+ internal func alignIfNeeded( ) {
251251 guard currentBit > 0 else { return }
252252 write ( currentValue)
253253 assert ( bufferOffset % 4 == 0 , " buffer must be 32-bit aligned " )
@@ -256,12 +256,12 @@ extension BitstreamWriter {
256256 }
257257
258258 /// Writes a Bool as a 1-bit integer value.
259- public func write( _ bool: Bool ) {
259+ internal func write( _ bool: Bool ) {
260260 write ( bool ? 1 as UInt : 0 , width: 1 )
261261 }
262262
263263 /// 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 ) {
265265 write ( abbrevOp. isLiteral) // the Literal bit.
266266 switch abbrevOp {
267267 case . literal( let value) :
@@ -290,19 +290,19 @@ extension BitstreamWriter {
290290 }
291291
292292 /// 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 ) {
294294 writeCode ( code. rawValue)
295295 }
296296
297297 /// 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 )
299299 where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
300300 {
301301 write ( code, width: codeBitWidth)
302302 }
303303
304304 /// 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 ) {
306306 precondition ( character. unicodeScalars. count == 1 , " character is not ASCII " )
307307 let c = UInt8 ( ascii: character. unicodeScalars. first!)
308308 write ( c, width: 8 )
@@ -314,7 +314,7 @@ extension BitstreamWriter {
314314extension BitstreamWriter {
315315 /// Defines an abbreviation and returns the unique identifier for that
316316 /// abbreviation.
317- public func defineAbbreviation( _ abbrev: Bitstream . Abbreviation ) -> Bitstream . AbbreviationID {
317+ internal func defineAbbreviation( _ abbrev: Bitstream . Abbreviation ) -> Bitstream . AbbreviationID {
318318 encodeAbbreviation ( abbrev)
319319 currentAbbreviations. append ( abbrev)
320320 let rawValue = UInt64 ( currentAbbreviations. count - 1 ) +
@@ -335,7 +335,7 @@ extension BitstreamWriter {
335335// MARK: Writing Records
336336
337337extension BitstreamWriter {
338- public struct RecordBuffer {
338+ internal struct RecordBuffer {
339339 private( set) var values = [ UInt32] ( )
340340
341341 fileprivate init ( ) {
@@ -378,7 +378,7 @@ extension BitstreamWriter {
378378 }
379379
380380 /// 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 )
382382 where CodeType: RawRepresentable , CodeType. RawValue == UInt8
383383 {
384384 writeCode ( . unabbreviatedRecord)
@@ -394,7 +394,7 @@ extension BitstreamWriter {
394394 /// Writes a record with the provided abbreviation ID and record contents.
395395 /// Optionally, emits the provided blob if the abbreviation referenced
396396 /// by that ID requires it.
397- public func writeRecord(
397+ internal func writeRecord(
398398 _ abbrevID: Bitstream . AbbreviationID ,
399399 _ composeRecord: ( inout RecordBuffer ) -> Void ,
400400 blob: String ? = nil
@@ -463,7 +463,7 @@ extension BitstreamWriter {
463463 " 0123456789._ " , ( 0 as UInt ) ... ) )
464464
465465 /// Writes a char6-encoded value.
466- public func writeChar6< IntType> ( _ value: IntType )
466+ internal func writeChar6< IntType> ( _ value: IntType )
467467 where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
468468 {
469469 guard ( 0 ..< 64 ) . contains ( value) else {
@@ -474,7 +474,7 @@ extension BitstreamWriter {
474474 }
475475
476476 /// 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 ) {
478478 switch op {
479479 case . literal( let literalValue) :
480480 // Do not write anything
@@ -494,7 +494,7 @@ extension BitstreamWriter {
494494
495495 /// Writes a block, beginning with the provided block code and the
496496 /// abbreviation width
497- public func writeBlock(
497+ internal func writeBlock(
498498 _ blockID: Bitstream . BlockID ,
499499 newAbbrevWidth: UInt8 ? = nil ,
500500 emitRecords: ( ) -> Void
@@ -504,7 +504,7 @@ extension BitstreamWriter {
504504 endBlock ( )
505505 }
506506
507- public func writeBlob< S> ( _ bytes: S , includeSize: Bool = true )
507+ internal func writeBlob< S> ( _ bytes: S , includeSize: Bool = true )
508508 where S: Collection , S. Element == UInt8
509509 {
510510 if includeSize {
@@ -529,7 +529,7 @@ extension BitstreamWriter {
529529
530530 /// Writes the blockinfo block and allows emitting abbreviations
531531 /// and records in it.
532- public func writeBlockInfoBlock( emitRecords: ( ) -> Void ) {
532+ internal func writeBlockInfoBlock( emitRecords: ( ) -> Void ) {
533533 writeBlock ( . blockInfo, newAbbrevWidth: 2 ) {
534534 currentBlockID = nil
535535 blockInfoRecords = [ : ]
@@ -547,7 +547,7 @@ extension BitstreamWriter {
547547 /// - blockID: The ID of the block to emit.
548548 /// - abbreviationBitWidth: The width of the largest abbreviation ID in this block.
549549 /// - defineSubBlock: A closure that is called to define the contents of the new block.
550- public func withSubBlock(
550+ internal func withSubBlock(
551551 _ blockID: Bitstream . BlockID ,
552552 abbreviationBitWidth: UInt8 ? = nil ,
553553 defineSubBlock: ( ) -> Void
@@ -568,7 +568,7 @@ extension BitstreamWriter {
568568 /// - Parameters:
569569 /// - blockID: The ID of the block to emit.
570570 /// - abbreviationBitWidth: The width of the largest abbreviation ID in this block.
571- public func enterSubblock(
571+ internal func enterSubblock(
572572 _ blockID: Bitstream . BlockID ,
573573 abbreviationBitWidth: UInt8 ? = nil
574574 ) {
@@ -601,7 +601,7 @@ extension BitstreamWriter {
601601 }
602602
603603 /// Marks the end of a new block record.
604- public func endBlock( ) {
604+ internal func endBlock( ) {
605605 guard let block = blockScope. popLast ( ) else {
606606 fatalError ( " endBlock() called with no block registered " )
607607 }
@@ -623,7 +623,7 @@ extension BitstreamWriter {
623623
624624 /// Defines an abbreviation within the blockinfo block for the provided
625625 /// block ID.
626- public func defineBlockInfoAbbreviation(
626+ internal func defineBlockInfoAbbreviation(
627627 _ blockID: Bitstream . BlockID ,
628628 _ abbrev: Bitstream . Abbreviation
629629 ) -> Bitstream . AbbreviationID {
0 commit comments