Skip to content

Commit

Permalink
Variable-ize identifier length
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-janidlo committed Dec 6, 2024
1 parent 8a077e3 commit dab79a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 8 additions & 0 deletions compute_sdk/globus_compute_sdk/serialize/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

from globus_compute_sdk.errors import DeserializationError

# 2 unique characters and a newline
IDENTIFIER_LENGTH = 3


class SerializationStrategy(metaclass=ABCMeta):
"""A SerializationStrategy is in charge of converting function source code or
arguments into string data and back again.
"""

def __init_subclass__(cls):
super().__init_subclass__()
if len(cls.identifier) != IDENTIFIER_LENGTH:
raise ValueError(f"Identifiers must be {IDENTIFIER_LENGTH} characters long")

@property
@abstractmethod
def identifier(self):
Expand Down
6 changes: 2 additions & 4 deletions compute_sdk/globus_compute_sdk/serialize/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import typing as t

from globus_compute_sdk.errors import DeserializationError, SerializationError
from globus_compute_sdk.serialize.base import SerializationStrategy
from globus_compute_sdk.serialize.base import IDENTIFIER_LENGTH, SerializationStrategy
from globus_compute_sdk.serialize.concretes import (
DEFAULT_STRATEGY_CODE,
DEFAULT_STRATEGY_DATA,
Expand Down Expand Up @@ -41,9 +41,7 @@ def validate(strategy: SerializationStrategy) -> SerializationStrategy:
validate(strategy_data) if strategy_data else DEFAULT_STRATEGY_DATA
)

# grab a randomish ID from the map (all identifiers should be the same length)
identifier = next(iter(STRATEGIES_MAP.keys()))
self.header_size = len(identifier)
self.header_size = IDENTIFIER_LENGTH

self.strategies = {
header: strategy_class()
Expand Down

0 comments on commit dab79a1

Please sign in to comment.