@@ -98,9 +98,16 @@ class CertificateAuthority(Enum):
98
98
c_line_protocol_version = ctypes .c_int
99
99
100
100
101
- class ProtocolVersion (Enum ):
102
- V1 = (c_line_protocol_version (0 ), 'v1' )
103
- V2 = (c_line_protocol_version (1 ), 'v2' )
101
+ class LineProtocolVersion (Enum ):
102
+ V1 = (c_line_protocol_version (1 ), 'v1' )
103
+ V2 = (c_line_protocol_version (2 ), 'v2' )
104
+
105
+ @classmethod
106
+ def from_int (cls , value : c_line_protocol_version ):
107
+ for member in cls :
108
+ if member .value [0 ].value == value :
109
+ return member
110
+ raise ValueError (f"invalid protocol version: { value } " )
104
111
105
112
106
113
class c_line_sender_opts (ctypes .Structure ):
@@ -213,6 +220,8 @@ def set_sig(fn, restype, *argtypes):
213
220
c_size_t )
214
221
set_sig (
215
222
dll .line_sender_buffer_set_line_protocol_version ,
223
+ c_bool ,
224
+ c_line_sender_buffer_p ,
216
225
c_line_protocol_version ,
217
226
c_line_sender_error_p_p )
218
227
set_sig (
@@ -594,12 +603,14 @@ def __init__(self, micros: int):
594
603
595
604
596
605
class Buffer :
597
- def __init__ (self , init_buf_size = 65536 , max_name_len = 127 , line_protocol_version = ProtocolVersion .V2 ):
606
+ def __init__ (self , init_buf_size = 65536 , max_name_len = 127 , line_protocol_version = LineProtocolVersion .V2 ):
598
607
self ._impl = _DLL .line_sender_buffer_with_max_name_len (
599
608
c_size_t (max_name_len ))
600
609
_DLL .line_sender_buffer_reserve (self ._impl , c_size_t (init_buf_size ))
601
610
_error_wrapped_call (
602
- _DLL .line_sender_buffer_set_line_protocol_version (self ._impl , line_protocol_version .value [0 ]))
611
+ _DLL .line_sender_buffer_set_line_protocol_version ,
612
+ self ._impl ,
613
+ line_protocol_version .value [0 ])
603
614
604
615
def __len__ (self ):
605
616
return _DLL .line_sender_buffer_size (self ._impl )
@@ -617,8 +628,11 @@ def peek(self) -> str:
617
628
else :
618
629
return ''
619
630
620
- def set_line_protocol_version (self , version : ProtocolVersion ):
621
- _error_wrapped_call (_DLL .line_sender_buffer_set_line_protocol_version (self ._impl , version ))
631
+ def set_line_protocol_version (self , version : LineProtocolVersion ):
632
+ _error_wrapped_call (
633
+ _DLL .line_sender_buffer_set_line_protocol_version ,
634
+ self ._impl ,
635
+ version .value [0 ])
622
636
623
637
def reserve (self , additional ):
624
638
_DLL .line_sender_buffer_reserve (self ._impl , c_size_t (additional ))
@@ -809,7 +823,8 @@ def connect(self):
809
823
810
824
def __enter__ (self ):
811
825
self .connect ()
812
- self ._buffer = Buffer (line_protocol_version = self .line_sender_default_line_protocol_version ())
826
+ self ._buffer = Buffer (
827
+ line_protocol_version = LineProtocolVersion .from_int (self .line_sender_default_line_protocol_version ()))
813
828
return self
814
829
815
830
def _check_connected (self ):
@@ -818,9 +833,7 @@ def _check_connected(self):
818
833
819
834
def line_sender_default_line_protocol_version (self ):
820
835
self ._check_connected ()
821
- return _error_wrapped_call (
822
- _DLL .line_sender_default_line_protocol_version ,
823
- self ._impl )
836
+ return _DLL .line_sender_default_line_protocol_version (self ._impl )
824
837
825
838
def table (self , table : str ):
826
839
self ._buffer .table (table )
0 commit comments