Skip to content

Commit

Permalink
Merge branch 'main' into swift-6
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba authored Mar 19, 2024
2 parents 53bd272 + 5f847f2 commit ab7aba4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Sources/Compute/Fastly/FastlyDevice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// FastlyDevice.swift
//
//
// Created by Andrew Barba on 3/19/24.
//

import ComputeRuntime

extension Fastly {
public struct Device: Sendable {

public struct DeviceLookup: Codable, Sendable {
public let name: String?
public let brand: String?
public let model: String?
public let hardwareType: String?
public let isDesktop: Bool?
public let isGameConsole: Bool?
public let isMediaPlayer: Bool?
public let isMobile: Bool?
public let isSmartTV: Bool?
public let isTablet: Bool?
public let isTouchscreen: Bool?
}

public static func lookup(userAgent: String) throws -> DeviceLookup {
return try wasiDecode(maxBufferLength: maxIpLookupLength) {
fastly_device__device_detection_lookup(userAgent, userAgent.utf8.count, $0, $1, &$2)
}
}

private init() {}
}
}
8 changes: 8 additions & 0 deletions Sources/Compute/Fastly/FastlyStubs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,12 @@ func fastly_cache__cache_get_body(

func fastly_cache__cache_transaction_cancel(_ handle: WasiHandle) -> Int32 { fatalError() }

func fastly_device__device_detection_lookup(
_ user_agent: UnsafePointer<CChar>!,
_ user_agent_len: Int,
_ buf: UnsafeMutablePointer<CChar>!,
_ buf_len: Int,
_ nwritten: UnsafeMutablePointer<Int>!
) -> Int32 { fatalError() }

#endif
6 changes: 6 additions & 0 deletions Sources/ComputeRuntime/include/ComputeRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,11 @@ int fastly_cache__cache_get_body(WasiHandle handle, uint32_t options_mask,
CacheGetBodyConfig *config,
WasiHandle *ret);

/* FASTLY_DEVICE */

WASM_IMPORT("fastly_device_detection", "lookup")
int fastly_device__device_detection_lookup(const char *user_agent, size_t user_agent_len, const char *buf,
size_t buf_len, size_t *nwritten);

#pragma GCC diagnostic pop
#endif /* ComputeRuntime_h */

0 comments on commit ab7aba4

Please sign in to comment.