1 /++ 2 +/ 3 module mir.ser.unwrap_ids; 4 5 import mir.ion.exception; 6 7 /++ 8 +/ 9 struct UnwrapSymbolIdsSerializer(Serializer, SymbolMap) 10 { 11 /// 12 Serializer* serializer; 13 /// 14 SymbolMap symbolMap; 15 16 /// 17 alias serializer this; 18 19 private void checkId(size_t id) const 20 { 21 if (id >= symbolMap.length) 22 { 23 version (D_Exceptions) 24 throw IonErrorCode.symbolIdIsTooLargeForTheCurrentSymbolTable.ionException; 25 else 26 assert(0, IonErrorCode.symbolIdIsTooLargeForTheCurrentSymbolTable.ionErrorMsg); 27 } 28 } 29 30 /++ 31 Performs `putKey(symbolMap[id])` 32 +/ 33 void putKeyId(size_t id) 34 { 35 checkId(id); 36 serializer.putKey(symbolMap[id]); 37 } 38 39 /++ 40 Performs `putValue(symbolMap[id])` 41 +/ 42 void putSymbolId(size_t id) 43 { 44 checkId(id); 45 putSymbol(symbolMap[id]); 46 } 47 48 static if (!__traits(hasMember, serializer, "putSymbol")) 49 void putSymbol(scope const(char)[] str) 50 { 51 putValue(str); 52 } 53 54 /++ 55 Performs `putAnnotation(symbolMap[id])` 56 +/ 57 void putAnnotationId(size_t id) 58 { 59 checkId(id); 60 serializer.putAnnotation(symbolMap[id]); 61 } 62 } 63 64 /++ 65 +/ 66 UnwrapSymbolIdsSerializer!(Serializer, SymbolMap) 67 unwrapSymbolIds(Serializer, SymbolMap) 68 (return scope Serializer* serializer, return scope SymbolMap symbolMap) 69 @trusted 70 { 71 return typeof(return)(serializer, symbolMap); 72 }