diff --git a/scripts/templates/template.py.jinja2 b/scripts/templates/template.py.jinja2 index c4242e8..dea7abe 100644 --- a/scripts/templates/template.py.jinja2 +++ b/scripts/templates/template.py.jinja2 @@ -4,13 +4,12 @@ from __future__ import annotations import struct -from io import BytesIO from snowflake.telemetry._internal.serialize import ( Enum, MessageMarshaler, Varint, ) -from typing import List, Optional +from typing import List {% for import in file_template.imports %} from {{ import }} import * @@ -56,7 +55,7 @@ class {{ message.name }}(MessageMarshaler): {%- endfor %} return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: {%- for field in message.fields %} {{ field.serialize_field_inline | indent(8) }} {%- endfor %} diff --git a/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/logs/v1/logs_service_marshaler.py b/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/logs/v1/logs_service_marshaler.py index 0c3002f..0734fcf 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/logs/v1/logs_service_marshaler.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/logs/v1/logs_service_marshaler.py @@ -4,11 +4,7 @@ from __future__ import annotations import struct -from io import BytesIO -from typing import ( - List, - Optional, -) +from typing import List from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs_marshaler import * from snowflake.telemetry._internal.serialize import ( @@ -43,7 +39,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource_logs: for v in self._resource_logs: out += b"\n" @@ -75,7 +71,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._partial_success is not None: out += b"\n" Varint.write_varint_u32(out, self._partial_success._get_size()) @@ -104,7 +100,7 @@ def calculate_size(self) -> int: size += len(b"\x12") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.rejected_log_records: out += b"\x08" Varint.write_varint_i64(out, self.rejected_log_records) diff --git a/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/metrics/v1/metrics_service_marshaler.py b/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/metrics/v1/metrics_service_marshaler.py index 71ac655..44ddf94 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/metrics/v1/metrics_service_marshaler.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/metrics/v1/metrics_service_marshaler.py @@ -4,11 +4,7 @@ from __future__ import annotations import struct -from io import BytesIO -from typing import ( - List, - Optional, -) +from typing import List from snowflake.telemetry._internal.opentelemetry.proto.metrics.v1.metrics_marshaler import * from snowflake.telemetry._internal.serialize import ( @@ -43,7 +39,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource_metrics: for v in self._resource_metrics: out += b"\n" @@ -75,7 +71,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._partial_success is not None: out += b"\n" Varint.write_varint_u32(out, self._partial_success._get_size()) @@ -104,7 +100,7 @@ def calculate_size(self) -> int: size += len(b"\x12") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.rejected_data_points: out += b"\x08" Varint.write_varint_i64(out, self.rejected_data_points) diff --git a/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/trace/v1/trace_service_marshaler.py b/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/trace/v1/trace_service_marshaler.py index 7ba8da6..c848a14 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/trace/v1/trace_service_marshaler.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/proto/collector/trace/v1/trace_service_marshaler.py @@ -4,11 +4,7 @@ from __future__ import annotations import struct -from io import BytesIO -from typing import ( - List, - Optional, -) +from typing import List from snowflake.telemetry._internal.opentelemetry.proto.trace.v1.trace_marshaler import * from snowflake.telemetry._internal.serialize import ( @@ -43,7 +39,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource_spans: for v in self._resource_spans: out += b"\n" @@ -75,7 +71,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._partial_success is not None: out += b"\n" Varint.write_varint_u32(out, self._partial_success._get_size()) @@ -104,7 +100,7 @@ def calculate_size(self) -> int: size += len(b"\x12") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.rejected_spans: out += b"\x08" Varint.write_varint_i64(out, self.rejected_spans) diff --git a/src/snowflake/telemetry/_internal/opentelemetry/proto/common/v1/common_marshaler.py b/src/snowflake/telemetry/_internal/opentelemetry/proto/common/v1/common_marshaler.py index 415d5dd..d0f199f 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/proto/common/v1/common_marshaler.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/proto/common/v1/common_marshaler.py @@ -4,11 +4,7 @@ from __future__ import annotations import struct -from io import BytesIO -from typing import ( - List, - Optional, -) +from typing import List from snowflake.telemetry._internal.serialize import ( Enum, @@ -87,7 +83,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.string_value is not None: v = self.string_value.encode("utf-8") out += b"\n" @@ -141,7 +137,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._values: for v in self._values: out += b"\n" @@ -174,7 +170,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._values: for v in self._values: out += b"\n" @@ -213,7 +209,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.key: v = self.key.encode("utf-8") out += b"\n" @@ -269,7 +265,7 @@ def calculate_size(self) -> int: size += len(b" ") + Varint.size_varint_u32(self.dropped_attributes_count) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.name: v = self.name.encode("utf-8") out += b"\n" diff --git a/src/snowflake/telemetry/_internal/opentelemetry/proto/logs/v1/logs_marshaler.py b/src/snowflake/telemetry/_internal/opentelemetry/proto/logs/v1/logs_marshaler.py index 1171ba8..20b25c8 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/proto/logs/v1/logs_marshaler.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/proto/logs/v1/logs_marshaler.py @@ -4,11 +4,7 @@ from __future__ import annotations import struct -from io import BytesIO -from typing import ( - List, - Optional, -) +from typing import List from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import * from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource_marshaler import * @@ -77,7 +73,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource_logs: for v in self._resource_logs: out += b"\n" @@ -131,7 +127,7 @@ def calculate_size(self) -> int: size += len(b"\x1a") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource is not None: out += b"\n" Varint.write_varint_u32(out, self._resource._get_size()) @@ -194,7 +190,7 @@ def calculate_size(self) -> int: size += len(b"\x1a") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._scope is not None: out += b"\n" Varint.write_varint_u32(out, self._scope._get_size()) @@ -304,7 +300,7 @@ def calculate_size(self) -> int: size += len(b"Y") + 8 return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.time_unix_nano: out += b"\t" out += struct.pack(" int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource_metrics: for v in self._resource_metrics: out += b"\n" @@ -109,7 +105,7 @@ def calculate_size(self) -> int: size += len(b"\x1a") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource is not None: out += b"\n" Varint.write_varint_u32(out, self._resource._get_size()) @@ -172,7 +168,7 @@ def calculate_size(self) -> int: size += len(b"\x1a") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._scope is not None: out += b"\n" Varint.write_varint_u32(out, self._scope._get_size()) @@ -303,7 +299,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.name: v = self.name.encode("utf-8") out += b"\n" @@ -371,7 +367,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._data_points: for v in self._data_points: out += b"\n" @@ -418,7 +414,7 @@ def calculate_size(self) -> int: size += len(b"\x18") + 1 return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._data_points: for v in self._data_points: out += b"\n" @@ -469,7 +465,7 @@ def calculate_size(self) -> int: size += len(b"\x10") + Varint.size_varint_u32(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._data_points: for v in self._data_points: out += b"\n" @@ -517,7 +513,7 @@ def calculate_size(self) -> int: size += len(b"\x10") + Varint.size_varint_u32(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._data_points: for v in self._data_points: out += b"\n" @@ -556,7 +552,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._data_points: for v in self._data_points: out += b"\n" @@ -632,7 +628,7 @@ def calculate_size(self) -> int: size += len(b"@") + Varint.size_varint_u32(self.flags) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.start_time_unix_nano: out += b"\x11" out += struct.pack(" int: size += len(b"a") + 8 return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.start_time_unix_nano: out += b"\x11" out += struct.pack(" int: size += len(b"q") + 8 return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._attributes: for v in self._attributes: out += b"\n" @@ -1010,7 +1006,7 @@ def calculate_size(self) -> int: size += len(b"\x12") + s + Varint.size_varint_u32(s) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.offset: out += b"\x08" Varint.write_varint_s32(out, self.offset) @@ -1088,7 +1084,7 @@ def calculate_size(self) -> int: size += len(b"@") + Varint.size_varint_u32(self.flags) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.start_time_unix_nano: out += b"\x11" out += struct.pack(" int: size += len(b"\x11") + 8 return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.quantile: out += b"\t" out += struct.pack(" int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.time_unix_nano: out += b"\x11" out += struct.pack(" int: size += len(b"\x10") + Varint.size_varint_u32(self.dropped_attributes_count) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._attributes: for v in self._attributes: out += b"\n" diff --git a/src/snowflake/telemetry/_internal/opentelemetry/proto/trace/v1/trace_marshaler.py b/src/snowflake/telemetry/_internal/opentelemetry/proto/trace/v1/trace_marshaler.py index 0a62f47..58741d9 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/proto/trace/v1/trace_marshaler.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/proto/trace/v1/trace_marshaler.py @@ -4,11 +4,7 @@ from __future__ import annotations import struct -from io import BytesIO -from typing import ( - List, - Optional, -) +from typing import List from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import * from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource_marshaler import * @@ -51,7 +47,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource_spans: for v in self._resource_spans: out += b"\n" @@ -105,7 +101,7 @@ def calculate_size(self) -> int: size += len(b"\x1a") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._resource is not None: out += b"\n" Varint.write_varint_u32(out, self._resource._get_size()) @@ -168,7 +164,7 @@ def calculate_size(self) -> int: size += len(b"\x1a") + Varint.size_varint_u32(len(v)) + len(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self._scope is not None: out += b"\n" Varint.write_varint_u32(out, self._scope._get_size()) @@ -336,7 +332,7 @@ def calculate_size(self) -> int: size += len(b"\x85\x01") + 4 return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.trace_id: out += b"\n" Varint.write_varint_u32(out, len(self.trace_id)) @@ -456,7 +452,7 @@ def calculate_size(self) -> int: ) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.time_unix_nano: out += b"\t" out += struct.pack(" int: size += len(b"5") + 4 return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.trace_id: out += b"\n" Varint.write_varint_u32(out, len(self.trace_id)) @@ -589,7 +585,7 @@ def calculate_size(self) -> int: size += len(b"\x18") + Varint.size_varint_u32(v) return size - def write_to(self, out: BytesIO) -> None: + def write_to(self, out: bytearray) -> None: if self.message: v = self.message.encode("utf-8") out += b"\x12"