use struct instead of ctype. allows the protobuf python library to work on cpython 3.11's new wasm target [1]

For https://github.com/protocolbuffers/protobuf/pull/12212

PiperOrigin-RevId: 631237602
pull/16763/head
Jie Luo 2024-05-06 17:33:22 -07:00 committed by Copybara-Service
parent d0b016fcfc
commit 9de810acdc
1 changed files with 2 additions and 2 deletions

View File

@ -22,7 +22,7 @@ TYPE_TO_DESERIALIZE_METHOD: A dictionary with field types and deserialization
__author__ = 'robinson@google.com (Will Robinson)'
import ctypes
import struct
import numbers
from google.protobuf.internal import decoder
@ -34,7 +34,7 @@ _FieldDescriptor = descriptor.FieldDescriptor
def TruncateToFourByteFloat(original):
return ctypes.c_float(original).value
return struct.unpack('<f', struct.pack('<f', original))[0]
def ToShortestFloat(original):