Coverage Report

Created: 2021-09-03 06:06

/src/swift-protobuf/Sources/SwiftProtobuf/CustomJSONCodable.swift
Line
Count
Source (jump to first uncovered line)
1
// Sources/SwiftProtobuf/CustomJSONCodable.swift - Custom JSON support for WKTs
2
//
3
// Copyright (c) 2014 - 2017 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
/// Custom protocol for the WKTs to support their custom JSON encodings.
12
///
13
// -----------------------------------------------------------------------------
14
15
/// Allows WKTs to provide their custom JSON encodings.
16
internal protocol _CustomJSONCodable {
17
  func encodedJSONString(options: JSONEncodingOptions) throws -> String
18
  mutating func decodeJSON(from: inout JSONDecoder) throws
19
20
  /// Called when the JSON `null` literal is encountered in a position where
21
  /// a message of the conforming type is expected. The message type can then
22
  /// handle the `null` value differently, if needed; for example,
23
  /// `Google_Protobuf_Value` returns a special instance whose `kind` is set to
24
  /// `.nullValue(.nullValue)`.
25
  ///
26
  /// The default behavior is to return `nil`, which indicates that `null`
27
  /// should be treated as the absence of a message.
28
  static func decodedFromJSONNull() throws -> Self?
29
}
30
31
extension _CustomJSONCodable {
32
0
  internal static func decodedFromJSONNull() -> Self? {
33
0
    // Return nil by default. Concrete types can provide custom logic.
34
0
    return nil
35
0
  }
36
}