Skip to content

Commit e465ea1

Browse files
committed
Address PR review feedback
1 parent 3431e24 commit e465ea1

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

azure/ConsiderationsForServiceDesign.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
| Date | Notes |
88
| ----------- | -------------------------------------------------------------- |
9+
| 2024-Jan-17 | Added guidelines on returning string offsets & lengths |
910
| 2022-Jul-15 | Update guidance on long-running operations |
10-
| 2022-Feb-01 | Updated error guidance |
11+
| 2022-Feb-01 | Updated error guidance |
1112
| 2021-Sep-11 | Add long-running operations guidance |
1213
| 2021-Aug-06 | Updated Azure REST Guidelines per Azure API Stewardship Board. |
1314

@@ -517,7 +518,7 @@ By computing and returning ETags for your resources, you enable clients to avoid
517518

518519
## Returning String Offsets & Lengths (Substrings)
519520

520-
Some Azure services return substring offset & length values within a string. For example, the offset & length within a string to a name, email address, or phone #.
521+
Some Azure services return substring offset & length values within a string. For example, the offset & length within a string to a name, email address, or phone number.
521522
When a service response includes a string, the client's programming language deserializes that string into that language's internal string encoding. Below are the possible encodings and examples of languages that use each encoding:
522523

523524
| Encoding | Example languages |
@@ -526,44 +527,44 @@ When a service response includes a string, the client's programming language des
526527
| UTF-16 | JavaScript, Java, C# |
527528
| CodePoint (UTF-32) | Python |
528529

529-
Because the service doesn't know what language a client is written in and what string encoding that language uses, the service can't return UTF-agnostic offset and length values that the client can use to index within the string. To address this, the service response must include offset & length values for all 3 possible encodings and then the client code must select the encoding it required by its language's internal string encoding.
530+
Because the service doesn't know in what language a client is written and what string encoding that language uses, the service can't return UTF-agnostic offset and length values that the client can use to index within the string. To address this, the service response must include offset & length values for all 3 possible encodings and then the client code must select the encoding required by its language's internal string encoding.
530531

531532
For example, if a service response needed to identify offset & length values for "name" and "email" substrings, the JSON response would look like this:
532533

533-
```
534+
```json
534535
{
535536
(... other properties not shown...)
536537
"fullString": "(...some string containing a name and an email address...)",
537538
"name": {
538539
"offset": {
539540
"utf8": 12,
540541
"utf16": 10,
541-
      "codePoint": 4
542+
      "codePoint": 4
542543
   },
543544
   "length": {
544545
   "uft8": 10,
545546
      "utf16": 8,
546-
      "codePoint": 2
547+
      "codePoint": 2
547548
    }
548549
  },
549550
  "email": {
550551
 "offset": {
551552
      "utf8": 12,
552553
      "utf16": 10,
553-
      "codePoint": 4
554+
      "codePoint": 4
554555
    },
555556
    "length": {
556557
      "uft8": 10,
557558
      "utf16": 8,
558-
      "codePoint": 4
559+
      "codePoint": 4
559560
    }
560561
  }
561562
}
562563
```
563564

564565
Then, the Go developer, for example, would get the substring containing the name using code like this:
565566

566-
```
567+
```go
567568
var response := client.SomeMethodReturningJSONShownAbove(...)
568569
name := response.fullString[ response.name.offset.utf8 : response.name.offset.utf8 + response.name.length.utf8]
569570
```

azure/Guidelines.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,14 @@ When a service response includes a string offset or length value, it should spec
11071107

11081108
<a href="#substrings-return-value-for-each-encoding" name="substrings-return-value-for-each-encoding">:white_check_mark:</a> **DO** include all 3 encodings (UTF-8, UTF-16, and CodePoint) for every string offset or length value in a service response.
11091109

1110+
<a href="#substrings-return-value-structure" name="substrings-return-value-structure">:white_check_mark:</a> **DO** define every string offset or length value in a service response as an object with the following structure:
1111+
1112+
| Property | Type | Required | Description |
1113+
| ----------- | ------- | :------: | ----------- |
1114+
| `utf8` | integer | true | The offset or length of the substring in UTF-8 encoding |
1115+
| `utf16` | integer | true | The offset or length of the substring in UTF-16 encoding |
1116+
| `codePoint` | integer | true | The offset or length of the substring in CodePoint encoding |
1117+
11101118
<a href="#telemetry" name="telemetry"></a>
11111119
### Distributed Tracing & Telemetry
11121120
Azure SDK client guidelines specify that client libraries must send telemetry data through the `User-Agent` header, `X-MS-UserAgent` header, and Open Telemetry.

0 commit comments

Comments
 (0)