      Encode a generic repeated field.
      The public repeated field encoding methods should call this method to handle
      */
-    private func encode<T>(tag: UInt32, wireType: FieldWireType, value: [T], packed: Bool, encode: (T) throws -> Void) rethrows {
+    private func encode<T>(tag: UInt32, wireType: FieldWireType, value: [T], packed: Bool?, encode: (T) throws -> Void) rethrows {
+        let packed: Bool = packed ?? messageStack[messageStackIndex].isProto3
         if packed {
             let key = ProtoWriter.makeFieldKey(tag: tag, wireType: .lengthDelimited)
             writeVarint(key)

    }

    /** Encode a repeated `fixed64` or `uint64` field */
    public func encode(tag: UInt32, value: [UInt64]?, encoding: ProtoIntEncoding = .variable, packed: Bool = false) throws {
        guard let value = value else { return }
        let wireType: FieldWireType = encoding == .fixed ? .fixed64 : .varint
        try encode(tag: tag, wireType: wireType, value: value, packed: packed) {

    }

    /** Encode a repeated `int32`, `sfixed32`, or `sint32` field */
    public func encode(tag: UInt32, value: [Int32]?, encoding: ProtoIntEncoding = .variable, packed: Bool? = nil) throws {
        guard let value = value else { return }
        let wireType: FieldWireType = encoding == .fixed ? .fixed32 : .varint
        try encode(tag: tag, wireType: wireType, value: value, packed: packed) {
