def serialize(self, builder: Builder): image_offset = builder.CreateByteVector(self.image) TesseractOcrRequestStart(builder) TesseractOcrRequestAddImage(builder, image_offset) return TesseractOcrRequestEnd(builder)
def _encode_vector(self, builder: flatbuffers.Builder, value: Collection, element_type: BaseType) -> int: if element_type == BaseType.UByte or element_type == BaseType.Byte: return builder.CreateByteVector(value) elements_encoded = [ self._encode_value(builder, element, element_type) for element in value ] element_bytesize = _number_type_by_base_type[element_type].bytewidth vector_element_type = _number_type_by_base_type[element_type] builder.StartVector(element_bytesize, len(elements_encoded), element_bytesize) for index, element in enumerate(reversed(elements_encoded)): if vector_element_type == flatbuffers.number_types.UOffsetTFlags: builder.PrependUOffsetTRelative(element) else: builder.Prepend(_number_type_by_base_type[element_type], element) return builder.EndVector(len(elements_encoded))