Skip to content

Commit

Permalink
Consolidate packer/unpacker field switch (#1808)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine authored Aug 19, 2022
1 parent ff357a1 commit d17a329
Showing 1 changed file with 10 additions and 50 deletions.
60 changes: 10 additions & 50 deletions message/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,46 +42,26 @@ func (f Field) Packer() func(*wrappers.Packer, interface{}) {
switch f {
case VersionStr:
return wrappers.TryPackStr
case NetworkID:
return wrappers.TryPackInt
case NodeID:
case NetworkID, NodeID, RequestID:
return wrappers.TryPackInt
case MyTime:
case MyTime, Deadline, VersionTime:
return wrappers.TryPackLong
case IP:
return wrappers.TryPackIP
case ChainID: // TODO: This will be shortened to use a modified varint spec
return wrappers.TryPackHash
case RequestID:
return wrappers.TryPackInt
case Deadline:
return wrappers.TryPackLong
case ContainerID:
case ChainID, ContainerID: // TODO: This will be shortened to use a modified varint spec
return wrappers.TryPackHash
case ContainerBytes:
case ContainerBytes, AppBytes, SigBytes, SummaryBytes:
return wrappers.TryPackBytes
case ContainerIDs:
case ContainerIDs, TrackedSubnets, SummaryIDs:
return wrappers.TryPackHashes
case MultiContainerBytes:
return wrappers.TryPack2DBytes
case AppBytes:
return wrappers.TryPackBytes
case SigBytes:
return wrappers.TryPackBytes
case VersionTime:
return wrappers.TryPackLong
case Peers:
return wrappers.TryPackClaimedIPPortList
case TrackedSubnets:
return wrappers.TryPackHashes
case Uptime:
return wrappers.TryPackByte
case SummaryBytes:
return wrappers.TryPackBytes
case SummaryHeights:
return wrappers.TryPackUint64Slice
case SummaryIDs:
return wrappers.TryPackHashes
default:
return nil
}
Expand All @@ -92,46 +72,26 @@ func (f Field) Unpacker() func(*wrappers.Packer) interface{} {
switch f {
case VersionStr:
return wrappers.TryUnpackStr
case NetworkID:
return wrappers.TryUnpackInt
case NodeID:
case NetworkID, NodeID, RequestID:
return wrappers.TryUnpackInt
case MyTime:
case MyTime, Deadline, VersionTime:
return wrappers.TryUnpackLong
case IP:
return wrappers.TryUnpackIP
case ChainID: // TODO: This will be shortened to use a modified varint spec
return wrappers.TryUnpackHash
case RequestID:
return wrappers.TryUnpackInt
case Deadline:
return wrappers.TryUnpackLong
case ContainerID:
case ChainID, ContainerID: // TODO: This will be shortened to use a modified varint spec
return wrappers.TryUnpackHash
case ContainerBytes:
case ContainerBytes, AppBytes, SigBytes, SummaryBytes:
return wrappers.TryUnpackBytes
case ContainerIDs:
case ContainerIDs, TrackedSubnets, SummaryIDs:
return wrappers.TryUnpackHashes
case MultiContainerBytes:
return wrappers.TryUnpack2DBytes
case AppBytes:
return wrappers.TryUnpackBytes
case SigBytes:
return wrappers.TryUnpackBytes
case VersionTime:
return wrappers.TryUnpackLong
case Peers:
return wrappers.TryUnpackClaimedIPPortList
case TrackedSubnets:
return wrappers.TryUnpackHashes
case Uptime:
return wrappers.TryUnpackByte
case SummaryBytes:
return wrappers.TryUnpackBytes
case SummaryHeights:
return wrappers.TryUnpackUint64Slice
case SummaryIDs:
return wrappers.TryUnpackHashes
default:
return nil
}
Expand Down

0 comments on commit d17a329

Please sign in to comment.