@@ -30,20 +30,21 @@ class ChunkKeyEncodingParams(TypedDict):
30
30
31
31
@dataclass (frozen = True )
32
32
class ChunkKeyEncoding (ABC , Metadata ):
33
- name : ClassVar [ str ]
34
- separator : SeparatorLiteral = "."
33
+ """
34
+ Defines how chunk coordinates are mapped to store keys.
35
35
36
- def __post_init__ (self ) -> None :
37
- separator_parsed = parse_separator (self .separator )
38
- object .__setattr__ (self , "separator" , separator_parsed )
36
+ Subclasses must define a class variable `name` and implement `encode_chunk_key`.
37
+ """
38
+
39
+ name : ClassVar [str ]
39
40
40
41
@classmethod
41
42
def from_dict (cls , data : dict [str , JSON ]) -> Self :
42
- name_parsed , config_parsed = parse_named_configuration (data , require_configuration = False )
43
+ _ , config_parsed = parse_named_configuration (data , require_configuration = False )
43
44
return cls (** config_parsed if config_parsed else {}) # type: ignore[arg-type]
44
45
45
46
def to_dict (self ) -> dict [str , JSON ]:
46
- return {"name" : self .name , "configuration" : { "separator" : self . separator } }
47
+ return {"name" : self .name , "configuration" : super (). to_dict () }
47
48
48
49
def decode_chunk_key (self , chunk_key : str ) -> tuple [int , ...]:
49
50
"""
@@ -66,7 +67,11 @@ def encode_chunk_key(self, chunk_coords: tuple[int, ...]) -> str:
66
67
@dataclass (frozen = True )
67
68
class DefaultChunkKeyEncoding (ChunkKeyEncoding ):
68
69
name : ClassVar [Literal ["default" ]] = "default"
69
- separator : SeparatorLiteral = "/" # default
70
+ separator : SeparatorLiteral = "/"
71
+
72
+ def __post_init__ (self ) -> None :
73
+ separator_parsed = parse_separator (self .separator )
74
+ object .__setattr__ (self , "separator" , separator_parsed )
70
75
71
76
def decode_chunk_key (self , chunk_key : str ) -> tuple [int , ...]:
72
77
if chunk_key == "c" :
@@ -80,7 +85,11 @@ def encode_chunk_key(self, chunk_coords: tuple[int, ...]) -> str:
80
85
@dataclass (frozen = True )
81
86
class V2ChunkKeyEncoding (ChunkKeyEncoding ):
82
87
name : ClassVar [Literal ["v2" ]] = "v2"
83
- separator : SeparatorLiteral = "." # default
88
+ separator : SeparatorLiteral = "."
89
+
90
+ def __post_init__ (self ) -> None :
91
+ separator_parsed = parse_separator (self .separator )
92
+ object .__setattr__ (self , "separator" , separator_parsed )
84
93
85
94
def decode_chunk_key (self , chunk_key : str ) -> tuple [int , ...]:
86
95
return tuple (map (int , chunk_key .split (self .separator )))
0 commit comments