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 7 months ago committed by Copybara-Service
parent d0b016fcfc
commit 9de810acdc
  1. 4
      python/google/protobuf/internal/type_checkers.py

@ -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):

Loading…
Cancel
Save