Skip to content

Commit a474268

Browse files
authored
fix(contrib): rename binary propagator's functions. (open-telemetry#776)
1 parent 89c147e commit a474268

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

opentelemetry-contrib/src/trace/propagator/binary/base64_format.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ use opentelemetry::trace::SpanContext;
1616
/// representation.
1717
pub trait Base64Format {
1818
/// Serializes span context into a base64 encoded string
19-
fn to_base64(&self, context: &SpanContext) -> String;
19+
fn serialize_into_base64(&self, context: &SpanContext) -> String;
2020

2121
/// Deserialize a span context from a base64 encoded string
22-
fn from_base64(&self, base64: &str) -> SpanContext;
22+
fn deserialize_from_base64(&self, base64: &str) -> SpanContext;
2323
}
2424

2525
impl<Format> Base64Format for Format
2626
where
2727
Format: BinaryFormat,
2828
{
29-
fn to_base64(&self, context: &SpanContext) -> String {
30-
encode(&self.to_bytes(context))
29+
fn serialize_into_base64(&self, context: &SpanContext) -> String {
30+
encode(&self.serialize_into_bytes(context))
3131
}
3232

33-
fn from_base64(&self, base64: &str) -> SpanContext {
33+
fn deserialize_from_base64(&self, base64: &str) -> SpanContext {
3434
if let Ok(bytes) = decode(base64.as_bytes()) {
35-
self.from_bytes(bytes)
35+
self.deserialize_from_bytes(bytes)
3636
} else {
3737
SpanContext::empty_context()
3838
}
@@ -69,23 +69,23 @@ mod tests {
6969
}
7070

7171
#[test]
72-
fn to_base64_conversion() {
72+
fn serialize_into_base64_conversion() {
7373
let propagator = BinaryPropagator::new();
7474

7575
for (context, data) in to_base64_data() {
76-
assert_eq!(propagator.to_base64(&context), data)
76+
assert_eq!(propagator.serialize_into_base64(&context), data)
7777
}
7878
}
7979

8080
#[test]
81-
fn from_base64_conversion() {
81+
fn deserialize_from_base64_conversion() {
8282
let propagator = BinaryPropagator::new();
8383

8484
for (context, data) in from_base64_data() {
85-
assert_eq!(propagator.from_base64(&data), context)
85+
assert_eq!(propagator.deserialize_from_base64(&data), context)
8686
}
8787
for (context, data) in to_base64_data() {
88-
assert_eq!(propagator.from_base64(&data), context)
88+
assert_eq!(propagator.deserialize_from_base64(&data), context)
8989
}
9090
}
9191
}

opentelemetry-contrib/src/trace/propagator/binary/binary_propagator.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use std::convert::TryInto;
1212
/// representation.
1313
pub trait BinaryFormat {
1414
/// Serializes span context into a byte array and returns the array.
15-
fn to_bytes(&self, context: &SpanContext) -> [u8; 29];
15+
fn serialize_into_bytes(&self, context: &SpanContext) -> [u8; 29];
1616

1717
/// Deserializes a span context from a byte array.
18-
fn from_bytes(&self, bytes: Vec<u8>) -> SpanContext;
18+
fn deserialize_from_bytes(&self, bytes: Vec<u8>) -> SpanContext;
1919
}
2020

2121
/// Extracts and injects `SpanContext`s from byte arrays.
@@ -31,7 +31,7 @@ impl BinaryPropagator {
3131

3232
impl BinaryFormat for BinaryPropagator {
3333
/// Serializes span context into a byte array and returns the array.
34-
fn to_bytes(&self, context: &SpanContext) -> [u8; 29] {
34+
fn serialize_into_bytes(&self, context: &SpanContext) -> [u8; 29] {
3535
let mut res = [0u8; 29];
3636
if !context.is_valid() {
3737
return res;
@@ -46,7 +46,7 @@ impl BinaryFormat for BinaryPropagator {
4646
}
4747

4848
/// Deserializes a span context from a byte array.
49-
fn from_bytes(&self, bytes: Vec<u8>) -> SpanContext {
49+
fn deserialize_from_bytes(&self, bytes: Vec<u8>) -> SpanContext {
5050
if bytes.is_empty() {
5151
return SpanContext::empty_context();
5252
}
@@ -159,20 +159,20 @@ mod tests {
159159
}
160160

161161
#[test]
162-
fn to_bytes_conversion() {
162+
fn serialize_into_bytes_conversion() {
163163
let propagator = BinaryPropagator::new();
164164

165165
for (context, data) in to_bytes_data() {
166-
assert_eq!(propagator.to_bytes(&context), data)
166+
assert_eq!(propagator.serialize_into_bytes(&context), data)
167167
}
168168
}
169169

170170
#[test]
171-
fn from_bytes_conversion() {
171+
fn deserialize_from_bytes_conversion() {
172172
let propagator = BinaryPropagator::new();
173173

174174
for (context, data) in from_bytes_data() {
175-
assert_eq!(propagator.from_bytes(data), context)
175+
assert_eq!(propagator.deserialize_from_bytes(data), context)
176176
}
177177
}
178178
}

0 commit comments

Comments
 (0)