Skip to content

Commit ccded32

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
fix: correct ternary handling in java2spec, nullable strings in repeated elements
- java2spec: ternary with null false-branch (cond ? val : null) now preserves the original write method and uses the true branch as field name, instead of blindly treating all ternaries as bool-as-int. Fixes ClipData.ActivityInfo being misidentified as ParcelItemActivityInfos bool. - codegen: string8/string16 in repeated elements are now *string with WriteNullableString/ReadNullableString, matching Java's nullable semantics. - parcel: add WriteNullableString and WriteNullableString16 helpers. - Revert unrelated codec2_test.go refactoring.
1 parent d43f70b commit ccded32

19 files changed

Lines changed: 124 additions & 292 deletions

File tree

android/companion/virtual/virtualdeviceparams.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/content/clipdata.go

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/content/types/clipdata.go

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/media/tv/tvtrackinfo.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/telecom/parcelablecall.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/telecom/parcelableconference.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/telecom/parcelableconnection.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/telephony/data/trafficdescriptor.go

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/window/tasksnapshot.go

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parcel/string.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ func (p *Parcel) WriteNullString16() {
5252
p.WriteInt32(-1)
5353
}
5454

55+
// WriteNullableString16 writes a nullable string in UTF-16LE wire format.
56+
// If s is nil, writes a null sentinel (-1). Otherwise writes the string.
57+
func (p *Parcel) WriteNullableString16(s *string) {
58+
if s == nil {
59+
p.WriteNullString16()
60+
return
61+
}
62+
p.WriteString16(*s)
63+
}
64+
5565
// ReadString16 reads a string in UTF-16LE wire format.
5666
// Reads int32 char count. If -1, returns empty string.
5767
// Then reads (charCount+1)*2 bytes (including null terminator), padded to 4 bytes.
@@ -148,6 +158,16 @@ func (p *Parcel) WriteNullString() {
148158
p.WriteInt32(-1)
149159
}
150160

161+
// WriteNullableString writes a nullable string in UTF-8 wire format.
162+
// If s is nil, writes a null sentinel (-1). Otherwise writes the string.
163+
func (p *Parcel) WriteNullableString(s *string) {
164+
if s == nil {
165+
p.WriteNullString()
166+
return
167+
}
168+
p.WriteString(*s)
169+
}
170+
151171
// ReadString reads a string in UTF-8 wire format (for @utf8InCpp).
152172
// Reads int32 byte length. If -1, returns empty string.
153173
// Then reads byteLen+1 bytes (including null terminator), padded to 4 bytes.

0 commit comments

Comments
 (0)