fwcd / fwcd/swift-binary-coder
Cannot re-read input or amend output
- Langage dominant
- Swift
- Étoiles
- 4
- Forks
- 1
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
The standard encoder/decoder implementations provided by Apple (e.g. JSONDecoder) allow you to take multiple attempts at reading data in different formats. For example, you could try reading a field as a String, and then handle the error if that fails and try again to read it as an Int.
Similarly you can write to the same output object multiple times with difference objects to get an aggregate output, as in this example: https://gist.github.com/nicklockwood/ff51117ac8139248507ecc84a1ed7fed
Unfortunately this doesn't work with your current BinaryEncoder implementation.
For decoding the problem appears to be that the BinaryDecodingState is shared between containers, which means that once one container has read a value, it's permanently popped from the internal Data object and cannot be read again by another container. This seems like it should be straightforward to fix by using a resettable cursor variable for the current data read position, but I've not attempted to work out a detailed implementation.
For encoding I guess the problem is that you write out the data immediately to the output, making it impossible to add additional fields to the same object using another container. I'm not sure what the solution is there, although this seems like a less common requirement than multiple reads (I only just discovered that it was even possible with JSONDecoder today!).
In any case, it would be great to fix the re-reading limitation in BinaryDecoder at least.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par lire BinaryDecodingState et les implémentations du conteneur BinaryDecoder afin de comprendre comment l’état partagé consomme l’entrée. Comparez le comportement avec JSONDecoder et l’exemple aggregate-output lié, puis définissez et testez des lectures et des écritures répétées afin que plusieurs conteneurs puissent fonctionner sur les mêmes données ou le même objet de sortie.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- swift
- Domaine
- api
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100