JSONEncodingOptions.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Sources/SwiftProtobuf/JSONEncodingOptions.swift - JSON encoding options
  2. //
  3. // Copyright (c) 2014 - 2018 Apple Inc. and the project authors
  4. // Licensed under Apache License v2.0 with Runtime Library Exception
  5. //
  6. // See LICENSE.txt for license information:
  7. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  8. //
  9. // -----------------------------------------------------------------------------
  10. ///
  11. /// JSON encoding options
  12. ///
  13. // -----------------------------------------------------------------------------
  14. /// Options for JSONEncoding.
  15. public struct JSONEncodingOptions: Sendable {
  16. /// Always prints int64s values as numbers.
  17. /// By default, they are printed as strings as per proto3 JSON mapping rules.
  18. /// NB: When used as Map keys, int64s will be printed as strings as expected.
  19. public var alwaysPrintInt64sAsNumbers: Bool = false
  20. /// Always print enums as ints. By default they are printed as strings.
  21. public var alwaysPrintEnumsAsInts: Bool = false
  22. /// Whether to preserve proto field names.
  23. /// By default they are converted to JSON(lowerCamelCase) names.
  24. public var preserveProtoFieldNames: Bool = false
  25. /// Whether to use deterministic ordering when serializing.
  26. ///
  27. /// Note that the deterministic serialization is NOT canonical across languages.
  28. /// It is NOT guaranteed to remain stable over time. It is unstable across
  29. /// different builds with schema changes due to unknown fields. Users who need
  30. /// canonical serialization (e.g., persistent storage in a canonical form,
  31. /// fingerprinting, etc.) should define their own canonicalization specification
  32. /// and implement their own serializer rather than relying on this API.
  33. ///
  34. /// If deterministic serialization is requested, map entries will be sorted
  35. /// by keys in lexicographical order. This is an implementation detail
  36. /// and subject to change.
  37. public var useDeterministicOrdering: Bool = false
  38. public init() {}
  39. }