-
Notifications
You must be signed in to change notification settings - Fork 32
Making Utf8/Utf16 a subclass of Struct is misleading #34
Comments
Just to add to this, it's compounded because a string should currently be represented in two different ways:
This bifurcation means that I have to choose in my typedef to make it easier to pass in strings or receive strings. |
Thanks for the report! If we change it to non-struct, one can no longer have a Alternatively, we could opt for adding fields to And while on the topic of fixing the Strings design, if we could allow copy-free strings, that would be great dart-lang/sdk#39787. That might also require moving Strings to |
Utf8
andUtf16
are subclasses ofStruct
. This makes it possible to pass aPointer<Utf8>
as a parameter to native methods.However, the
Utf8
andUtf16
classes do not have any fields. AUtf8
instance does not actually contain a UTF-8 character, andsizeOf<Utf8>()
returns zero. This means that a call toallocate<Utf8>()
will return a zero length buffer, which is probably not what the user expects.It may be preferable to make
Utf8
/Utf16
purely helper classes that do not extendNativeType
. UTF-8/UTF-16 strings can then be more accurately represented withPointer<Uint8>
andPointer<Uint16>
types.@mit-mit @timsneath
The text was updated successfully, but these errors were encountered: