Skip to content

The default JSON Encoder serialization doesn't work with SignalR Server for byte[] #304

@moozzyk

Description

@moozzyk

Binary payloads are by default translated to JSON array and rejected by the server. Example:

for i in 1...5 {
    // continuation.yield([UInt8(i)] // fails
    continuation.yield(Data([UInt8(i)]).base64EncodedString()) // workaround
    Thread.sleep(forTimeInterval: 0.1)
}

The workaround is to base64 encode the data before sending. Similarly, receiving the data as byte array won't work. It needs to be a string which the client needs to then base64 decode.

struct MessageSHA: Decodable {
    // let value: [UInt8] - doesn't work
    let value: String
    let shaType: Int
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions